ipfs-cluster/state.go
Hector Sanjuan 9c1c256e33 Introduce the concept of PinTracker. Thin ClusterState to minimal.
+ Try to make RPC handling code cleaner.
2016-12-06 22:29:59 +01:00

39 lines
728 B
Go

package ipfscluster
import (
"sync"
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.
type MapState struct {
PinMap map[string]bool
rpcCh chan ClusterRPC
mux sync.Mutex
}
func NewMapState() MapState {
return MapState{
PinMap: make(map[string]bool),
rpcCh: make(chan ClusterRPC),
}
}
func (st MapState) AddPin(c *cid.Cid) error {
st.mux.Lock()
defer st.mux.Unlock()
st.PinMap[c.String()] = true
return nil
}
func (st MapState) RmPin(c *cid.Cid) error {
st.mux.Lock()
defer st.mux.Unlock()
delete(st.PinMap, c.String())
return nil
}