2017-03-14 15:37:29 +00:00
|
|
|
// Package state holds the interface that any state implementation for
|
|
|
|
// IPFS Cluster must satisfy.
|
2017-03-10 16:24:25 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
// State represents the shared state of the cluster and it
|
|
|
|
import (
|
2018-06-27 04:03:15 +00:00
|
|
|
"context"
|
2017-03-13 17:44:42 +00:00
|
|
|
"io"
|
|
|
|
|
2017-03-14 15:37:29 +00:00
|
|
|
cid "github.com/ipfs/go-cid"
|
2018-09-22 01:00:10 +00:00
|
|
|
|
2017-03-10 16:24:25 +00:00
|
|
|
"github.com/ipfs/ipfs-cluster/api"
|
|
|
|
)
|
|
|
|
|
2017-03-14 15:37:29 +00:00
|
|
|
// State is used by the Consensus component to keep track of
|
2017-03-10 16:24:25 +00:00
|
|
|
// objects which objects are pinned. This component should be thread safe.
|
|
|
|
type State interface {
|
|
|
|
// Add adds a pin to the State
|
2019-02-27 17:04:35 +00:00
|
|
|
Add(context.Context, *api.Pin) error
|
2017-03-10 16:24:25 +00:00
|
|
|
// Rm removes a pin from the State
|
2018-06-27 04:03:15 +00:00
|
|
|
Rm(context.Context, cid.Cid) error
|
2017-03-10 16:24:25 +00:00
|
|
|
// List lists all the pins in the state
|
2019-02-27 17:04:35 +00:00
|
|
|
List(context.Context) []*api.Pin
|
2017-03-10 16:24:25 +00:00
|
|
|
// Has returns true if the state is holding information for a Cid
|
2018-06-27 04:03:15 +00:00
|
|
|
Has(context.Context, cid.Cid) bool
|
2017-03-10 16:24:25 +00:00
|
|
|
// Get returns the information attacthed to this pin
|
2019-02-27 17:04:35 +00:00
|
|
|
Get(context.Context, cid.Cid) (*api.Pin, bool)
|
2017-12-19 17:05:32 +00:00
|
|
|
// Migrate restores the serialized format of an outdated state to the current version
|
2018-06-27 04:03:15 +00:00
|
|
|
Migrate(ctx context.Context, r io.Reader) error
|
2017-11-28 22:45:10 +00:00
|
|
|
// Return the version of this state
|
|
|
|
GetVersion() int
|
|
|
|
// Marshal serializes the state to a byte slice
|
2019-02-19 17:59:46 +00:00
|
|
|
Marshal(io.Writer) error
|
2017-11-28 22:45:10 +00:00
|
|
|
// Unmarshal deserializes the state from marshaled bytes
|
2019-02-19 17:59:46 +00:00
|
|
|
Unmarshal(io.Reader) error
|
2017-03-10 16:24:25 +00:00
|
|
|
}
|