Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultDataDir() string
- func NewHTTPHandlerStack(srv http.Handler, cors []string, vhosts []string, jwtSecret []byte) http.Handler
- func NewWSHandlerStack(srv http.Handler, jwtSecret []byte) http.Handler
- type Config
- func (c *Config) ExtRPCEnabled() bool
- func (c *Config) GetKeyStoreDir() (string, bool, error)
- func (c *Config) HTTPEndpoint() string
- func (c *Config) IPCEndpoint() string
- func (c *Config) KeyDirConfig() (string, error)
- func (c *Config) ResolvePath(path string) string
- func (c *Config) WSEndpoint() string
- type Node
- func (n *Node) AccountManager() *accounts.Manager
- func (n *Node) Attach() *rpc.Client
- func (n *Node) Close() error
- func (n *Node) Config() *Config
- func (n *Node) DataDir() string
- func (n *Node) EventMux() *event.TypeMux
- func (n *Node) HTTPAuthEndpoint() string
- func (n *Node) HTTPEndpoint() string
- func (n *Node) IPCEndpoint() string
- func (n *Node) InstanceDir() string
- func (n *Node) KeyStoreDir() string
- func (n *Node) OpenDatabase(name string, cache, handles int, namespace string, readonly bool) (ethdb.Database, error)
- func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, ancient string, namespace string, ...) (ethdb.Database, error)
- func (n *Node) RPCHandler() (*rpc.Server, error)
- func (n *Node) RegisterAPIs(apis []rpc.API)
- func (n *Node) RegisterHandler(name, path string, handler http.Handler)
- func (n *Node) RegisterLifecycle(lifecycle node.Lifecycle)
- func (n *Node) ResolveAncient(name string, ancient string) string
- func (n *Node) ResolvePath(x string) string
- func (n *Node) Start() error
- func (n *Node) WSAuthEndpoint() string
- func (n *Node) WSEndpoint() string
- func (n *Node) Wait()
Constants ¶
const ( DefaultHTTPHost = "localhost" // Default host interface for the HTTP RPC server DefaultHTTPPort = 8645 // Default TCP port for the HTTP RPC server DefaultWSHost = "localhost" // Default host interface for the websocket RPC server DefaultWSPort = 8646 // Default TCP port for the websocket RPC server DefaultAuthHost = "localhost" // Default host interface for the authenticated apis DefaultAuthPort = 8651 // Default port for the authenticated apis )
Variables ¶
var ( DefaultAuthCors = []string{"localhost"} // Default cors domain for the authenticated apis DefaultAuthVhosts = []string{"localhost"} // Default virtual hosts for the authenticated apis DefaultAuthOrigins = []string{"localhost"} // Default origins for the authenticated apis DefaultAuthPrefix = "" // Default prefix for the authenticated apis DefaultAuthModules = []string{"eth", "engine"} )
var DefaultConfig = Config{ DataDir: DefaultDataDir(), HTTPPort: DefaultHTTPPort, AuthAddr: DefaultAuthHost, AuthPort: DefaultAuthPort, AuthVirtualHosts: DefaultAuthVhosts, HTTPModules: []string{"net", "web3"}, HTTPVirtualHosts: []string{"localhost"}, HTTPTimeouts: rpc.DefaultHTTPTimeouts, WSPort: DefaultWSPort, WSModules: []string{"net", "web3"}, BatchRequestLimit: 1000, BatchResponseMaxSize: 25 * 1000 * 1000, GraphQLVirtualHosts: []string{"localhost"}, DBEngine: "", }
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.
Types ¶
type Config ¶
type Config struct { // Name sets the instance name of the node. It must not contain the / character. // The instance name of mive is "mive". If no value is specified, the basename // of the current executable is used. Name string `toml:"-"` // Version should be set to the version number of the program. 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 // 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"` // ExternalSigner specifies an external URI for a clef-type signer. ExternalSigner 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"` // InsecureUnlockAllowed allows user to unlock accounts in unsafe http environment. InsecureUnlockAllowed bool `toml:",omitempty"` // USB enables hardware wallet monitoring and connectivity. USB 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 // HTTPHost is the host interface on which to start the HTTP RPC server. If this // field is empty, no HTTP API endpoint will be started. HTTPHost string // HTTPPort is the TCP port number on which to start the HTTP RPC server. The // default zero value is/ valid and will pick a port number randomly (useful // for ephemeral nodes). HTTPPort int `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 // HTTPTimeouts allows for customization of the timeout values used by the HTTP RPC // interface. HTTPTimeouts rpc.HTTPTimeouts // HTTPPathPrefix specifies a path prefix on which http-rpc is to be served. HTTPPathPrefix string `toml:",omitempty"` // AuthAddr is the listening address on which authenticated APIs are provided. AuthAddr string `toml:",omitempty"` // AuthPort is the port number on which authenticated APIs are provided. AuthPort int `toml:",omitempty"` // AuthVirtualHosts is the list of virtual hostnames which are allowed on incoming requests // for the authenticated api. This is by default {'localhost'}. AuthVirtualHosts []string `toml:",omitempty"` // WSHost is the host interface on which to start the websocket RPC server. If // this field is empty, no websocket API endpoint will be started. WSHost string // WSPort is the TCP port number on which to start the websocket RPC server. The // default zero value is/ valid and will pick a port number randomly (useful for // ephemeral nodes). WSPort int `toml:",omitempty"` // WSPathPrefix specifies a path prefix on which ws-rpc is to be served. WSPathPrefix 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 // 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"` // GraphQLCors 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. GraphQLCors []string `toml:",omitempty"` // GraphQLVirtualHosts 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 GraphQLVirtualHosts []string `toml:",omitempty"` // AllowUnprotectedTxs allows non EIP-155 protected transactions to be send over RPC. AllowUnprotectedTxs bool `toml:",omitempty"` // Logger is a custom logger to use with the Node. Logger log.Logger `toml:",omitempty"` // BatchRequestLimit is the maximum number of requests in a batch. BatchRequestLimit int `toml:",omitempty"` // BatchResponseMaxSize is the maximum number of bytes returned from a batched rpc call. BatchResponseMaxSize int `toml:",omitempty"` // JWTSecret is the path to the hex-encoded jwt secret. JWTSecret string `toml:",omitempty"` DBEngine string `toml:",omitempty"` }
Config represents a small collection of configuration values. These values can be further extended by all registered services.
func (*Config) ExtRPCEnabled ¶
ExtRPCEnabled returns the indicator whether node enables the external RPC(http, ws or graphql).
func (*Config) GetKeyStoreDir ¶
GetKeyStoreDir retrieves the key directory and will create and ephemeral one if necessary.
func (*Config) HTTPEndpoint ¶
HTTPEndpoint resolves an HTTP endpoint based on the configured host interface and port parameters.
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) KeyDirConfig ¶
KeyDirConfig determines the settings for keydirectory
func (*Config) ResolvePath ¶
ResolvePath resolves path in the instance directory.
func (*Config) WSEndpoint ¶
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 (*Node) AccountManager ¶
AccountManager retrieves the account manager used by the protocol stack.
func (*Node) EventMux ¶
EventMux retrieves the event multiplexer used by all the network services in the current protocol stack.
func (*Node) HTTPAuthEndpoint ¶
HTTPAuthEndpoint returns the URL of the authenticated HTTP server.
func (*Node) HTTPEndpoint ¶
HTTPEndpoint returns the URL of the HTTP server. Note that this URL does not contain the JSON-RPC path prefix set by HTTPPathPrefix.
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) KeyStoreDir ¶
KeyStoreDir retrieves the key directory
func (*Node) OpenDatabase ¶
func (n *Node) OpenDatabase(name string, cache, handles int, namespace string, readonly bool) (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 instance directory. If the node is ephemeral, a memory database is returned.
func (*Node) OpenDatabaseWithFreezer ¶
func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, ancient string, namespace string, readonly bool) (ethdb.Database, error)
OpenDatabaseWithFreezer opens an existing database with the given name (or creates one if no previous can be found) from within the node's data directory, also attaching a chain freezer to it that moves ancient chain data from the database to immutable append-only files. If the node is an ephemeral one, a memory database is returned.
func (*Node) RPCHandler ¶
RPCHandler returns the in-process RPC request handler.
func (*Node) RegisterAPIs ¶
RegisterAPIs registers the APIs a service provides on the node.
func (*Node) RegisterHandler ¶
RegisterHandler mounts a handler on the given path on the canonical HTTP server.
The name of the handler is shown in a log message when the HTTP server starts and should be a descriptive term for the service provided by the handler.
func (*Node) RegisterLifecycle ¶
RegisterLifecycle registers the given Lifecycle on the node.
func (*Node) ResolveAncient ¶
ResolveAncient returns the absolute path of the root ancient directory.
func (*Node) ResolvePath ¶
ResolvePath returns the absolute path of a resource in the instance directory.
func (*Node) Start ¶
Start starts all registered lifecycles, RPC services and p2p networking. Node can only be started once.
func (*Node) WSAuthEndpoint ¶
WSAuthEndpoint returns the current authenticated JSON-RPC over WebSocket endpoint.
func (*Node) WSEndpoint ¶
WSEndpoint returns the current JSON-RPC over WebSocket endpoint.