config

package module
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2019 License: MIT Imports: 19 Imported by: 26

Documentation

Overview

package config implements the ipfs config file datastructures and utilities.

Index

Constants

View Source
const (
	// DefaultPathName is the default config dir name
	DefaultPathName = ".btfs"
	// DefaultPathRoot is the path to the default config dir location.
	DefaultPathRoot = "~/" + DefaultPathName
	// DefaultConfigFile is the filename of the configuration file
	DefaultConfigFile = "config"
	// EnvDir is the environment variable used to change the path root.
	EnvDir = "BTFS_PATH"
)
View Source
const DefaultConnMgrGracePeriod = time.Second * 20

DefaultConnMgrGracePeriod is the default value for the connection managers grace period

View Source
const DefaultConnMgrHighWater = 900

DefaultConnMgrHighWater is the default value for the connection managers 'high water' mark

View Source
const DefaultConnMgrLowWater = 600

DefaultConnMgrLowWater is the default value for the connection managers 'low water' mark

View Source
const DefaultDataStoreDirectory = "datastore"

DefaultDataStoreDirectory is the directory to store all the local IPFS data.

View Source
const DefaultHostsSyncEnabled = true

DefaultHostSyncEnabled is the default value for the periodic hosts sync from hub

View Source
const DefaultHostsSyncMode = "score"

DefaultHostsSyncMode is the default value for the hosts sync mode from hub

View Source
const IdentityTag = "Identity"
View Source
const PrivKeySelector = IdentityTag + "." + PrivKeyTag
View Source
const PrivKeyTag = "PrivKey"

Variables

View Source
var DefaultBootstrapAddresses = []string{
	"/ip4/18.237.54.123/tcp/4001/btfs/QmWJWGxKKaqZUW4xga2BCzT5FBtYDL8Cc5Q5jywd6xPt1g",
	"/ip4/54.213.128.120/tcp/4001/btfs/QmWm3vBCRuZcJMUT9jDZysoYBb66aokmSReX26UaMk8qq5",
	"/ip4/34.213.5.20/tcp/4001/btfs/QmQVQBsM7uoJy8hATjTm51uSAkx2y3iGLhSwA6LWLa7iQJ",
	"/ip4/18.237.202.91/tcp/4001/btfs/QmbVFdiNkvxtc7Nni7yBWAgtHg8MuyhaZ5mDaYR2ZrhhvN",
	"/ip4/13.229.45.41/tcp/4001/btfs/QmX7RZXh27AX8iv2BKLGMgPBiuUpEy8p4LFXgtXAfaZDn9",
	"/ip4/54.254.227.188/tcp/4001/btfs/QmYqCq3PasrzLr3PxtLo5D6spEAJ836W9Re9Eo4zUou45U",
	"/ip4/52.77.240.134/tcp/4001/btfs/QmURPwdLYesWUDB66EGXvDvwcyV44rVRqV2iGNqKN24eVu",
	"/ip4/3.120.224.94/tcp/4001/btfs/QmWTTmvchTodUaVvuKZMo67xk7ZgkxJf4nBo7SZry3vGU5",
	"/ip4/18.194.71.27/tcp/4001/btfs/QmYHkY5CrWcvgaDo4PfvzTQgaZtfaqRGDjwW1MrHUj8cLK",
	"/ip4/54.93.47.134/tcp/4001/btfs/QmeHaHe7WvjeY37z5MYC3qYQcQcuvDwUhwTXtP3KhKLXXK",
}

DefaultBootstrapAddresses are the hardcoded bootstrap addresses for IPFS. they are nodes run by the IPFS team. docs on these later. As with all p2p networks, bootstrap is an important security concern.

NOTE: This is here -- and not inside cmd/btfs/init.go -- because of an import dependency issue. TODO: move this into a config/default/ package.

View Source
var ErrInvalidPeerAddr = errors.New("invalid peer address")

ErrInvalidPeerAddr signals an address is not a valid peer address.

