2016-12-02 18:33:39 +00:00
|
|
|
package ipfscluster
|
|
|
|
|
|
|
|
import (
|
2016-12-05 14:30:11 +00:00
|
|
|
"sync"
|
2016-12-02 18:33:39 +00:00
|
|
|
|
|
|
|
cid "gx/ipfs/QmcTcsTvfaeEBRFo1TkFgT8sRmgi1n1LTZpecfVP8fzpGD/go-cid"
|
|
|
|
)
|
|
|
|
|
2016-12-06 21:29:59 +00:00
|
|
|
// MapState is a very simple database to store
|
|
|
|
// the state of the system.
|
|
|
|
// PinMap is public because it is serialized
|
|
|
|
// and maintained by Raft.
|
2016-12-02 18:33:39 +00:00
|
|
|
type MapState struct {
|
2016-12-06 21:29:59 +00:00
|
|
|
PinMap map[string]bool
|
2016-12-02 18:33:39 +00:00
|
|
|
rpcCh chan ClusterRPC
|
2016-12-05 14:30:11 +00:00
|
|
|
mux sync.Mutex
|
2016-12-02 18:33:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 21:29:59 +00:00
|
|
|
func NewMapState() MapState {
|
2016-12-02 18:33:39 +00:00
|
|
|
return MapState{
|
2016-12-06 21:29:59 +00:00
|
|
|
PinMap: make(map[string]bool),
|
2016-12-02 18:33:39 +00:00
|
|
|
rpcCh: make(chan ClusterRPC),
|
2016-12-05 14:30:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 21:29:59 +00:00
|
|
|
func (st MapState) AddPin(c *cid.Cid) error {
|
2016-12-05 14:30:11 +00:00
|
|
|
st.mux.Lock()
|
|
|
|
defer st.mux.Unlock()
|
2016-12-06 21:29:59 +00:00
|
|
|
st.PinMap[c.String()] = true
|
2016-12-02 18:33:39 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (st MapState) RmPin(c *cid.Cid) error {
|
2016-12-05 14:30:11 +00:00
|
|
|
st.mux.Lock()
|
|
|
|
defer st.mux.Unlock()
|
2016-12-02 18:33:39 +00:00
|
|
|
delete(st.PinMap, c.String())
|
|
|
|
return nil
|
|
|
|
}
|