config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BootstrapList = []string{
		"/ip4/13.234.78.241/udp/4000/quic/p2p/QmVbcMycaK8ni5CeiM7JRjBRAdmwky6dQ6KcoxLesZDPk9",
	}

	RpcURI               = "127.0.0.1:"
	RpcPort              = 5555
	BootstrapRefreshRate = 15 * time.Second
)
View Source
var (
	True  = true
	False = false
)

Alias for true and false

View Source
var DefaultAccountCert = func(cfg *Config) error {
	cfg.AccountCert = nil
	return nil
}

DefaultAccountCert defines a nil cert. A new cert will be created when the client starts

View Source
var DefaultAccountPrvKey = func(cfg *Config) error {
	cfg.AccountPrvKey = nil
	return nil
}

DefaultAccountPrvKey defines a nil default account. A new account will be created when the client starts.

View Source
var DefaultBootstrapNodes = func(cfg *Config) error {
	cfg.BootstrapNodes = BootstrapList
	return nil
}

DefaultBootstrapNodes assigns few nodes helping in bootstrapping.

View Source
var DefaultBootstrapRefreshRate = func(cfg *Config) error {
	cfg.BootstrapRefreshRate = BootstrapRefreshRate
	return nil
}

DefaultBootstrapRefreshRate specifies time interval to look for new peer nodes

View Source
var DefaultBootstrapRendezvous = func(cfg *Config) error {
	cfg.BootstrapRendezvous = ""
	return nil
}

DefaultBootstrapRendezvous is a string to announce and find more nodes related to similar data topic. It is unique to each data topic to get better graph neighbours (nodes sending/receiving similar kind of data).

View Source
var DefaultHostString = func(cfg *Config) error {
	cfg.Host = "0.0.0.0"
	return nil
}

DefaultHostString defines host to listen on

View Source
var DefaultPortString = func(cfg *Config) error {
	cfg.Port = "0"
	return nil
}

DefaultPortString defines port to listen on

View Source
var DefaultRPCConfig = func(cfg *Config) error {
	cfg.RPC = []RPCConfig{
		RPCConfig{
			Endpoint: RpcURI + strconv.Itoa(RpcPort),
			Mode:     "raw",
		},
	}
	return nil
}

DefaultRPCConfig defines listen address and mode of RPC

View Source
var DefaultRelayAsAService = func(cfg *Config) error {
	cfg.RelayAsAService = new(bool)
	*cfg.RelayAsAService = false
	return nil
}

DefaultRelayAsAService defines if this node gives relay service to others

View Source
var DefaultRemoteAccessURI = func(cfg *Config) error {
	cfg.RemoteAccessURI = remoteURI
	return nil
}

DefaultRemoteAccessURI defines a remote point URL which is used for authentication of data topics, publishers and subscribers. It can be a central server or a blockchain service. It should support interface defined in 'interface/blockchain/blockchain.go'

View Source
var Defaults = []struct {
	Fallback func(cfg *Config) bool
	Opt      Option
}{
	{
		Fallback: func(cfg *Config) bool { return cfg.AccountPrvKey == nil },
		Opt:      DefaultAccountPrvKey,
	},
	{
		Fallback: func(cfg *Config) bool { return cfg.AccountCert == nil },
		Opt:      DefaultAccountCert,
	},
	{
		Fallback: func(cfg *Config) bool { return cfg.BootstrapNodes == nil },
		Opt:      DefaultBootstrapNodes,
	},
	{
		Fallback: func(cfg *Config) bool { return cfg.BootstrapRendezvous == "" },
		Opt:      DefaultBootstrapRendezvous,
	},
	{
		Fallback: func(cfg *Config) bool { return cfg.BootstrapRefreshRate == 0 },
		Opt:      DefaultBootstrapRefreshRate,
	},
	{
		Fallback: func(cfg *Config) bool { return cfg.RemoteAccessURI == "" },
		Opt:      DefaultRemoteAccessURI,
	},
	{
		Fallback: func(cfg *Config) bool { return cfg.RPC == nil },
		Opt:      DefaultRPCConfig,
	},
	{
		Fallback: func(cfg *Config) bool { return cfg.Host == "" },
		Opt:      DefaultHostString,
	},
	{
		Fallback: func(cfg *Config) bool { return cfg.Port == "" },
		Opt:      DefaultPortString,
	},
	{
		Fallback: func(cfg *Config) bool { return cfg.RelayAsAService == nil },
		Opt:      DefaultRelayAsAService,
	},
}

Defaults contains the conditions for which defaults are defined.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Accounts
	AccountPrvKey crypto.PrivKey
	AccountCert   *x509.Certificate

	// Bootstrap
	BootstrapNodes       []string
	BootstrapRendezvous  string
	BootstrapRefreshRate time.Duration

	// Remote Access
	RemoteAccessURI        string // TODO: what about the contract address?????
	RemoteAccessPrivateKey *ecdsa.PrivateKey

	// RPC
	RPC []RPCConfig

	// Listening socket
	Host string
	Port string

	// Relay
	RelayAsAService *bool
}

Config struct defines what options can be passed to the mesh client.

func NewConfig

func NewConfig(opts ...Option) (*Config, error)

NewConfig return new configuration with default or new options set.

func (*Config) ApplyOpts

func (c *Config) ApplyOpts(opts ...Option) error

ApplyOpts executes all option functions.

type Option

type Option func(cfg *Config) error

Option defines a function to help assign configs.

var DefaultOptions Option = func(cfg *Config) error {
	for _, defaultCfg := range Defaults {
		if !defaultCfg.Fallback(cfg) {
			continue
		}

		cfg.ApplyOpts(defaultCfg.Opt)
	}
	return nil
}

DefaultOptions sets some default values.

type RPCConfig

type RPCConfig struct {
	Endpoint string
	Mode     string
	CertPath string
	KeyPath  string
}

RPCConfig defines RPC endpoint and mode ["raw" and "web"]

Jump to

Keyboard shortcuts

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