View Source
var Profiles = map[string]Profile{
	"server": {
		Description: `Disables local host discovery, recommended when
running IPFS on machines with public IPv4 addresses.`,

		Transform: func(c *Config) error {
			c.Addresses.NoAnnounce = appendSingle(c.Addresses.NoAnnounce, defaultServerFilters)
			c.Swarm.AddrFilters = appendSingle(c.Swarm.AddrFilters, defaultServerFilters)
			c.Discovery.MDNS.Enabled = false
			c.Swarm.DisableNatPortMap = true
			return nil
		},
	},

	"local-discovery": {
		Description: `Sets default values to fields affected by the server
profile, enables discovery in local networks.`,

		Transform: func(c *Config) error {
			c.Addresses.NoAnnounce = deleteEntries(c.Addresses.NoAnnounce, defaultServerFilters)
			c.Swarm.AddrFilters = deleteEntries(c.Swarm.AddrFilters, defaultServerFilters)
			c.Discovery.MDNS.Enabled = true
			c.Swarm.DisableNatPortMap = false
			return nil
		},
	},
	"test": {
		Description: `Reduces external interference of IPFS daemon, this
is useful when using the daemon in test environments.`,

		Transform: func(c *Config) error {
			c.Addresses.API = Strings{"/ip4/127.0.0.1/tcp/0"}
			c.Addresses.Gateway = Strings{"/ip4/127.0.0.1/tcp/0"}
			c.Addresses.Swarm = []string{
				"/ip4/127.0.0.1/tcp/0",
			}

			c.Swarm.DisableNatPortMap = true

			c.Bootstrap = []string{}
			c.Discovery.MDNS.Enabled = false
			return nil
		},
	},
	"default-networking": {
		Description: `Restores default network settings.
Inverse profile of the test profile.`,

		Transform: func(c *Config) error {
			c.Addresses = addressesConfig()

			bootstrapPeers, err := DefaultBootstrapPeers()
			if err != nil {
				return err
			}
			c.Bootstrap = appendSingle(c.Bootstrap, BootstrapPeerStrings(bootstrapPeers))

			c.Swarm.DisableNatPortMap = false
			c.Discovery.MDNS.Enabled = true
			return nil
		},
	},
	"announce-public": {
		Description: `Announce public IP when running on cloud VM or local network.`,
		Transform: func(c *Config) error {
			address, err := ExternalIP()
			if err != nil {
				return err
			}
			c.Addresses.Announce = appendSingle(c.Addresses.Announce, []string{address})
			return nil
		},
	},
	"badgerds": {
		Description: `Replaces default datastore configuration with experimental
badger datastore.

If you apply this profile after ipfs init, you will need
to convert your datastore to the new configuration.
You can do this using ipfs-ds-convert.

For more on ipfs-ds-convert see
$ ipfs-ds-convert --help
and
$ ipfs-ds-convert convert --help

WARNING: badger datastore is experimental.
Make sure to backup your data frequently.`,

		Transform: func(c *Config) error {
			c.Datastore.Spec = map[string]interface{}{
				"type":   "measure",
				"prefix": "badger.datastore",
				"child": map[string]interface{}{
					"type":       "badgerds",
					"path":       "badgerds",
					"syncWrites": true,
					"truncate":   true,
				},
			}
			return nil
		},
	},
	"default-datastore": {
		Description: `Restores default datastore configuration.

If you apply this profile after ipfs init, you will need
to convert your datastore to the new configuration.
You can do this using ipfs-ds-convert.

For more on ipfs-ds-convert see
$ ipfs-ds-convert --help
and
$ ipfs-ds-convert convert --help
`,

		Transform: func(c *Config) error {
			c.Datastore.Spec = DefaultDatastoreConfig().Spec
			return nil
		},
	},
	"lowpower": {
		Description: `Reduces daemon overhead on the system. May affect node
functionality - performance of content discovery and data
fetching may be degraded.
`,
		Transform: func(c *Config) error {
			c.Routing.Type = "dhtclient"
			c.Reprovider.Interval = "0"

			c.Swarm.ConnMgr.LowWater = 20
			c.Swarm.ConnMgr.HighWater = 40
			c.Swarm.ConnMgr.GracePeriod = time.Minute.String()
			return nil
		},
	},
	"randomports": {
		Description: `Use a random port number for swarm.`,

		Transform: func(c *Config) error {
			port, err := getAvailablePort()
			if err != nil {
				return err
			}
			c.Addresses.Swarm = []string{
				fmt.Sprintf("/ip4/0.0.0.0/tcp/%d", port),
				fmt.Sprintf("/ip6/::/tcp/%d", port),
			}
			return nil
		},
	},
	"storage-host": {
		Description: `Configures necessary flags and options for node to become a storage host.`,

		Transform: func(c *Config) error {
			c.Experimental.Libp2pStreamMounting = true
			c.Experimental.StorageHostEnabled = true
			c.Addresses.RemoteAPI = Strings{"/ip4/0.0.0.0/tcp/5101"}

			return nil
		},
	},
	"storage-client": {
		Description: `Configures necessary flags and options for node to pay to store files on the network.`,

		Transform: func(c *Config) error {
			c.Experimental.Libp2pStreamMounting = true
			c.Experimental.StorageClientEnabled = true
			c.Experimental.HostsSyncEnabled = true
			c.Experimental.HostsSyncMode = DefaultHostsSyncMode
			c.Addresses.RemoteAPI = Strings{"/ip4/0.0.0.0/tcp/5101"}

			return nil
		},
	},
}

