node

package
v0.0.0-...-471f645 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrServiceUnknown unknown service
	ErrServiceUnknown = errors.New("unknown service")
	// ErrDatadirUsed datadir already used by another process,datadir can only be accessed by a process.
	ErrDatadirUsed = errors.New("datadir already used by another process")
	// ErrNodeStopped node not started
	ErrNodeStopped = errors.New("node not started")
	// ErrNodeRunning node already running
	ErrNodeRunning = errors.New("node already running")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Name    string
	DataDir string `mapstructure:"datadir"`
	IPCPath string `mapstructure:"ipcpath"`

	HTTPHost         string   `mapstructure:"httphost"`
	HTTPPort         int      `mapstructure:"httpport"`
	HTTPModules      []string `mapstructure:"httpmodules"`
	HTTPCors         []string `mapstructure:"httpcors"`
	HTTPVirtualHosts []string `mapstructure:"httpvirtualhosts"`

	WSHost      string   `mapstructure:"wshost"`
	WSPort      int      `mapstructure:"wsport"`
	WSModules   []string `mapstructure:"wsmodules"`
	WSOrigins   []string `mapstructure:"wsorigins"`
	WSExposeAll bool     `mapstructure:"wsexposall"`

	// p2p
	P2PBootNodes    string `mapstructure:"bootnodes"`
	P2PStaticNodes  string `mapstructure:"staticnodes"`
	P2PTrustNodes   string `mapstructure:"trustnodes"`
	P2PNodeDatabase string `mapstructure:"nodedb"`

	P2PConfig *p2p.Config `mapstructure:"p2p"`

	// 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.

func NewConfig

func NewConfig(name, datadir string) *Config

NewConfig initialize config

func (*Config) BootNodes

func (c *Config) BootNodes() []*enode.Node

BootNodes returns a list of node enode URLs configured as boot nodes.

func (*Config) HTTPEndpoint

func (c *Config) HTTPEndpoint() string

HTTPEndpoint resolves an HTTP endpoint based on the configured host interface and port parameters.

func (*Config) IPCEndpoint

func (c *Config) IPCEndpoint() string

IPCEndpoint resolves an RPC endpoint based on a configured value, taking into account the set data folders as well as the designated platform we're currently running on.

func (*Config) NodeDB

func (c *Config) NodeDB() string

NodeDB returns the path of nodedatabase

func (*Config) NodeKey

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

func (*Config) StaticNodes

func (c *Config) StaticNodes() []*enode.Node

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

func (*Config) TrustedNodes

func (c *Config) TrustedNodes() []*enode.Node

TrustedNodes returns a list of node enode URLs configured as trusted nodes.

func (*Config) WSEndpoint

func (c *Config) WSEndpoint() string

WSEndpoint resolves a websocket endpoint based on the configured host interface and port parameters.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node is a container on which services can be registered.

func New

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

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

func (*Node) GetNodeConfig

func (n *Node) GetNodeConfig() *ServiceContext

func (*Node) Register

func (n *Node) Register(constructor ServiceConstructor) 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) Restart

func (n *Node) Restart() error

Restart terminates a running node and boots up a new one in its place. If the node isn't running, an error is returned.

func (*Node) Service

func (n *Node) Service(service interface{}) error

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

func (*Node) Start

func (n *Node) Start() error

Start create a live 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.

func (*Node) Wait

func (n *Node) Wait()

Wait blocks the thread until the node is stopped. If the node is not running at the time of invocation, the method immediately returns.

type Service

type Service interface {
	// todo 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.
	// todo Start(server *p2p.Server) error
	Start() error

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

Service is an individual protocol that can be registered into a node.

type ServiceConstructor

type ServiceConstructor func(ctx *ServiceContext) (Service, error)

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

type ServiceContext

type ServiceContext struct {
	P2P *adaptor.ProtoAdaptor
	// contains filtered or unexported fields
}

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 (*ServiceContext) AppendBootNodes

func (ctx *ServiceContext) AppendBootNodes(nodes []string)

AppendBootNodes the enode URLs of the P2P bootstrap nodes running on the network.

func (*ServiceContext) OpenDatabase

func (ctx *ServiceContext) OpenDatabase(name string, cache int, handles int) (fdb.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 (*ServiceContext) ResolvePath

func (ctx *ServiceContext) 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 (*ServiceContext) Service

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

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

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