{"modulePath":"github.com/MatrixAINetwork/MATRIX-TESTNET","version":"v1.1.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package pod\n\nPackage node sets up multi-protocol Matrix nodes.\n\nIn the model exposed by this package, a node is a collection of services which use shared resources to provide RPC APIs. Services can also offer devp2p protocols, which are wired up to the devp2p network when the node instance is started.\n\n### Resources Managed By Node {#hdr-Resources_Managed_By_Node}\n\nAll file-system resources used by a node instance are located in a directory called the data directory. The location of each resource can be overridden through additional node configuration. The data directory is optional. If it is not set and the location of a resource is otherwise unspecified, package node will create the resource in memory.\n\nTo access to the devp2p network, Node configures and starts p2p.Server. Each host on the devp2p network has a unique identifier, the node key. The Node instance persists this key across restarts. Node also loads static and trusted node lists and ensures that knowledge about other hosts is persisted.\n\nJSON-RPC servers which run HTTP, WebSocket or IPC can be started on a Node. RPC modules offered by registered services will be offered on those endpoints. Users can restrict any endpoint to a subset of RPC modules. Node itself offers the \"debug\", \"admin\" and \"web3\" modules.\n\nService implementations can open LevelDB databases through the service context. Package node chooses the file system location of each database. If the node is configured to run without a data directory, databases are opened in memory instead.\n\nNode also creates the shared store of encrypted Matrix account keys. Services can access the account manager through the service context.\n\n### Sharing Data Directory Among Instances {#hdr-Sharing_Data_Directory_Among_Instances}\n\nMultiple node instances can share a single data directory if they have distinct instance names (set through the Name config option). Sharing behaviour depends on the type of resource.\n\ndevp2p-related resources (node key, static/trusted node lists, known hosts database) are stored in a directory with the same name as the instance. Thus, multiple node instances using the same data directory will store this information in different subdirectories of the data directory.\n\nLevelDB databases are also stored within the instance subdirectory. If multiple node instances use the same data directory, opening the databases with identical names will create one database for each instance.\n\nThe account key store is shared among all node instances using the same data directory unless its location is changed through the KeyStoreDir configuration option.\n\n### Data Directory Sharing Example {#hdr-Data_Directory_Sharing_Example}\n\nIn this example, two node instances named A and B are started with the same data directory. Mode instance A opens the database \"db\", node instance B opens the databases \"db\" and \"db-2\". The following files will be created in the data directory:\n\n\tdata-directory/\n\t     A/\n\t         nodekey            -- devp2p node key of instance A\n\t         nodes/             -- devp2p discovery knowledge database of instance A\n\t         db/                -- LevelDB content for \"db\"\n\t     A.ipc                  -- JSON-RPC UNIX domain socket endpoint of instance A\n\t     B/\n\t         nodekey            -- devp2p node key of node B\n\t         nodes/             -- devp2p discovery knowledge database of instance B\n\t         static-nodes.json  -- devp2p static node list of instance B\n\t         db/                -- LevelDB content for \"db\"\n\t         db-2/              -- LevelDB content for \"db-2\"\n\t     B.ipc                  -- JSON-RPC UNIX domain socket endpoint of instance B\n\t     keystore/              -- account key store, used by both instances\n\n## Constants\n\n```go\nconst (\n\tDefaultHTTPHost = \"localhost\" // Default host interface for the HTTP RPC server\n\tDefaultHTTPPort = 8341        // Default TCP port for the HTTP RPC server\n\tDefaultWSHost   = \"localhost\" // Default host interface for the websocket RPC server\n\tDefaultWSPort   = 8546        // Default TCP port for the websocket RPC server\n)\n```\n\n## Variables\n\n```go\nvar (\n\tErrDatadirUsed    = errors.New(\"datadir already used by another process\")\n\tErrNodeStopped    = errors.New(\"node not started\")\n\tErrNodeRunning    = errors.New(\"node already running\")\n\tErrServiceUnknown = errors.New(\"unknown service\")\n)\n```\n\n```go\nvar DefaultConfig = Config{\n\tDataDir:          DefaultDataDir(),\n\tHTTPPort:         DefaultHTTPPort,\n\tHTTPModules:      []string{\"net\", \"web3\"},\n\tHTTPVirtualHosts: []string{\"localhost\"},\n\tWSPort:           DefaultWSPort,\n\tWSModules:        []string{\"net\", \"web3\"},\n\tP2P: p2p.Config{\n\t\tListenAddr: \":50505\",\n\t\tMaxPeers:   10000,\n\t\tNAT:        nat.Any(),\n\t},\n}\n```\nDefaultConfig contains reasonable default settings.\n\n## Functions\n\n```go\nfunc DefaultDataDir() string\n```\nDefaultDataDir is the default data directory to use for the databases and other persistence requirements.\n\n```go\nfunc DefaultHTTPEndpoint() string\n```\nDefaultHTTPEndpoint returns the HTTP endpoint used by default.\n\n```go\nfunc DefaultIPCEndpoint(clientIdentifier string) string\n```\nDefaultIPCEndpoint returns the IPC path used by default.\n\n```go\nfunc DefaultWSEndpoint() string\n```\nDefaultWSEndpoint returns the websocket endpoint used by default.\n\n## Types\n\n```go\ntype Config struct {\n\t// Name sets the instance name of the node. It must not contain the / character and is\n\t// used in the devp2p node identifier. The instance name of gman is \"gman\". If no\n\t// value is specified, the basename of the current executable is used.\n\tName string `toml:\"-\"`\n\n\t// UserIdent, if set, is used as an additional component in the devp2p node identifier.\n\tUserIdent string `toml:\",omitempty\"`\n\n\t// Version should be set to the version number of the program. It is used\n\t// in the devp2p node identifier.\n\tVersion string `toml:\"-\"`\n\n\t// DataDir is the file system folder the node should use for any data storage\n\t// requirements. The configured data directory will not be directly shared with\n\t// registered services, instead those can use utility methods to create/access\n\t// databases or flat files. This enables ephemeral nodes which can fully reside\n\t// in memory.\n\tDataDir string\n\n\t// Configuration of peer-to-peer networking.\n\tP2P p2p.Config\n\n\t// KeyStoreDir is the file system folder that contains private keys. The directory can\n\t// be specified as a relative path, in which case it is resolved relative to the\n\t// current directory.\n\t//\n\t// If KeyStoreDir is empty, the default location is the \"keystore\" subdirectory of\n\t// DataDir. If DataDir is unspecified and KeyStoreDir is empty, an ephemeral directory\n\t// is created by New and destroyed when the node is stopped.\n\tKeyStoreDir string `toml:\",omitempty\"`\n\n\t// UseLightweightKDF lowers the memory and CPU requirements of the key store\n\t// scrypt KDF at the expense of security.\n\tUseLightweightKDF bool `toml:\",omitempty\"`\n\n\t// NoUSB disables hardware wallet monitoring and connectivity.\n\tNoUSB bool `toml:\",omitempty\"`\n\n\t// IPCPath is the requested location to place the IPC endpoint. If the path is\n\t// a simple file name, it is placed inside the data directory (or on the root\n\t// pipe path on Windows), whereas if it's a resolvable path name (absolute or\n\t// relative), then that specific path is enforced. An empty path disables IPC.\n\tIPCPath string `toml:\",omitempty\"`\n\n\t// HTTPHost is the host interface on which to start the HTTP RPC server. If this\n\t// field is empty, no HTTP API endpoint will be started.\n\tHTTPHost string `toml:\",omitempty\"`\n\n\t// HTTPPort is the TCP port number on which to start the HTTP RPC server. The\n\t// default zero value is/ valid and will pick a port number randomly (useful\n\t// for ephemeral nodes).\n\tHTTPPort int `toml:\",omitempty\"`\n\n\t// HTTPCors is the Cross-Origin Resource Sharing header to send to requesting\n\t// clients. Please be aware that CORS is a browser enforced security, it's fully\n\t// useless for custom HTTP clients.\n\tHTTPCors []string `toml:\",omitempty\"`\n\n\t// HTTPVirtualHosts is the list of virtual hostnames which are allowed on incoming requests.\n\t// This is by default {'localhost'}. Using this prevents attacks like\n\t// DNS rebinding, which bypasses SOP by simply masquerading as being within the same\n\t// origin. These attacks do not utilize CORS, since they are not cross-domain.\n\t// By explicitly checking the Host-header, the server will not allow requests\n\t// made against the server with a malicious host domain.\n\t// Requests using ip address directly are not affected\n\tHTTPVirtualHosts []string `toml:\",omitempty\"`\n\n\t// HTTPModules is a list of API modules to expose via the HTTP RPC interface.\n\t// If the module list is empty, all RPC API endpoints designated public will be\n\t// exposed.\n\tHTTPModules []string `toml:\",omitempty\"`\n\n\t// WSHost is the host interface on which to start the websocket RPC server. If\n\t// this field is empty, no websocket API endpoint will be started.\n\tWSHost string `toml:\",omitempty\"`\n\n\t// WSPort is the TCP port number on which to start the websocket RPC server. The\n\t// default zero value is/ valid and will pick a port number randomly (useful for\n\t// ephemeral nodes).\n\tWSPort int `toml:\",omitempty\"`\n\n\t// WSOrigins is the list of domain to accept websocket requests from. Please be\n\t// aware that the server can only act upon the HTTP request the client sends and\n\t// cannot verify the validity of the request header.\n\tWSOrigins []string `toml:\",omitempty\"`\n\n\t// WSModules is a list of API modules to expose via the websocket RPC interface.\n\t// If the module list is empty, all RPC API endpoints designated public will be\n\t// exposed.\n\tWSModules []string `toml:\",omitempty\"`\n\n\t// WSExposeAll exposes all API modules via the WebSocket RPC interface rather\n\t// than just the public ones.\n\t//\n\t// *WARNING* Only set this if the node is running in a trusted network, exposing\n\t// private APIs to untrusted users is a major security risk.\n\tWSExposeAll bool `toml:\",omitempty\"`\n\n\t// Logger is a custom logger to use with the p2p.Server.\n\tLogger log.Logger `toml:\",omitempty\"`\n\n\tLessDisk bool `toml:\",omitempty\"`\n}\n```\nConfig 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.\n\n```go\nfunc (c *Config) AccountConfig() (int, int, string, error)\n```\nAccountConfig determines the settings for scrypt and keydirectory\n\n```go\nfunc (c *Config) HTTPEndpoint() string\n```\nHTTPEndpoint resolves an HTTP endpoint based on the configured host interface and port parameters.\n\n```go\nfunc (c *Config) IPCEndpoint() string\n```\nIPCEndpoint 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.\n\n```go\nfunc (c *Config) NodeDB() string\n```\nNodeDB returns the path to the discovery node database.\n\n```go\nfunc (c *Config) NodeKey() *ecdsa.PrivateKey\n```\nNodeKey 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.\n\n```go\nfunc (c *Config) NodeName() string\n```\nNodeName returns the devp2p node identifier.\n\n```go\nfunc (c *Config) StaticNodes() []*discover.Node\n```\nStaticNodes returns a list of node enode URLs configured as static nodes.\n\n```go\nfunc (c *Config) TrustedNodes() []*discover.Node\n```\nTrustedNodes returns a list of node enode URLs configured as trusted nodes.\n\n```go\nfunc (c *Config) WSEndpoint() string\n```\nWSEndpoint resolves a websocket endpoint based on the configured host interface and port parameters.\n\n```go\ntype DuplicateServiceError struct {\n\tKind reflect.Type\n}\n```\nDuplicateServiceError is returned during Node startup if a registered service constructor returns a service of the same type that was already started.\n\n```go\nfunc (e *DuplicateServiceError) Error() string\n```\nError generates a textual representation of the duplicate service error.\n\n```go\ntype Node struct {\n\tMsgCenter *mc.Center\n\t// contains filtered or unexported fields\n}\n```\nNode is a container on which services can be registered.\n\n```go\nfunc New(conf *Config) (*Node, error)\n```\nNew creates a new P2P node, ready for protocol registration.\n\n```go\nfunc (n *Node) AccountManager() *accounts.Manager\n```\nAccountManager retrieves the account manager used by the protocol stack.\n\n```go\nfunc (n *Node) Attach() (*rpc.Client, error)\n```\nAttach creates an RPC client attached to an in-process API handler.\n\n```go\nfunc (n *Node) DataDir() string\n```\nDataDir retrieves the current datadir used by the protocol stack. Deprecated: No files should be stored in this directory, use InstanceDir instead.\n\n```go\nfunc (n *Node) EventMux() *event.TypeMux\n```\nEventMux retrieves the event multiplexer used by all the network services in the current protocol stack.\n\n```go\nfunc (n *Node) HTTPEndpoint() string\n```\nHTTPEndpoint retrieves the current HTTP endpoint used by the protocol stack.\n\n```go\nfunc (n *Node) IPCEndpoint() string\n```\nIPCEndpoint retrieves the current IPC endpoint used by the protocol stack.\n\n```go\nfunc (n *Node) InstanceDir() string\n```\nInstanceDir retrieves the instance directory used by the protocol stack.\n\n```go\nfunc (n *Node) OpenDatabase(name string, cache, handles int) (mandb.Database, error)\n```\nOpenDatabase 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.\n\n```go\nfunc (n *Node) RPCHandler() (*rpc.Server, error)\n```\nRPCHandler returns the in-process RPC request handler.\n\n```go\nfunc (n *Node) Register(constructor ServiceConstructor) error\n```\nRegister 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.\n\n```go\nfunc (n *Node) ResolvePath(x string) string\n```\nResolvePath returns the absolute path of a resource in the instance directory.\n\n```go\nfunc (n *Node) Restart() error\n```\nRestart terminates a running node and boots up a new one in its place. If the node isn't running, an error is returned.\n\n```go\nfunc (n *Node) Server() *p2p.Server\n```\nServer 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.\n\n```go\nfunc (n *Node) Service(service interface{}) error\n```\nService retrieves a currently running service registered of a specific type.\n\n```go\nfunc (n *Node) SignalHelper() *signhelper.SignHelper\n```\n\n```go\nfunc (n *Node) Signature() (signature common.Signature, manAddr common.Address, signTime time.Time)\n```\n\n```go\nfunc (n *Node) Start() error\n```\nStart create a live P2P node and starts running it.\n\n```go\nfunc (n *Node) Stop() error\n```\nStop terminates a running node along with all it's services. In the node was not started, an error is returned.\n\n```go\nfunc (n *Node) WSEndpoint() string\n```\nWSEndpoint retrieves the current WS endpoint used by the protocol stack.\n\n```go\nfunc (n *Node) Wait()\n```\nWait blocks the thread until the node is stopped. If the node is not running at the time of invocation, the method immediately returns.\n\n```go\ntype PrivateAdminAPI struct {\n\t// contains filtered or unexported fields\n}\n```\nPrivateAdminAPI is the collection of administrative API methods exposed only over a secure RPC channel.\n\n```go\nfunc NewPrivateAdminAPI(node *Node) *PrivateAdminAPI\n```\nNewPrivateAdminAPI creates a new API definition for the private admin methods of the node itself.\n\n```go\nfunc (api *PrivateAdminAPI) AddPeer(url string) (bool, error)\n```\nAddPeer requests connecting to a remote node, and also maintaining the new connection at all times, even reconnecting if it is lost.\n\n```go\nfunc (api *PrivateAdminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription, error)\n```\nPeerEvents creates an RPC subscription which receives peer events from the node's p2p.Server\n\n```go\nfunc (api *PrivateAdminAPI) RemovePeer(url string) (bool, error)\n```\nRemovePeer disconnects from a a remote node if the connection exists\n\n```go\nfunc (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error)\n```\nStartRPC starts the HTTP RPC API server.\n\n```go\nfunc (api *PrivateAdminAPI) StartWS(host *string, port *int, allowedOrigins *string, apis *string) (bool, error)\n```\nStartWS starts the websocket RPC API server.\n\n```go\nfunc (api *PrivateAdminAPI) StopRPC() (bool, error)\n```\nStopRPC terminates an already running HTTP RPC API endpoint.\n\n```go\nfunc (api *PrivateAdminAPI) StopWS() (bool, error)\n```\nStopWS terminates an already running websocket RPC API endpoint.\n\n```go\ntype PublicAdminAPI struct {\n\t// contains filtered or unexported fields\n}\n```\nPublicAdminAPI is the collection of administrative API methods exposed over both secure and unsecure RPC channels.\n\n```go\nfunc NewPublicAdminAPI(node *Node) *PublicAdminAPI\n```\nNewPublicAdminAPI creates a new API definition for the public admin methods of the node itself.\n\n```go\nfunc (api *PublicAdminAPI) AddressTable() (map[common.Address]*discover.Node, error)\n```\n\n```go\nfunc (api *PublicAdminAPI) Datadir() string\n```\nDatadir retrieves the current data directory the node is using.\n\n```go\nfunc (api *PublicAdminAPI) NodeInfo() (*p2p.NodeInfo, error)\n```\nNodeInfo retrieves all the information we know about the host node at the protocol granularity.\n\n```go\nfunc (api *PublicAdminAPI) Peers() ([]*p2p.PeerInfo, error)\n```\nPeers retrieves all the information we know about each individual peer at the protocol granularity.\n\n```go\ntype PublicDebugAPI struct {\n\t// contains filtered or unexported fields\n}\n```\nPublicDebugAPI is the collection of debugging related API methods exposed over both secure and unsecure RPC channels.\n\n```go\nfunc NewPublicDebugAPI(node *Node) *PublicDebugAPI\n```\nNewPublicDebugAPI creates a new API definition for the public debug methods of the node itself.\n\n```go\nfunc (api *PublicDebugAPI) Metrics(raw bool) (map[string]interface{}, error)\n```\nMetrics retrieves all the known system metric collected by the node.\n\n```go\ntype PublicWeb3API struct {\n\t// contains filtered or unexported fields\n}\n```\nPublicWeb3API offers helper utils\n\n```go\nfunc NewPublicWeb3API(stack *Node) *PublicWeb3API\n```\nNewPublicWeb3API creates a new Web3Service instance\n\n```go\nfunc (s *PublicWeb3API) ClientVersion() string\n```\nClientVersion returns the node name\n\n```go\nfunc (s *PublicWeb3API) Sha3(input hexutil.Bytes) hexutil.Bytes\n```\nSha3 applies the matrix sha3 implementation on the input. It assumes the input is hex encoded.\n\n```go\ntype Service interface {\n\t// Protocols retrieves the P2P protocols the service wishes to start.\n\tProtocols() []p2p.Protocol\n\n\t// APIs retrieves the list of RPC descriptors the service provides\n\tAPIs() []rpc.API\n\n\t// Start is called after all services have been constructed and the networking\n\t// layer was also initialized to spawn any goroutines required by the service.\n\tStart(server *p2p.Server) error\n\n\t// Stop terminates all goroutines belonging to the service, blocking until they\n\t// are all terminated.\n\tStop() error\n}\n```\nService is an individual protocol that can be registered into a node.\n\nNotes:\n\n• 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.\n\n• Restart logic is not required as the node will create a fresh instance every time a service is started.\n\n```go\ntype ServiceConstructor func(ctx *ServiceContext) (Service, error)\n```\nServiceConstructor is the function signature of the constructors needed to be registered for service instantiation.\n\n```go\ntype ServiceContext struct {\n\tEventMux       *event.TypeMux    // Event multiplexer used for decoupled notifications\n\tAccountManager *accounts.Manager // Account manager created by the node.\n\tCa             *ca.Identity\n\tMsgCenter      *mc.Center\n\tHD             *msgsend.HD\n\tSignHelper     *signhelper.SignHelper\n\t// contains filtered or unexported fields\n}\n```\nServiceContext 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.\n\n```go\nfunc (ctx *ServiceContext) GetConfig() *Config\n```\n\n```go\nfunc (ctx *ServiceContext) OpenDatabase(name string, cache int, handles int, dbsize int) (mandb.Database, error)\n```\nOpenDatabase 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.\n\n```go\nfunc (ctx *ServiceContext) ResolvePath(path string) string\n```\nResolvePath 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.\n\n```go\nfunc (ctx *ServiceContext) Service(service interface{}) error\n```\nService retrieves a currently running service registered of a specific type.\n\n```go\ntype SignatureFile struct {\n\tSignature common.Signature `json:\"signature\"`\n\tTime      time.Time        `json:\"time\"`\n}\n```\n\n```go\ntype StopError struct {\n\tServer   error\n\tServices map[reflect.Type]error\n}\n```\nStopError is returned if a Node fails to stop either any of its registered services or itself.\n\n```go\nfunc (e *StopError) Error() string\n```\nError generates a textual representation of the stop error.\n\n","path":"github.com/MatrixAINetwork/MATRIX-TESTNET/pod","name":"pod","synopsis":"Package node sets up multi-protocol Matrix nodes.","isRedistributable":true}
