Documentation ¶
Index ¶
- Variables
- type Config
- type DuplicateServiceError
- type Node
- func (n *Node) Attach() (*rpc.Client, error)
- func (n *Node) DataDir() string
- func (n *Node) EventMux() *event.TypeMux
- func (n *Node) HTTPEndpoint() string
- func (n *Node) IPCEndpoint() string
- func (n *Node) InstanceDir() string
- func (n *Node) OpenDatabase(name string, cache, handles int) (database.Database, error)
- func (n *Node) RPCHandler() (*rpc.Server, error)
- func (n *Node) Register(constructor ServiceConstructor) error
- func (n *Node) ResolvePath(x string) string
- func (n *Node) Restart() error
- func (n *Node) Service(service interface{}) error
- func (n *Node) Start() error
- func (n *Node) Stop() error
- func (n *Node) WSEndpoint() string
- func (n *Node) Wait()
- type PrivateAdminAPI
- func (api *PrivateAdminAPI) StartRPC(endpoint *string, cors *string, apis *string, vhosts *string) (bool, error)
- func (api *PrivateAdminAPI) StartWS(endpoint *string, allowedOrigins *string, apis *string) (bool, error)
- func (api *PrivateAdminAPI) StopRPC() (bool, error)
- func (api *PrivateAdminAPI) StopWS() (bool, error)
- type PublicAdminAPI
- type PublicWeb3API
- type Service
- type ServiceConstructor
- type ServiceContext
- type StopError
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // 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 // KeyStoreDir is the file system folder that contains private keys. The directory can // be specified as a relative path, in which case it is resolved relative to the // current directory. // // If KeyStoreDir is empty, the default location is the "keystore" subdirectory of // DataDir. If DataDir is unspecified and KeyStoreDir is empty, an ephemeral directory // is created by New and destroyed when the node is stopped. KeyStoreDir string `toml:",omitempty"` // UseLightweightKDF lowers the memory and CPU requirements of the key store // scrypt KDF at the expense of security. UseLightweightKDF bool `toml:",omitempty"` // NoUSB disables hardware wallet monitoring and connectivity. NoUSB bool `toml:",omitempty"` // IPCPath is the requested location to place the IPC endpoint. If the path is // a simple file name, it is placed inside the data directory (or on the root // pipe path on Windows), whereas if it's a resolvable path name (absolute or // relative), then that specific path is enforced. An empty path disables IPC. IPCPath string `toml:",omitempty"` // HTTPEndpoint is the endpoint on which to start the HTTP RPC server. The valid // format should be host:port. If this field is empty, no HTTP API endpoint will // be started. HTTPEndpoint string `toml:",omitempty"` // HTTPCors is the Cross-Origin Resource Sharing header to send to requesting // clients. Please be aware that CORS is a browser enforced security, it's fully // useless for custom HTTP clients. HTTPCors []string `toml:",omitempty"` // HTTPVirtualHosts is the list of virtual hostnames which are allowed on incoming requests. // This is by default {'localhost'}. Using this prevents attacks like // DNS rebinding, which bypasses SOP by simply masquerading as being within the same // origin. These attacks do not utilize CORS, since they are not cross-domain. // By explicitly checking the Host-header, the server will not allow requests // made against the server with a malicious host domain. // Requests using ip address directly are not affected HTTPVirtualHosts []string `toml:",omitempty"` // HTTPModules is a list of API modules to expose via the HTTP RPC interface. // If the module list is empty, all RPC API endpoints designated public will be // exposed. HTTPModules []string `toml:",omitempty"` // HTTPTimeouts allows for customization of the timeout values used by the HTTP RPC // interface. HTTPTimeouts rpc.HTTPTimeouts // WSEndpoint is the endpoint on which to start the websocket RPC server. The valid // format should be host:port. If this field is empty, no websocket API endpoint will // be started. WSEndpoint string `toml:",omitempty"` // WSOrigins is the list of domain to accept websocket requests from. Please be // aware that the server can only act upon the HTTP request the client sends and // cannot verify the validity of the request header. WSOrigins []string `toml:",omitempty"` // WSModules is a list of API modules to expose via the websocket RPC interface. // If the module list is empty, all RPC API endpoints designated public will be // exposed. WSModules []string `toml:",omitempty"` // WSExposeAll exposes all API modules via the WebSocket RPC interface rather // than just the public ones. // // *WARNING* Only set this if the node is running in a trusted network, exposing // private APIs to untrusted users is a major security risk. WSExposeAll bool `toml:",omitempty"` // Logger is a custom logger to use with the p2p.Server. Logger logger.Logger `toml:",omitempty"` // MaxConcurrent is the maximum number of concurrent processes handled by rpc MaxConcurrent int `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 (*Config) IPCEndpoint ¶
IPCEndpoint resolves an IPC 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) ResolvePath ¶
ResolvePath resolves path in the instance directory.
type DuplicateServiceError ¶
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 Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a container on which services can be registered.
func (*Node) DataDir ¶
DataDir retrieves the current datadir used by the protocol stack. Deprecated: No files should be stored in this directory, use InstanceDir instead.
func (*Node) EventMux ¶
EventMux retrieves the event multiplexer used by all the network services in the current protocol stack.
func (*Node) HTTPEndpoint ¶
HTTPEndpoint retrieves the current HTTP endpoint used by the protocol stack.
func (*Node) IPCEndpoint ¶
IPCEndpoint retrieves the current IPC endpoint used by the protocol stack.
func (*Node) InstanceDir ¶
InstanceDir retrieves the instance directory used by the protocol stack.
func (*Node) OpenDatabase ¶
OpenDatabase opens an existing database with the given name (or creates one if no previous can be found) from within the node's instance directory. If the node is ephemeral, a memory database is returned.
func (*Node) RPCHandler ¶
RPCHandler returns the in-process RPC request handler.
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) ResolvePath ¶
ResolvePath returns the absolute path of a resource in the instance directory.
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.
func (*Node) Stop ¶
Stop terminates a running node along with all it's services. In the node was not started, an error is returned.
func (*Node) WSEndpoint ¶
WSEndpoint retrieves the current WS endpoint used by the protocol stack.
type PrivateAdminAPI ¶
type PrivateAdminAPI struct {
// contains filtered or unexported fields
}
PrivateAdminAPI is the collection of administrative API methods exposed only over a secure RPC channel.
func NewPrivateAdminAPI ¶
func NewPrivateAdminAPI(node *Node) *PrivateAdminAPI
NewPrivateAdminAPI creates a new API definition for the private admin methods of the node itself.
func (*PrivateAdminAPI) StartRPC ¶
func (api *PrivateAdminAPI) StartRPC(endpoint *string, cors *string, apis *string, vhosts *string) (bool, error)
StartRPC starts the HTTP RPC API server.
func (*PrivateAdminAPI) StartWS ¶
func (api *PrivateAdminAPI) StartWS(endpoint *string, allowedOrigins *string, apis *string) (bool, error)
StartWS starts the websocket RPC API server.
func (*PrivateAdminAPI) StopRPC ¶
func (api *PrivateAdminAPI) StopRPC() (bool, error)
StopRPC terminates an already running HTTP RPC API endpoint.
func (*PrivateAdminAPI) StopWS ¶
func (api *PrivateAdminAPI) StopWS() (bool, error)
StopWS terminates an already running websocket RPC API endpoint.
type PublicAdminAPI ¶
type PublicAdminAPI struct {
// contains filtered or unexported fields
}
PublicAdminAPI is the collection of administrative API methods exposed over both secure and unsecure RPC channels.
func NewPublicAdminAPI ¶
func NewPublicAdminAPI(node *Node) *PublicAdminAPI
NewPublicAdminAPI creates a new API definition for the public admin methods of the node itself.
func (*PublicAdminAPI) Datadir ¶
func (api *PublicAdminAPI) Datadir() string
Datadir retrieves the current data directory the node is using.
type PublicWeb3API ¶
type PublicWeb3API struct {
// contains filtered or unexported fields
}
PublicWeb3API offers helper utils
func NewPublicWeb3API ¶
func NewPublicWeb3API(stack *Node) *PublicWeb3API
NewPublicWeb3API creates a new Web3Service instance
func (*PublicWeb3API) ClientVersion ¶
func (s *PublicWeb3API) ClientVersion() string
ClientVersion returns the node name
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. // 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.
Notes:
• Service life-cycle management is delegated to the node. The service is allowed to initialize itself upon creation, but no goroutines should be spun up outside of the Start method.
• Restart logic is not required as the node will create a fresh instance every time a service is started.
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 { EventMux *event.TypeMux // Event multiplexer used for decoupled notifications // 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 ¶
func (ctx *ServiceContext) OpenDatabase(name string, cache int, handles int) (database.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.