config

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2021 License: MIT Imports: 12 Imported by: 4

Documentation

Overview

Package config defines the configuration for a Babble node.

Regardless of how Babble is started, directly from Go code or as a standalone process from the command line, it uses the Config object defined in this package to store and forward configuration options. On top of these configuration options, Babble relies on a data directory, defined by Config.DataDir, where it expects to find a few additional configuration files:

priv_key // a plain text file containing the raw private key (cf. babble keygen).
peers.json // a JSON file containing the current list of peers.
peers.genesis.json // (optional, defaults to peers.json) a JSON file containing the initial list of peers.
cert.pem // (optional) an x509 certificate for the WebRTC signaling server.

Index

Constants

View Source
const (
	// DefaultKeyfile is the default name of the file containing the validator's
	// private key
	DefaultKeyfile = "priv_key"

	// DefaultBadgerFile is the default name of the folder containing the Badger
	// database
	DefaultBadgerFile = "badger_db"

	// DefaultCertFile is the default name of the file containing the TLS
	// certificate for connecting to the signaling server.
	DefaultCertFile = "cert.pem"
)

Default filenames.

View Source
const (
	DefaultLogLevel             = "debug"
	DefaultBindAddr             = "127.0.0.1:1337"
	DefaultServiceAddr          = "127.0.0.1:8000"
	DefaultHeartbeatTimeout     = 10 * time.Millisecond
	DefaultSlowHeartbeatTimeout = 1000 * time.Millisecond
	DefaultTCPTimeout           = 1000 * time.Millisecond
	DefaultJoinTimeout          = 10000 * time.Millisecond
	DefaultCacheSize            = 10000
	DefaultSyncLimit            = 1000
	DefaultMaxPool              = 2
	DefaultStore                = false
	DefaultMaintenanceMode      = false
	DefaultSuspendLimit         = 100
	DefaultWebRTC               = false
	DefaultSignalAddr           = "127.0.0.1:2443"
	DefaultSignalRealm          = "main"
	DefaultSignalSkipVerify     = false
	DefaultICEAddress           = "stun:stun.l.google.com:19302"
	DefaultICEUsername          = ""
	DefaultICEPassword          = ""
)

Default configuration values.

Variables

This section is empty.

Functions

func DefaultDataDir

func DefaultDataDir() string

DefaultDataDir return the default directory name for top-level Babble config based on the underlying OS, attempting to respect conventions.

func DefaultDatabaseDir added in v0.5.8

func DefaultDatabaseDir() string

DefaultDatabaseDir returns the default path for the badger database files.

func DefaultICEServers added in v0.8.0

func DefaultICEServers() []webrtc.ICEServer

DefaultICEServers returns the default ICE configuration with one URL pointing to a public Google STUN server.

func HomeDir

func HomeDir() string

HomeDir returns the user's home directory.

func LogLevel

func LogLevel(l string) logrus.Level

LogLevel parses a string into a Logrus log level.

Types

type Config

