ipfs-cluster/state.go

39 lines
728 B
Go
Raw Normal View History

2016-12-02 18:33:39 +00:00
package ipfscluster
import (
"sync"
2016-12-02 18:33:39 +00:00
cid "gx/ipfs/QmcTcsTvfaeEBRFo1TkFgT8sRmgi1n1LTZpecfVP8fzpGD/go-cid"
)
// 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 {
PinMap map[string]bool
2016-12-02 18:33:39 +00:00
rpcCh chan ClusterRPC
mux sync.Mutex
2016-12-02 18:33:39 +00:00
}
func NewMapState() MapState {
2016-12-02 18:33:39 +00:00
return MapState{
PinMap: make(map[string]bool),
2016-12-02 18:33:39 +00:00
rpcCh: make(chan ClusterRPC),
}
}
func (st MapState) AddPin(c *cid.Cid) error {
st.mux.Lock()
defer st.mux.Unlock()
st.PinMap[c.String()] = true
2016-12-02 18:33:39 +00:00
return nil
}
func (st MapState) RmPin(c *cid.Cid) error {
st.mux.Lock()
defer st.mux.Unlock()
2016-12-02 18:33:39 +00:00
delete(st.PinMap, c.String())
return nil
}