ipfs-cluster: github.com/ipfs/ipfs-cluster/cmdutils Index | Files

package cmdutils

import "github.com/ipfs/ipfs-cluster/cmdutils"

Package cmdutils contains utilities to facilitate building of command line applications launching cluster peers.


Package Files

cmdutils.go configs.go state.go

func ErrorOut Uses

func ErrorOut(m string, a ...interface{})

ErrorOut formats something and prints it to sdterr.

func HandleSignals Uses

func HandleSignals(
    ctx context.Context,
    cancel context.CancelFunc,
    cluster *ipfscluster.Cluster,
    host host.Host,
    dht *dual.DHT,
    store datastore.Datastore,
) error

HandleSignals orderly shuts down an IPFS Cluster peer on SIGINT, SIGTERM, SIGHUP. It forces command termination on the 3rd-signal count.

func RandomizePorts Uses

func RandomizePorts(addrs []ma.Multiaddr) ([]ma.Multiaddr, error)

RandomizePorts replaces TCP and UDP ports with random, but valid port values, on the given multiaddresses

func WaitForIPFS Uses

func WaitForIPFS(ctx context.Context) error

WaitForIPFS hangs until IPFS API becomes available or the given context is cancelled. The IPFS API location is determined by the default ipfshttp component configuration and can be overridden using environment variables that affect that configuration. Note that we have to do this in the blind, since we want to wait for IPFS before we even fetch the IPFS component configuration (because the configuration might be hosted on IPFS itself)

type ConfigHelper Uses

type ConfigHelper struct {
    // contains filtered or unexported fields

ConfigHelper helps managing the configuration and identity files with the standard set of cluster components.

func NewConfigHelper Uses

func NewConfigHelper(configPath, identityPath, consensus string) *ConfigHelper

NewConfigHelper creates a config helper given the paths to the configuration and identity files. Remember to Shutdown() the ConfigHelper.Manager() after use.

func NewLoadedConfigHelper Uses

func NewLoadedConfigHelper(configPath, identityPath string) (*ConfigHelper, error)

NewLoadedConfigHelper creates a config helper given the paths to the configuration and identity files and loads the configurations from disk. Remember to Shutdown() the ConfigHelper.Manager() after use.

func (*ConfigHelper) Configs Uses

func (ch *ConfigHelper) Configs() *Configs

Configs returns the Configs object which holds all the cluster configurations. Configurations are empty if they have not been loaded from disk.

func (*ConfigHelper) GetConsensus Uses

func (ch *ConfigHelper) GetConsensus() string

GetConsensus attempts to return the configured consensus. If the ConfigHelper was initialized with a consensus string then it returns that.

Otherwise it checks whether one of the consensus configurations has been loaded. If both or non have been loaded, it returns an empty string.

func (*ConfigHelper) Identity Uses

func (ch *ConfigHelper) Identity() *config.Identity

Identity returns the Identity object. It returns an empty identity if not loaded yet.

func (*ConfigHelper) LoadConfigFromDisk Uses

func (ch *ConfigHelper) LoadConfigFromDisk() error

LoadConfigFromDisk parses the configuration from disk.

func (*ConfigHelper) LoadFromDisk Uses

func (ch *ConfigHelper) LoadFromDisk() error

LoadFromDisk loads both configuration and identity from disk.

func (*ConfigHelper) LoadIdentityFromDisk Uses

func (ch *ConfigHelper) LoadIdentityFromDisk() error

LoadIdentityFromDisk parses the identity from disk.

func (*ConfigHelper) MakeConfigFolder Uses

func (ch *ConfigHelper) MakeConfigFolder() error

MakeConfigFolder creates the folder to hold configuration and identity files.

func (*ConfigHelper) Manager Uses

func (ch *ConfigHelper) Manager() *config.Manager

Manager returns the config manager with all the cluster configurations registered.

func (*ConfigHelper) SaveConfigToDisk Uses

func (ch *ConfigHelper) SaveConfigToDisk() error

SaveConfigToDisk saves the configuration file to disk.

func (*ConfigHelper) SaveIdentityToDisk Uses

func (ch *ConfigHelper) SaveIdentityToDisk() error

SaveIdentityToDisk saves the identity file to disk.

func (*ConfigHelper) SetupTracing Uses

func (ch *ConfigHelper) SetupTracing(forceEnabled bool)

SetupTracing propagates tracingCfg.EnableTracing to all other configurations. Use only when identity has been loaded or generated. The forceEnabled parameter allows to override the EnableTracing value.

type Configs Uses

type Configs struct {
    Cluster          *ipfscluster.Config
    Restapi          *rest.Config
    Ipfsproxy        *ipfsproxy.Config
    Ipfshttp         *ipfshttp.Config
    Raft             *raft.Config
    Crdt             *crdt.Config
    Statelesstracker *stateless.Config
    Pubsubmon        *pubsubmon.Config
    Diskinf          *disk.Config
    Numpininf        *numpin.Config
    Metrics          *observations.MetricsConfig
    Tracing          *observations.TracingConfig
    Badger           *badger.Config

Configs carries config types used by a Cluster Peer.

type StateManager Uses

type StateManager interface {
    ImportState(io.Reader) error
    ExportState(io.Writer) error
    GetStore() (ds.Datastore, error)
    GetOfflineState(ds.Datastore) (state.State, error)
    Clean() error

StateManager is the interface that allows to import, export and clean different cluster states depending on the consensus component used.

func NewStateManager Uses

func NewStateManager(consensus string, ident *config.Identity, cfgs *Configs) (StateManager, error)

NewStateManager returns an state manager implementation for the given consensus ("raft" or "crdt"). It will need initialized configs.

func NewStateManagerWithHelper Uses

func NewStateManagerWithHelper(cfgHelper *ConfigHelper) (StateManager, error)

NewStateManagerWithHelper returns a state manager initialized using the configuration and identity provided by the given config helper.

Package cmdutils imports 35 packages (graph). Updated 2020-06-07. Refresh now. Tools for package owners.