Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 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:"-"` // 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 // 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.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a container on which services can be registered.
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 ¶
Restart terminates a running node and boots up a new one in its place. If the node isn't running, an error is returned.
type Service ¶
type Service interface { // 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 {
// 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) OpenDatabase ¶
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.