type Config struct {
	// DataDir is the top-level directory containing Babble configuration and
	// data
	DataDir string `mapstructure:"datadir"`

	// LogLevel determines the chattiness of the log output.
	LogLevel string `mapstructure:"log"`

	// BindAddr is the local address:port where this node gossips with other
	// nodes. in some cases, there may be a routable address that cannot be
	// bound. Use AdvertiseAddr to advertise a different address to support
	// this. If this address is not routable, the node will be in a constant
	// flapping state as other nodes will treat the non-routability as a
	// failure.
	BindAddr string `mapstructure:"listen"`

	// AdvertiseAddr is used to change the address that we advertise to other
	// nodes.
	AdvertiseAddr string `mapstructure:"advertise"`

	// NoService disables the HTTP API service.
	NoService bool `mapstructure:"no-service"`

	// ServiceAddr is the address:port of the optional HTTP service. If not
	// specified, and "no-service" is not set, the API handlers are registered
	// with the DefaultServerMux of the http package. It is possible that
	// another server in the same process is simultaneously using the
	// DefaultServerMux. In which case, the handlers will be accessible from
	// both servers. This is usefull when Babble is used in-memory and expected
	// to use the same endpoint (address:port) as the application's API.
	ServiceAddr string `mapstructure:"service-listen"`

	// HeartbeatTimeout is the frequency of the gossip timer when the node has
	// something to gossip about.
	HeartbeatTimeout time.Duration `mapstructure:"heartbeat"`

	// SlowHeartbeatTimeout is the frequency of the gossip timer when the node
	// has nothing to gossip about.
	SlowHeartbeatTimeout time.Duration `mapstructure:"slow-heartbeat"`

	// MaxPool controls how many connections are pooled per target in the gossip
	// routines.
	MaxPool int `mapstructure:"max-pool"`

	// TCPTimeout is the timeout of gossip RPC connections. It also applies to
	// WebRTC connections.
	TCPTimeout time.Duration `mapstructure:"timeout"`

	// JoinTimeout is the timeout of Join Requests
	JoinTimeout time.Duration `mapstructure:"join_timeout"`

	// SyncLimit defines the max number of hashgraph events to include in a
	// SyncResponse or EagerSyncRequest
	SyncLimit int `mapstructure:"sync-limit"`

	// EnableFastSync enables the FastSync protocol.
	EnableFastSync bool `mapstructure:"fast-sync"`

	// Store activates persistant storage.
	Store bool `mapstructure:"store"`

	// DatabaseDir is the directory containing database files.
	DatabaseDir string `mapstructure:"db"`

	// CacheSize is the max number of items in in-memory caches.
	CacheSize int `mapstructure:"cache-size"`

	// Bootstrap determines whether or not to load Babble from an existing
	// database file. Forces Store, ie. bootstrap only works with a persistant
	// database store.
	Bootstrap bool `mapstructure:"bootstrap"`

	// MaintenanceMode when set to true causes Babble to initialise in a
	// suspended state. I.e. it does not start gossipping. Forces Bootstrap,
	// which itself forces Store. I.e. MaintenanceMode only works if the node is
	// bootstrapped from an existing database.
	MaintenanceMode bool `mapstructure:"maintenance-mode"`

	// SuspendLimit is the multiplier that is dynamically applied to the number
	// of validators to determine the limit of undetermined events (events which
	// haven't reached consensus) that will cause the node to become suspended.
	// For example, if there are 4 validators and SuspendLimit=100, then the
	// node will suspend itself after registering 400 undetermined events.
	SuspendLimit int `mapstructure:"suspend-limit"`

	// Moniker defines the friendly name of this node
	Moniker string `mapstructure:"moniker"`

	// WebRTC determines whether to use a WebRTC transport. WebRTC uses a very
	// different protocol stack than TCP/IP and enables peers to connect
	// directly even with multiple layers of NAT between them, such as in
	// cellular networks. WebRTC relies on a signalling server who's address is
	// specified by SignalAddr. When WebRTC is enabled, BindAddr and
	// AdvertiseAddr are ignored.
	WebRTC bool `mapstructure:"webrtc"`

	// SignalAddr is the IP:PORT of the WebRTC signaling server. It is ignored
	// when WebRTC is not enabled. The connection is over secured web-sockets,
	// wss, and it possible to include a self-signed certificated in a file
	// called cert.pem in the datadir. If no self-signed certificate is found,
	// the server's certifacate signing authority better be trusted.
	SignalAddr string `mapstructure:"signal-addr"`

	// SignalRealm is an administrative domain within the WebRTC signaling
	// server. WebRTC signaling messages are only routed within a Realm.
	SignalRealm string `mapstructure:"signal-realm"`

	// SignalSkipVerify controls whether the signal client verifies the server's
	// certificate chain and host name. If SignalSkipVerify is true, TLS accepts
	// any certificate presented by the server and any host name in that
	// certificate. In this mode, TLS is susceptible to man-in-the-middle
	// attacks. This should be used only for testing.
	SignalSkipVerify bool `mapstructure:"signal-skip-verify"`

	// ICE address is the URI of a server providing services for ICE, such as
	// STUN and TURN. The server should support password-based authentication,
	// as Babble will try to connect with the username and password provided in
	// ICEUsername and ICEPassword below. Username adn password can also be
	// empty if the ICE server does not use authentication.
	// https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer/urls
	ICEAddress string `mapstructure:"ice-addr"`

	// ICEUsername is the username that will be used to authenticate with the
	// ICE server defined in ICEAddress.
	ICEUsername string `mapstructure:"ice-username"`

	// ICEPassword is the password that will be used to authenticate with the
	// ICE server defined in ICEAddress.
	ICEPassword string `mapstructure:"ice-password"`

	// Proxy is the application proxy that enables Babble to communicate with
	// the application.
	Proxy proxy.AppProxy

	// Key is the private key of the validator.
	Key *ecdsa.PrivateKey
	// contains filtered or unexported fields
}

Config contains all the configuration properties of a Babble node.

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig returns a config object with default values. All the default configuration values are set, even if they cancel eachother out. For example, When WebRTC = false, all the Signal options are ignored. Likewise, when WebRTC = true, BindAddr and ServiceAddr are not used.

func NewTestConfig

func NewTestConfig(t testing.TB, level logrus.Level) *Config

NewTestConfig returns a config object with default values and a special logger for debugging tests.

func (*Config) CertFile added in v0.8.0

func (c *Config) CertFile() string

CertFile returns the full path of the file containing the signal-server TLS certificate.

func (*Config) ICEServers added in v0.8.0

func (c *Config) ICEServers() []webrtc.ICEServer

ICEServers returns a list of ICE servers used by the WebRTCStreamLayer to connect to peers. The list contains a single item which is based on the configuration passed through the config object. This configuration is limited to a single server, with password-based authentication.

func (*Config) Keyfile

func (c *Config) Keyfile() string

Keyfile returns the full path of the file containing the private key.

func (*Config) Logger

func (c *Config) Logger() *logrus.Entry

Logger returns a formatted logrus Entry, with prefix set to "babble".

func (*Config) SetDataDir added in v0.5.8

func (c *Config) SetDataDir(dataDir string)

SetDataDir sets the top-level Babble directory, and updates the database directory if it is currently set to the default value. If the database directory is not currently the default, it means the user has explicitely set it to something else, so avoid changing it again here.

Jump to

Keyboard shortcuts

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