ipfs-cluster: github.com/ipfs/ipfs-cluster/consensus/crdt Index | Files

package crdt

import "github.com/ipfs/ipfs-cluster/consensus/crdt"


Package Files

config.go consensus.go


var (
    DefaultClusterName         = "ipfs-cluster"
    DefaultPeersetMetric       = "ping"
    DefaultDatastoreNamespace  = "/c" // from "/crdt"
    DefaultRebroadcastInterval = time.Minute
    DefaultTrustedPeers        = []peer.ID{}
    DefaultTrustAll            = true

Default configuration values

var (
    ErrNoLeader = errors.New("crdt consensus component does not provide a leader")
    ErrRmPeer   = errors.New("crdt consensus component cannot remove peers")

Common variables for the module.

func Clean Uses

func Clean(ctx context.Context, cfg *Config, store ds.Datastore) error

Clean deletes all crdt-consensus datas from the given datastore.

func OfflineState Uses

func OfflineState(cfg *Config, store ds.Datastore) (state.BatchingState, error)

OfflineState returns an offline, batching state using the given datastore. This allows to inspect and modify the shared state in offline mode.

type Config Uses

type Config struct {

    // The topic we wish to subscribe to
    ClusterName string

    // TrustAll specifies whether we should trust all peers regardless of
    // the TrustedPeers contents.
    TrustAll bool

    // Any update received from a peer outside this set is ignored and not
    // forwarded. Trusted peers can also access additional RPC endpoints
    // for this peer that are forbidden for other peers.
    TrustedPeers []peer.ID

    // The interval before re-announcing the current state
    // to the network when no activity is observed.
    RebroadcastInterval time.Duration

    // The name of the metric we use to obtain the peerset (every peer
    // with valid metric of this type is part of it).
    PeersetMetric string

    // All keys written to the datastore will be namespaced with this prefix
    DatastoreNamespace string

    // Tracing enables propagation of contexts across binary boundaries.
    Tracing bool
    // contains filtered or unexported fields

Config is the configuration object for Consensus.

func (*Config) ApplyEnvVars Uses

func (cfg *Config) ApplyEnvVars() error

ApplyEnvVars fills in any Config fields found as environment variables.

func (*Config) ConfigKey Uses

func (cfg *Config) ConfigKey() string

ConfigKey returns the section name for this type of configuration.

func (*Config) Default Uses

func (cfg *Config) Default() error

Default sets the configuration fields to their default values.

func (*Config) LoadJSON Uses

func (cfg *Config) LoadJSON(raw []byte) error

LoadJSON takes a raw JSON slice and sets all the configuration fields.

func (*Config) ToDisplayJSON Uses

func (cfg *Config) ToDisplayJSON() ([]byte, error)

ToDisplayJSON returns JSON config as a string.

func (*Config) ToJSON Uses

func (cfg *Config) ToJSON() ([]byte, error)

ToJSON returns the JSON representation of this configuration.

func (*Config) Validate Uses

func (cfg *Config) Validate() error

Validate returns an error if the configuration has invalid values.

type Consensus Uses

type Consensus struct {
    // contains filtered or unexported fields

Consensus implement ipfscluster.Consensus and provides the facility to add and remove pins from the Cluster shared state. It uses a CRDT-backed implementation of go-datastore (go-ds-crdt).

func New Uses

func New(
    host host.Host,
    dht routing.Routing,
    pubsub *pubsub.PubSub,
    cfg *Config,
    store ds.Datastore,
) (*Consensus, error)

New creates a new crdt Consensus component. The given PubSub will be used to broadcast new heads. The given thread-safe datastore will be used to persist data and all will be prefixed with cfg.DatastoreNamespace.

func (*Consensus) AddPeer Uses

func (css *Consensus) AddPeer(ctx context.Context, pid peer.ID) error

AddPeer is a no-op as we do not need to do peerset management with Merkle-CRDTs. Therefore adding a peer to the peerset means doing nothing.

func (*Consensus) Clean Uses

func (css *Consensus) Clean(ctx context.Context) error

Clean deletes all crdt-consensus datas from the datastore.

func (*Consensus) Distrust Uses

func (css *Consensus) Distrust(ctx context.Context, pid peer.ID) error

Distrust removes a peer from the "trusted" set.

func (*Consensus) IsTrustedPeer Uses

func (css *Consensus) IsTrustedPeer(ctx context.Context, pid peer.ID) bool

IsTrustedPeer returns whether the given peer is taken into account when submitting updates to the consensus state.

func (*Consensus) Leader Uses

func (css *Consensus) Leader(ctx context.Context) (peer.ID, error)

Leader returns ErrNoLeader.

func (*Consensus) LogPin Uses

func (css *Consensus) LogPin(ctx context.Context, pin *api.Pin) error

LogPin adds a new pin to the shared state.

func (*Consensus) LogUnpin Uses

func (css *Consensus) LogUnpin(ctx context.Context, pin *api.Pin) error

LogUnpin removes a pin from the shared state.

func (*Consensus) Peers Uses

func (css *Consensus) Peers(ctx context.Context) ([]peer.ID, error)

Peers returns the current known peerset. It uses the monitor component and considers every peer with valid known metrics a member.

func (*Consensus) Ready Uses

func (css *Consensus) Ready(ctx context.Context) <-chan struct{}

Ready returns a channel which is signalled when the component is ready to use.

func (*Consensus) RmPeer Uses

func (css *Consensus) RmPeer(ctx context.Context, pid peer.ID) error

RmPeer is a no-op which always errors, as, since we do not do peerset management, we also have no ability to remove a peer from it.

func (*Consensus) SetClient Uses

func (css *Consensus) SetClient(c *rpc.Client)

SetClient gives the component the ability to communicate and leaves it ready to use.

func (*Consensus) Shutdown Uses

func (css *Consensus) Shutdown(ctx context.Context) error

Shutdown closes this component, cancelling the pubsub subscription and closing the datastore.

func (*Consensus) State Uses

func (css *Consensus) State(ctx context.Context) (state.ReadOnly, error)

State returns the cluster shared state. It will block until the consensus component is ready, shutdown or the given context has been cancelled.

func (*Consensus) Trust Uses

func (css *Consensus) Trust(ctx context.Context, pid peer.ID) error

Trust marks a peer as "trusted". It makes sure it is trusted as issuer for pubsub updates, it is protected in the connection manager, it has the highest priority when the peerstore is saved, and it's addresses are always remembered.

func (*Consensus) WaitForSync Uses

func (css *Consensus) WaitForSync(ctx context.Context) error

WaitForSync is a no-op as it is not necessary to be fully synced for the component to be usable.

Package crdt imports 29 packages (graph) and is imported by 1 packages. Updated 2020-10-23. Refresh now. Tools for package owners.