node

package
v0.0.0-...-585dd88 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: LGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDatadirUsed    = errors.New("datadir already used by another process")
	ErrNodeStopped    = errors.New("node not started")
	ErrNodeRunning    = errors.New("node already running")
	ErrServiceUnknown = errors.New("unknown service")
)
View Source
var DefaultConfig = NodeConfig{
	DataDir: DefaultDataDir(),
}

DefaultConfig contains reasonable default settings.

Functions

func DefaultDataDir

func DefaultDataDir() string

DefaultDataDir is the default data directory to use for the databases and other persistence requirements.

func MakeAccountManager

func MakeAccountManager(conf *NodeConfig) (*accounts.Manager, error)

Types

type DuplicateServiceError

type DuplicateServiceError struct {
	Kind reflect.Type
}

DuplicateServiceError is returned during Node startup if a registered service constructor returns a service of the same type that was already started.

func (*DuplicateServiceError) Error

func (e *DuplicateServiceError) Error() string

Error generates a textual representation of the duplicate service error.

type FTransService

type FTransService interface {
	// Protocols retrieves the P2P protocols the service wishes to start.
	Protocols() []p2p.Protocol

	// APIs retrieves the list of RPC descriptors the service provides
	APIs() []rpc.API

	// Start is called after all services have been constructed and the networking
	// layer was also initialized to spawn any goroutines required by the service.
	StartClient(*p2p.Client) error

	// Stop terminates all goroutines belonging to the service, blocking until they
	// are all terminated.
	Stop() error
}

type FTransServiceConstructor

type FTransServiceConstructor func(ctx *FTransServiceContext) (FTransService, error)

ServiceConstructor is the function signature of the constructors needed to be registered for service instantiation.

type FTransServiceContext

type FTransServiceContext struct {
	Config         *NodeConfig
	Services       map[reflect.Type]FTransService // Index of the already constructed services
	EventMux       *event.TypeMux                 // Event multiplexer used for decoupled notifications
	AccountManager *accounts.Manager              // Account manager created by the node.
}

ServiceContext is a collection of service independent options inherited from the protocol stack, that is passed to all constructors to be optionally used; as well as utility methods to operate on the service environment.

func (*FTransServiceContext) OpenDatabase

func (ctx *FTransServiceContext) OpenDatabase(name string, cache int, handles int) (ethdb.Database, error)

OpenDatabase opens an existing database with the given name (or creates one if no previous can be found) from within the node's data directory. If the node is an ephemeral one, a memory database is returned.

func (*FTransServiceContext) ResolvePath

func (ctx *FTransServiceContext) ResolvePath(path string) string

ResolvePath resolves a user path into the data directory if that was relative and if the user actually uses persistent storage. It will return an empty string for emphemeral storage and the user's own input for absolute paths.

func (*FTransServiceContext) Service

func (ctx *FTransServiceContext) Service(service interface{}) error

Service retrieves a currently running service registered of a specific type.

func (*FTransServiceContext) SetService

func (s *FTransServiceContext) SetService(kind reflect.Type, srv FTransService)

type Node

type Node struct {
	FTransAPI *ftransfer.PrivateFTransAPI
	Peer      *p2p.Peer
	// contains filtered or unexported fields
}

Node is a container on which services can be registered.

func New

func New(conf *NodeConfig) (*Node, error)

New creates a new P2P node, ready for protocol registration.

func (*Node) GetAccMan

func (n *Node) GetAccMan() *accounts.Manager

GetAccMan retrieves the account manager.

func (*Node) GetConfig

func (n *Node) GetConfig() *NodeConfig

GetConfig retrieves the node config.

func (*Node) Register

func (n *Node) Register(constructor FTransServiceConstructor) error

Register injects a new service into the node's stack. The service created by the passed constructor must be unique in its type with regard to sibling ones.

func (*Node) SetConfig

func (n *Node) SetConfig(cfg *NodeConfig)

SetConfig retrieves the node config.

func (*Node) Start

func (n *Node) Start() error

Start create a live P2P node and starts running it.

func (*Node) Stop

func (n *Node) Stop() error

Stop terminates a running node along with all it's services. In the node was not started, an error is returned.

type NodeConfig

type NodeConfig struct {
	// Name sets the instance name of the node. It must not contain the / character and is
	// used in the devp2p node identifier. The instance name of geth is "geth". If no
	// value is specified, the basename of the current executable is used.
	Name string `toml:"-"`

	// BasePassphrase used for the base passphrase of the FTP
	BaseAddress    string
	BasePassphrase string

	// Version should be set to the version number of the program. It is used
	// in the devp2p node identifier.
	Version string `toml:"-"`

	// DataDir is the file system folder the node should use for any data storage
	// requirements. The configured data directory will not be directly shared with
	// registered services, instead those can use utility methods to create/access
	// databases or flat files. This enables ephemeral nodes which can fully reside
	// in memory.
	DataDir string

	// Configuration of peer-to-peer networking.
	P2P p2p.ClientCfg

	// Logger is a custom logger to use with the p2p.Server.
	Logger log.Logger `toml:",omitempty"`
}

Config represents a small collection of configuration values to fine tune the P2P network layer of a protocol stack. These values can be further extended by all registered services.

func (*NodeConfig) AccountConfig

func (c *NodeConfig) AccountConfig() (int, int, string)

AccountConfig determines the settings for scrypt and keydirectory

func (*NodeConfig) NodeDB

func (c *NodeConfig) NodeDB() string

NodeDB returns the path to the discovery node database.

func (*NodeConfig) NodeKey

func (c *NodeConfig) NodeKey() *ecdsa.PrivateKey

NodeKey retrieves the currently configured private key of the node, checking first any manually set key, falling back to the one found in the configured data folder. If no key can be found, a new one is generated.

func (*NodeConfig) NodeName

func (c *NodeConfig) NodeName() string

NodeName returns the devp2p node identifier.

func (*NodeConfig) StaticNodes

func (c *NodeConfig) StaticNodes() []*discover.Node

StaticNodes returns a list of node enode URLs configured as static nodes.

type StopError

type StopError struct {
	Server   error
	Services map[reflect.Type]error
}

StopError is returned if a Node fails to stop either any of its registered services or itself.

func (*StopError) Error

func (e *StopError) Error() string

Error generates a textual representation of the stop error.

Jump to

Keyboard shortcuts

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