Profiles is a map holding configuration transformers. Docs are in docs/config.md

Functions

func BootstrapPeerStrings

func BootstrapPeerStrings(bps []peer.AddrInfo) []string

BootstrapPeerStrings formats a list of AddrInfos as a bootstrap peer list suitable for serialization.

func DataStorePath

func DataStorePath(configroot string) (string, error)

DataStorePath returns the default data store path given a configuration root (set an empty string to have the default configuration root)

func DefaultBootstrapPeers

func DefaultBootstrapPeers() ([]peer.AddrInfo, error)

DefaultBootstrapPeers returns the (parsed) set of default bootstrap peers. if it fails, it returns a meaningful error for the user. This is here (and not inside cmd/btfs/init) because of module dependency problems.

func ExternalIP added in v0.1.2

func ExternalIP() (string, error)

func Filename

func Filename(configroot string) (string, error)

Filename returns the configuration file path given a configuration root directory. If the configuration root directory is empty, use the default one

func HumanOutput

func HumanOutput(value interface{}) ([]byte, error)

HumanOutput gets a config value ready for printing

func Marshal

func Marshal(value interface{}) ([]byte, error)

Marshal configuration with JSON

func ParseBootstrapPeers

func ParseBootstrapPeers(addrs []string) ([]peer.AddrInfo, error)

ParseBootstrapPeer parses a bootstrap list into a list of AddrInfos.

func Path

func Path(configroot, extension string) (string, error)

Path returns the path `extension` relative to the configuration root. If an empty string is provided for `configroot`, the default root is used.

func PathRoot

func PathRoot() (string, error)

PathRoot returns the default configuration root directory

func ToMap

func ToMap(conf *Config) (map[string]interface{}, error)

Types

type API

type API struct {
	HTTPHeaders map[string][]string // HTTP headers to return with the API.
}

type Addresses

type Addresses struct {
	Swarm      []string // addresses for the swarm to listen on
	Announce   []string // swarm addresses to announce to the network
	NoAnnounce []string // swarm addresses not to announce to the network
	API        Strings  // address for the local API (RPC)
	Gateway    Strings  // address to listen on for BTFS HTTP object gateway
	RemoteAPI  Strings  // address to listen for remote API (RPC over libp2p)
}

Addresses stores the (string) multiaddr addresses for the node.

type Config

type Config struct {
	Identity  Identity  // local node's peer identity
	Datastore Datastore // local node's storage
	Addresses Addresses // local node's addresses
	Mounts    Mounts    // local node's mount points
	Discovery Discovery // local node's discovery mechanisms
	Routing   Routing   // local node's routing settings
	Ipns      Ipns      // Ipns settings
	Bootstrap []string  // local nodes's bootstrap peer addresses
	Gateway   Gateway   // local node's gateway server options
	API       API       // local node's API settings
	Swarm     SwarmConfig
	Pubsub    PubsubConfig

	Provider           Provider
	Reprovider         Reprovider
	StatusServerDomain string
	Experimental       Experiments
}

Config is used to load ipfs config files.

func FromMap

func FromMap(v map[string]interface{}) (*Config, error)

func Init

func Init(out io.Writer, nBitsForKeypair int, keyType string, importKey string, rmOnUnpin bool) (*Config, error)

func (*Config) BootstrapPeers

func (c *Config) BootstrapPeers() ([]peer.AddrInfo, error)

func (*Config) Clone

func (c *Config) Clone() (*Config, error)

Clone copies the config. Use when updating.

func (*Config) SetBootstrapPeers

func (c *Config) SetBootstrapPeers(bps []peer.AddrInfo)

type ConnMgr

type ConnMgr struct {
	Type        string
	LowWater    int
	HighWater   int
	GracePeriod string
}

ConnMgr defines configuration options for the libp2p connection manager

type Datastore

