Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertFileLockError(err error) error
- func DefaultDataDir() string
- func DefaultHTTPEndpoint() string
- func DefaultWSEndpoint() string
- type Config
- func (c *Config) HTTPEndpoint() string
- func (c *Config) IPCEndpoint() string
- func (c *Config) LoadKey(filename string) (*ecdsa.PrivateKey, error)
- func (c *Config) NodeDB() string
- func (c *Config) NodeKey() *ecdsa.PrivateKey
- func (c *Config) NodeName() string
- func (c *Config) ResolvePath(path string) string
- func (c *Config) RevokeKeyPath() error
- func (c *Config) SaveKey(filename string, key *ecdsa.PrivateKey) error
- func (c *Config) StaticNodes() []*discover.Node
- func (c *Config) TrustedNodes() []*discover.Node
- func (c *Config) WSEndpoint() string
- type DuplicateServiceError
- type Node
- func (n *Node) DataDir() string
- func (n *Node) RPCHandler() (*rpc.Server, error)
- func (n *Node) Register(constructor pkgservice.ServiceConstructor) error
- func (n *Node) Restart(isRevoke bool, isRestart bool) error
- func (n *Node) Server() *p2p.Server
- func (n *Node) Services() map[reflect.Type]pkgservice.PttService
- func (n *Node) Start() error
- func (n *Node) Stop(isRevoke bool, isRestart bool) error
- type PrivateAdminAPI
- func (api *PrivateAdminAPI) AddPeer(url string) (bool, error)
- func (api *PrivateAdminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription, error)
- func (api *PrivateAdminAPI) RemovePeer(url string) (bool, error)
- func (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error)
- func (api *PrivateAdminAPI) StartWS(host *string, port *int, allowedOrigins *string, apis *string) (bool, error)
- func (api *PrivateAdminAPI) StopRPC() (bool, error)
- func (api *PrivateAdminAPI) StopWS() (bool, error)
- type PublicAdminAPI
- type PublicDebugAPI
- type StopError
Constants ¶
const ( Mainnet uint32 Testnet Devnet )
const ( DataDirPrivateKey = "nodekey" // Path within the datadir to the node's private key DataDirDefaultKeyStore = "keystore" // Path within the datadir to the keystore DataDirStaticNodes = "static-nodes.json" // Path within the datadir to the static node list DataDirTrustedNodes = "trusted-nodes.json" // Path within the datadir to the trusted node list DataDirNodeDatabase = "nodes" // Path within the datadir to store the node infos DefaultHTTPHost = "" // Default host interface for the HTTP RPC server DefaultHTTPPort = 14779 // Default TCP port for the HTTP RPC server DefaultWSHost = "" // Default host interface for the websocket RPC server DefaultWSPort = 15779 // Default TCP port for the websocket RPC server DefaultNetworkID = Devnet )
Variables ¶
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") ErrNodeRestart = errors.New("node restart") )
var ( DefaultConfig = Config{ DataDir: DefaultDataDir(), IPCPath: "gptt.ipc", HTTPHost: DefaultHTTPHost, HTTPPort: DefaultHTTPPort, HTTPCors: []string{"localhost"}, HTTPVirtualHosts: []string{"localhost"}, HTTPModules: []string{"debug", "net", "admin", "ptt", "account", "content", "me", "friend"}, WSPort: DefaultWSPort, P2P: p2p.Config{ ListenAddr: ":29487", MaxPeers: 350, NAT: nat.Any(), P2PListenAddr: "/ip4/0.0.0.0/tcp/9487", }, NetworkID: DefaultNetworkID, } )
Functions ¶
func ConvertFileLockError ¶
func DefaultDataDir ¶
func DefaultDataDir() string
DefaultDataDir is the default data directory to use for the databases and other persistence requirements. used by cmd.utils
func DefaultHTTPEndpoint ¶
func DefaultHTTPEndpoint() string
DefaultHTTPEndpoint returns the HTTP endpoint used by default.
func DefaultWSEndpoint ¶
func DefaultWSEndpoint() string
DefaultWSEndpoint returns the websocket endpoint used by default.
Types ¶
type Config ¶
type Config struct { // Version should be set to the version number of the program. It is used // in the devp2p node identifier. Version int `toml:"-"` // 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:"-"` // UserIdent, if set, is used as an additional component in the devp2p node identifier. UserIdent string `toml:",omitempty"` DataDir string // Configuration of peer-to-peer networking. P2P p2p.Config // 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"` // 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"` // 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 `toml:",omitempty"` // 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"` ExternHTTPAddr string // 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"` // 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 `toml:",omitempty"` // 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"` // 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 log.Logger `toml:",omitempty"` NetworkID uint32 }
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) NodeKey ¶
func (c *Config) 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 (*Config) ResolvePath ¶
resolvePath resolves path in the instance directory.
func (*Config) RevokeKeyPath ¶
func (*Config) StaticNodes ¶
StaticNodes returns a list of node enode URLs configured as static nodes.
func (*Config) TrustedNodes ¶
TrustedNodes returns a list of node enode URLs configured as trusted nodes.
func (*Config) WSEndpoint ¶
WSEndpoint resolves a websocket endpoint based on the configured host interface and port parameters.
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 ¶
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) RPCHandler ¶
RPCHandler returns the in-process RPC request handler.
func (*Node) Register ¶
func (n *Node) Register(constructor pkgservice.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.
func (*Node) Server ¶
Server retrieves the currently running P2P network layer. This method is meant only to inspect fields of the currently running server, life cycle management should be left to this Node entity.
func (*Node) Services ¶
func (n *Node) Services() map[reflect.Type]pkgservice.PttService
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) AddPeer ¶
func (api *PrivateAdminAPI) AddPeer(url string) (bool, error)
AddPeer requests connecting to a remote node, and also maintaining the new connection at all times, even reconnecting if it is lost.
func (*PrivateAdminAPI) PeerEvents ¶
func (api *PrivateAdminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription, error)
PeerEvents creates an RPC subscription which receives peer events from the node's p2p.Server
func (*PrivateAdminAPI) RemovePeer ¶
func (api *PrivateAdminAPI) RemovePeer(url string) (bool, error)
RemovePeer disconnects from a a remote node if the connection exists
func (*PrivateAdminAPI) StartRPC ¶
func (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error)
StartRPC starts the HTTP RPC API server.
func (*PrivateAdminAPI) StartWS ¶
func (api *PrivateAdminAPI) StartWS(host *string, port *int, 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 PublicDebugAPI ¶
type PublicDebugAPI struct {
// contains filtered or unexported fields
}
PublicDebugAPI is the collection of debugging related API methods exposed over both secure and unsecure RPC channels.
func NewPublicDebugAPI ¶
func NewPublicDebugAPI(node *Node) *PublicDebugAPI
NewPublicDebugAPI creates a new API definition for the public debug methods of the node itself.