Documentation
¶
Overview ¶
Package ipfscluster implements a wrapper for the IPFS deamon which allows to orchestrate pinning operations among several IPFS nodes.
IPFS Cluster uses a go-libp2p-raft to keep a shared state between the different members of the cluster. It also uses LibP2P to enable communication between its different components, which perform different tasks like managing the underlying IPFS daemons, or providing APIs for external control.
Index ¶
- Constants
- Variables
- func SetLogLevel(l string)
- type API
- type CidArg
- type Cluster
- func (c *Cluster) GlobalSync() ([]GlobalPinInfo, error)
- func (c *Cluster) GlobalSyncCid(h *cid.Cid) (GlobalPinInfo, error)
- func (c *Cluster) ID() ID
- func (c *Cluster) LocalSync() ([]PinInfo, error)
- func (c *Cluster) LocalSyncCid(h *cid.Cid) (PinInfo, error)
- func (c *Cluster) Members() []peer.ID
- func (c *Cluster) Pin(h *cid.Cid) error
- func (c *Cluster) Pins() []*cid.Cid
- func (c *Cluster) Shutdown() error
- func (c *Cluster) StateSync() ([]PinInfo, error)
- func (c *Cluster) Status() ([]GlobalPinInfo, error)
- func (c *Cluster) StatusCid(h *cid.Cid) (GlobalPinInfo, error)
- func (c *Cluster) Unpin(h *cid.Cid) error
- func (c *Cluster) Version() string
- type Component
- type Config
- type Consensus
- func (cc *Consensus) Leader() (peer.ID, error)
- func (cc *Consensus) LogPin(c *cid.Cid) error
- func (cc *Consensus) LogUnpin(c *cid.Cid) error
- func (cc *Consensus) Rollback(state State) error
- func (cc *Consensus) SetClient(c *rpc.Client)
- func (cc *Consensus) Shutdown() error
- func (cc *Consensus) State() (State, error)
- type GlobalPinInfo
- type ID
- type IPFSConnector
- type IPFSHTTPConnector
- type IPFSStatus
- type JSONConfig
- type MapPinTracker
- func (mpt *MapPinTracker) Recover(c *cid.Cid) error
- func (mpt *MapPinTracker) SetClient(c *rpc.Client)
- func (mpt *MapPinTracker) Shutdown() error
- func (mpt *MapPinTracker) Status() []PinInfo
- func (mpt *MapPinTracker) StatusCid(c *cid.Cid) PinInfo
- func (mpt *MapPinTracker) Sync(c *cid.Cid) bool
- func (mpt *MapPinTracker) Track(c *cid.Cid) error
- func (mpt *MapPinTracker) Untrack(c *cid.Cid) error
- type MapState
- type Peered
- type PinInfo
- type PinTracker
- type RESTAPI
- type RPCAPI
- func (api *RPCAPI) ConsensusLogPin(in *CidArg, out *struct{}) error
- func (api *RPCAPI) ConsensusLogUnpin(in *CidArg, out *struct{}) error
- func (api *RPCAPI) GlobalSync(in struct{}, out *[]GlobalPinInfo) error
- func (api *RPCAPI) GlobalSyncCid(in *CidArg, out *GlobalPinInfo) error
- func (api *RPCAPI) ID(in struct{}, out *ID) error
- func (api *RPCAPI) IPFSIsPinned(in *CidArg, out *bool) error
- func (api *RPCAPI) IPFSPin(in *CidArg, out *struct{}) error
- func (api *RPCAPI) IPFSUnpin(in *CidArg, out *struct{}) error
- func (api *RPCAPI) LocalSync(in struct{}, out *[]PinInfo) error
- func (api *RPCAPI) LocalSyncCid(in *CidArg, out *PinInfo) error
- func (api *RPCAPI) MemberList(in struct{}, out *[]peer.ID) error
- func (api *RPCAPI) Pin(in *CidArg, out *struct{}) error
- func (api *RPCAPI) PinList(in struct{}, out *[]string) error
- func (api *RPCAPI) StateSync(in struct{}, out *[]PinInfo) error
- func (api *RPCAPI) Status(in struct{}, out *[]GlobalPinInfo) error
- func (api *RPCAPI) StatusCid(in *CidArg, out *GlobalPinInfo) error
- func (api *RPCAPI) Track(in *CidArg, out *struct{}) error
- func (api *RPCAPI) TrackerStatus(in struct{}, out *[]PinInfo) error
- func (api *RPCAPI) TrackerStatusCid(in *CidArg, out *PinInfo) error
- func (api *RPCAPI) Unpin(in *CidArg, out *struct{}) error
- func (api *RPCAPI) Untrack(in *CidArg, out *struct{}) error
- func (api *RPCAPI) Version(in struct{}, out *string) error
- type RaftConfig
- type State
- Bugs
Constants ¶
const ( DefaultConfigCrypto = crypto.RSA DefaultConfigKeyLength = 2048 DefaultAPIAddr = "/ip4/127.0.0.1/tcp/9094" DefaultIPFSProxyAddr = "/ip4/127.0.0.1/tcp/9095" DefaultIPFSNodeAddr = "/ip4/127.0.0.1/tcp/5001" DefaultClusterAddr = "/ip4/0.0.0.0/tcp/9096" )
Default parameters for the configuration
const ( LogOpPin = iota + 1 LogOpUnpin )
Type of pin operation
const ( // IPFSStatus should never take this value Bug = iota // The cluster node is offline or not responding ClusterError // An error occurred pinning PinError // An error occurred unpinning UnpinError // The IPFS daemon has pinned the item Pinned // The IPFS daemon is currently pinning the item Pinning // The IPFS daemon is currently unpinning the item Unpinning // The IPFS daemon is not pinning the item Unpinned // The IPFS deamon is not pinning the item but it is being tracked RemotePin )
IPFSStatus values
const Version = ""
Version is the current cluster version. Version alignment between components, apis and tools ensures compatibility among them.
Variables ¶
var ( // maximum duration before timing out read of the request IPFSProxyServerReadTimeout = 5 * time.Second // maximum duration before timing out write of the response IPFSProxyServerWriteTimeout = 10 * time.Second // server-side the amount of time a Keep-Alive connection will be // kept idle before being reused IPFSProxyServerIdleTimeout = 60 * time.Second )
IPFS Proxy settings
var ( PinningTimeout = 15 * time.Minute UnpinningTimeout = 10 * time.Second )
A Pin or Unpin operation will be considered failed if the Cid has stayed in Pinning or Unpinning state for longer than these values.
var ( // maximum duration before timing out read of the request RESTAPIServerReadTimeout = 5 * time.Second // maximum duration before timing out write of the response RESTAPIServerWriteTimeout = 10 * time.Second // server-side the amount of time a Keep-Alive connection will be // kept idle before being reused RESTAPIServerIdleTimeout = 60 * time.Second )
Server settings
var Commit string
Commit is the current build commit of cluster. See Makefile
var LeaderTimeout = 120 * time.Second
LeaderTimeout specifies how long to wait during initialization before failing for not having a leader.
var RPCProtocol = protocol.ID("/ipfscluster/" + Version + "/rpc")
RPCProtocol is used to send libp2p messages between cluster members
var SilentRaft = true
SilentRaft controls whether all Raft log messages are discarded.
Functions ¶
Types ¶
type API ¶
type API interface { Component }
API is a component which offers an API for Cluster. This is a base component.
type CidArg ¶
type CidArg struct {
Cid string
}
CidArg is an arguments that carry a Cid. It may carry more things in the future.
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
Cluster is the main IPFS cluster component. It provides the go-API for it and orchestrates the components that make up the system.
func NewCluster ¶
func NewCluster(cfg *Config, api API, ipfs IPFSConnector, state State, tracker PinTracker) (*Cluster, error)
NewCluster builds a new IPFS Cluster. It initializes a LibP2P host, creates and RPC Server and client and sets up all components.
func (*Cluster) GlobalSync ¶
func (c *Cluster) GlobalSync() ([]GlobalPinInfo, error)
GlobalSync triggers Sync() operations in all members of the Cluster.
func (*Cluster) GlobalSyncCid ¶
func (c *Cluster) GlobalSyncCid(h *cid.Cid) (GlobalPinInfo, error)
GlobalSyncCid triggers a LocalSyncCid() operation for a given Cid in all members of the Cluster.
GlobalSyncCid will only return when all operations have either failed, succeeded or timed-out.
func (*Cluster) LocalSync ¶
LocalSync makes sure that the current state the Tracker matches the IPFS daemon state by triggering a Tracker.Sync() and Recover() on all items that need it. Returns PinInfo for items changed on Sync().
LocalSync triggers recoveries asynchronously, and will not wait for them to fail or succeed before returning.
func (*Cluster) LocalSyncCid ¶
LocalSyncCid performs a Tracker.Sync() operation followed by a Recover() when needed. It returns the latest known PinInfo for the Cid.
LocalSyncCid will wait for the Recover operation to fail or succeed before returning.
func (*Cluster) Pin ¶
Pin makes the cluster Pin a Cid. This implies adding the Cid to the IPFS Cluster peers shared-state. Depending on the cluster pinning strategy, the PinTracker may then request the IPFS daemon to pin the Cid.
Pin returns an error if the operation could not be persisted to the global state. Pin does not reflect the success or failure of underlying IPFS daemon pinning operations.
func (*Cluster) Pins ¶
Pins returns the list of Cids managed by Cluster and which are part of the current global state. This is the source of truth as to which pins are managed, but does not indicate if the item is successfully pinned.
func (*Cluster) StateSync ¶
StateSync syncs the consensus state to the Pin Tracker, ensuring that every Cid that should be tracked is tracked. It returns PinInfo for Cids which were added or deleted.
func (*Cluster) Status ¶
func (c *Cluster) Status() ([]GlobalPinInfo, error)
Status returns the GlobalPinInfo for all tracked Cids. If an error happens, the slice will contain as much information as could be fetched.
func (*Cluster) StatusCid ¶
func (c *Cluster) StatusCid(h *cid.Cid) (GlobalPinInfo, error)
StatusCid returns the GlobalPinInfo for a given Cid. If an error happens, the GlobalPinInfo should contain as much information as could be fetched.
func (*Cluster) Unpin ¶
Unpin makes the cluster Unpin a Cid. This implies adding the Cid to the IPFS Cluster peers shared-state.
Unpin returns an error if the operation could not be persisted to the global state. Unpin does not reflect the success or failure of underlying IPFS daemon unpinning operations.
type Component ¶
Component represents a piece of ipfscluster. Cluster components usually run their own goroutines (a http server for example). They communicate with the main Cluster component and other components (both local and remote), using an instance of rpc.Client.
type Config ¶
type Config struct { // Libp2p ID and private key for Cluster communication (including) // the Consensus component. ID peer.ID PrivateKey crypto.PrivKey // List of multiaddresses of the peers of this cluster. ClusterPeers []ma.Multiaddr // Listen parameters for the Cluster libp2p Host. Used by // the RPC and Consensus components. ClusterAddr ma.Multiaddr // Listen parameters for the the Cluster HTTP API component. APIAddr ma.Multiaddr // Listen parameters for the IPFS Proxy. Used by the IPFS // connector component. IPFSProxyAddr ma.Multiaddr // Host/Port for the IPFS daemon. IPFSNodeAddr ma.Multiaddr // Storage folder for snapshots, log store etc. Used by // the Consensus component. ConsensusDataFolder string // Hashicorp's Raft configuration RaftConfig *hashiraft.Config }
Config represents an ipfs-cluster configuration. It is used by Cluster components. An initialized version of it can be obtained with NewDefaultConfig().
func LoadConfig ¶
LoadConfig reads a JSON configuration file from the given path, parses it and returns a new Config object.
func NewDefaultConfig ¶
NewDefaultConfig returns a default configuration object with a randomly generated ID and private key.
func (*Config) ToJSONConfig ¶
func (cfg *Config) ToJSONConfig() (j *JSONConfig, err error)
ToJSONConfig converts a Config object to its JSON representation which is focused on user presentation and easy understanding.
type Consensus ¶
type Consensus struct {
// contains filtered or unexported fields
}
Consensus handles the work of keeping a shared-state between the members of an IPFS Cluster, as well as modifying that state and applying any updates in a thread-safe manner.
func NewConsensus ¶
NewConsensus builds a new ClusterConsensus component. The state is used to initialize the Consensus system, so any information in it is discarded.
func (*Consensus) Leader ¶
Leader returns the peerID of the Leader of the cluster. It returns an error when there is no leader.
func (*Consensus) LogPin ¶
LogPin submits a Cid to the shared state of the cluster. It will forward the operation to the leader if this is not it.
func (*Consensus) Rollback ¶
Rollback replaces the current agreed-upon state with the state provided. Only the consensus leader can perform this operation.
type GlobalPinInfo ¶
GlobalPinInfo contains cluster-wide status information about a tracked Cid, indexed by cluster member.
type IPFSConnector ¶
type IPFSConnector interface { Component Pin(*cid.Cid) error Unpin(*cid.Cid) error IsPinned(*cid.Cid) (bool, error) }
IPFSConnector is a component which allows cluster to interact with an IPFS daemon. This is a base component.
type IPFSHTTPConnector ¶
type IPFSHTTPConnector struct {
// contains filtered or unexported fields
}
IPFSHTTPConnector implements the IPFSConnector interface and provides a component which does two tasks:
On one side, it proxies HTTP requests to the configured IPFS daemon. It is able to intercept these requests though, and perform extra operations on them.
On the other side, it is used to perform on-demand requests against the configured IPFS daemom (such as a pin request).
func NewIPFSHTTPConnector ¶
func NewIPFSHTTPConnector(cfg *Config) (*IPFSHTTPConnector, error)
NewIPFSHTTPConnector creates the component and leaves it ready to be started
func (*IPFSHTTPConnector) IsPinned ¶
func (ipfs *IPFSHTTPConnector) IsPinned(hash *cid.Cid) (bool, error)
IsPinned performs a "pin ls" request against the configured IPFS daemon. It returns true when the given Cid is pinned not indirectly.
func (*IPFSHTTPConnector) Pin ¶
func (ipfs *IPFSHTTPConnector) Pin(hash *cid.Cid) error
Pin performs a pin request against the configured IPFS daemon.
func (*IPFSHTTPConnector) SetClient ¶
func (ipfs *IPFSHTTPConnector) SetClient(c *rpc.Client)
SetClient makes the component ready to perform RPC requests.
func (*IPFSHTTPConnector) Shutdown ¶
func (ipfs *IPFSHTTPConnector) Shutdown() error
Shutdown stops any listeners and stops the component from taking any requests.
type IPFSStatus ¶
type IPFSStatus int
IPFSStatus represents the status of a tracked Cid in the IPFS daemon
func (IPFSStatus) String ¶
func (st IPFSStatus) String() string
String converts an IPFSStatus into a readable string.
type JSONConfig ¶
type JSONConfig struct { // Libp2p ID and private key for Cluster communication (including) // the Consensus component. ID string `json:"id"` PrivateKey string `json:"private_key"` // List of multiaddresses of the peers of this cluster. This list may // include the multiaddress of this node. ClusterPeers []string `json:"cluster_peers"` // Listen address for the Cluster libp2p host. This is used for // interal RPC and Consensus communications between cluster members. ClusterListenMultiaddress string `json:"cluster_multiaddress"` // Listen address for the the Cluster HTTP API component. // Tools like ipfs-cluster-ctl will connect to his endpoint to // manage cluster. APIListenMultiaddress string `json:"api_listen_multiaddress"` // Listen address for the IPFS Proxy, which forwards requests to // an IPFS daemon. IPFSProxyListenMultiaddress string `json:"ipfs_proxy_listen_multiaddress"` // API address for the IPFS daemon. IPFSNodeMultiaddress string `json:"ipfs_node_multiaddress"` // Storage folder for snapshots, log store etc. Used by // the Consensus component. ConsensusDataFolder string `json:"consensus_data_folder"` // Raft configuration RaftConfig *RaftConfig `json:"raft_config"` }
JSONConfig represents a Cluster configuration as it will look when it is saved using JSON. Most configuration keys are converted into simple types like strings, and key names aim to be self-explanatory for the user.
func (*JSONConfig) ToConfig ¶
func (jcfg *JSONConfig) ToConfig() (c *Config, err error)
ToConfig converts a JSONConfig to its internal Config representation, where options are parsed into their native types.
type MapPinTracker ¶
type MapPinTracker struct {
// contains filtered or unexported fields
}
MapPinTracker is a PinTracker implementation which uses a Go map to store the status of the tracked Cids. This component is thread-safe.
func NewMapPinTracker ¶
func NewMapPinTracker(cfg *Config) *MapPinTracker
NewMapPinTracker returns a new object which has been correcly initialized with the given configuration.
func (*MapPinTracker) Recover ¶
func (mpt *MapPinTracker) Recover(c *cid.Cid) error
Recover will re-track or re-untrack a Cid in error state, possibly retriggering an IPFS pinning operation and returning only when it is done.
func (*MapPinTracker) SetClient ¶
func (mpt *MapPinTracker) SetClient(c *rpc.Client)
SetClient makes the MapPinTracker ready to perform RPC requests to other components.
func (*MapPinTracker) Shutdown ¶
func (mpt *MapPinTracker) Shutdown() error
Shutdown finishes the services provided by the MapPinTracker and cancels any active context.
func (*MapPinTracker) Status ¶
func (mpt *MapPinTracker) Status() []PinInfo
Status returns information for all Cids tracked by this MapPinTracker.
func (*MapPinTracker) StatusCid ¶
func (mpt *MapPinTracker) StatusCid(c *cid.Cid) PinInfo
StatusCid returns information for a Cid tracked by this MapPinTracker.
func (*MapPinTracker) Sync ¶
func (mpt *MapPinTracker) Sync(c *cid.Cid) bool
Sync verifies that the status of a Cid matches the status of it in the IPFS daemon. If not, it will be transitioned to Pin or Unpin error. Sync returns true if the status was modified or the status is error. Pins in error states can be recovered with Recover().
type MapState ¶
type MapState struct { PinMap map[string]struct{} // contains filtered or unexported fields }
MapState is a very simple database to store the state of the system using a Go map. It is thread safe. It implements the State interface.
func NewMapState ¶
func NewMapState() *MapState
NewMapState initializes the internal map and returns a new MapState object.
type Peered ¶
Peered represents a component which needs to be aware of the peers in the Cluster and of any changes to the peer set.
type PinInfo ¶
PinInfo holds information about local pins. PinInfo is serialized when requesting the Global status, therefore we cannot use *cid.Cid.
type PinTracker ¶
type PinTracker interface { Component // Track tells the tracker that a Cid is now under its supervision // The tracker may decide to perform an IPFS pin. Track(*cid.Cid) error // Untrack tells the tracker that a Cid is to be forgotten. The tracker // may perform an IPFS unpin operation. Untrack(*cid.Cid) error // Status returns the list of pins with their local status. Status() []PinInfo // StatusCid returns the local status of a given Cid. StatusCid(*cid.Cid) PinInfo // Sync makes sure that the Cid status reflect the real IPFS status. // The return value indicates if the Cid status deserved attention, // either because its state was updated or because it is in error state. Sync(*cid.Cid) bool // Recover retriggers a Pin/Unpin operation in Cids with error status. Recover(*cid.Cid) error }
PinTracker represents a component which tracks the status of the pins in this cluster and ensures they are in sync with the IPFS daemon. This component should be thread safe.
type RESTAPI ¶
type RESTAPI struct {
// contains filtered or unexported fields
}
RESTAPI implements an API and aims to provides a RESTful HTTP API for Cluster.
func NewRESTAPI ¶
NewRESTAPI creates a new object which is ready to be started.
type RPCAPI ¶
type RPCAPI struct {
// contains filtered or unexported fields
}
RPCAPI is a go-libp2p-gorpc service which provides the internal ipfs-cluster API, which enables components and members of the cluster to communicate and request actions from each other.
The RPC API methods are usually redirects to the actual methods in the different components of ipfs-cluster, with very little added logic. Refer to documentation on those methods for details on their behaviour.
func (*RPCAPI) ConsensusLogPin ¶
ConsensusLogPin runs Consensus.LogPin().
func (*RPCAPI) ConsensusLogUnpin ¶
ConsensusLogUnpin runs Consensus.LogUnpin().
func (*RPCAPI) GlobalSync ¶
func (api *RPCAPI) GlobalSync(in struct{}, out *[]GlobalPinInfo) error
GlobalSync runs Cluster.GlobalSync().
func (*RPCAPI) GlobalSyncCid ¶
func (api *RPCAPI) GlobalSyncCid(in *CidArg, out *GlobalPinInfo) error
GlobalSyncCid runs Cluster.GlobalSyncCid().
func (*RPCAPI) IPFSIsPinned ¶
IPFSIsPinned runs IPFSConnector.IsPinned().
func (*RPCAPI) LocalSyncCid ¶
LocalSyncCid runs Cluster.LocalSyncCid().
func (*RPCAPI) MemberList ¶
MemberList runs Cluster.Members().
func (*RPCAPI) Status ¶
func (api *RPCAPI) Status(in struct{}, out *[]GlobalPinInfo) error
Status runs Cluster.Status().
func (*RPCAPI) StatusCid ¶
func (api *RPCAPI) StatusCid(in *CidArg, out *GlobalPinInfo) error
StatusCid runs Cluster.StatusCid().
func (*RPCAPI) TrackerStatus ¶
TrackerStatus runs PinTracker.Status().
func (*RPCAPI) TrackerStatusCid ¶
TrackerStatusCid runs PinTracker.StatusCid().
type RaftConfig ¶
type RaftConfig struct { SnapshotIntervalSeconds int `json:"snapshot_interval_seconds"` EnableSingleNode bool `json:"enable_single_node"` }
RaftConfig is a configuration section which affects the behaviour of the Raft component. See https://godoc.org/github.com/hashicorp/raft#Config for more information. Only the options below are customizable, the rest will take the default values from raft.DefaultConfig().
type State ¶
type State interface { // AddPin adds a pin to the State AddPin(*cid.Cid) error // RmPin removes a pin from the State RmPin(*cid.Cid) error // ListPins lists all the pins in the state ListPins() []*cid.Cid // HasPin returns true if the state is holding a Cid HasPin(*cid.Cid) bool }
State represents the shared state of the cluster and it is used by the Consensus component to keep track of objects which objects are pinned. This component should be thread safe.
Notes ¶
Bugs ¶
See go-libp2p-raft#16 err = cc.p2pRaft.transport.Close()
if err != nil { errMsgs += "could not close libp2p transport: " + err.Error() + ".\n" }