type Datastore struct {
	StorageMax         string // in B, kB, kiB, MB, ...
	StorageGCWatermark int64  // in percentage to multiply on StorageMax
	GCPeriod           string // in ns, us, ms, s, m, h

	// deprecated fields, use Spec
	Type   string           `json:",omitempty"`
	Path   string           `json:",omitempty"`
	NoSync bool             `json:",omitempty"`
	Params *json.RawMessage `json:",omitempty"`

	Spec map[string]interface{}

	HashOnRead      bool
	BloomFilterSize int
}

Datastore tracks the configuration of the datastore.

func DefaultDatastoreConfig

func DefaultDatastoreConfig() Datastore

DefaultDatastoreConfig is an internal function exported to aid in testing.

type Discovery

type Discovery struct {
	MDNS MDNS
}

type Experiments

type Experiments struct {
	FilestoreEnabled     bool
	UrlstoreEnabled      bool
	ShardingEnabled      bool
	Libp2pStreamMounting bool
	P2pHttpProxy         bool
	QUIC                 bool
	PreferTLS            bool
	StrategicProviding   bool
	StorageHostEnabled   bool
	StorageClientEnabled bool
	Analytics            bool
	RemoveOnUnpin        bool
	HostsSyncEnabled     bool
	HostsSyncMode        string
}

type Gateway

type Gateway struct {
	HTTPHeaders  map[string][]string // HTTP headers to return with the gateway
	RootRedirect string
	Writable     bool
	PathPrefixes []string
	APICommands  []string
	NoFetch      bool
}

Gateway contains options for the HTTP gateway server.

type Identity

type Identity struct {
	PeerID  string
	PrivKey string `json:",omitempty"`
}

Identity tracks the configuration of the local node's identity.

func (*Identity) DecodePrivateKey

func (i *Identity) DecodePrivateKey(passphrase string) (ic.PrivKey, error)

DecodePrivateKey is a helper to decode the users PrivateKey

type Ipns

type Ipns struct {
	RepublishPeriod string
	RecordLifetime  string

	ResolveCacheSize int
}

type MDNS

type MDNS struct {
	Enabled bool

	// Time in seconds between discovery rounds
	Interval int
}

type Mounts

type Mounts struct {
	IPFS           string
	IPNS           string
	FuseAllowOther bool
}

Mounts stores the (string) mount points

type Profile

type Profile struct {
	// Description briefly describes the functionality of the profile
	Description string

	// Transform takes ipfs configuration and applies the profile to it
	Transform Transformer
}

Profile contains the profile transformer the description of the profile

type Provider

type Provider struct {
	Strategy string // Which keys to announce
}

type PubsubConfig

type PubsubConfig struct {
	// Router can be either floodsub (legacy) or gossipsub (new and
	// backwards compatible).
	Router string

	// DisableSigning disables message signing. Message signing is *enabled*
	// by default.
	DisableSigning bool

	// StrictSignatureVerification enables strict signature verification.
	// When enabled, unsigned messages will be rejected. Eventually, this
	// will be made the default and this option will disappear. Once this
	// happens, networks will either need to completely disable or
	// completely enable message signing.
	StrictSignatureVerification bool
}

type Reprovider

type Reprovider struct {
	Interval string // Time period to reprovide locally stored objects to the network
	Strategy string // Which keys to announce
}

type Routing

type Routing struct {
	// Type sets default daemon routing mode.
	Type string
}

Routing defines configuration options for libp2p routing

type Strings

type Strings []string

Strings is a helper type that (un)marshals a single string to/from a single JSON string and a slice of strings to/from a JSON array of strings.

func (Strings) MarshalJSON

func (o Strings) MarshalJSON() ([]byte, error)

MarshalJSON conforms to the json.Marshaler interface.

func (*Strings) UnmarshalJSON

func (o *Strings) UnmarshalJSON(data []byte) error

UnmarshalJSON conforms to the json.Unmarshaler interface.

type SwarmConfig

type SwarmConfig struct {
	AddrFilters             []string
	DisableBandwidthMetrics bool
	DisableNatPortMap       bool
	DisableRelay            bool
	EnableRelayHop          bool

	// autorelay functionality
	// if true, then the libp2p host will be constructed with autorelay functionality.
	EnableAutoRelay bool
	// if true, then an AutoNATService will be instantiated to facilitate autorelay
	EnableAutoNATService bool

	ConnMgr ConnMgr
}

type Transformer

type Transformer func(c *Config) error

Transformer is a function which takes configuration and applies some filter to it

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL