Documentation ¶
Overview ¶
Package node defines simple data structures to represent p2p node identities.
Index ¶
Constants ¶
const DiscoveryPortParam = "disc"
DiscoveryPortParam is the param used to define the port used for discovery.
const Scheme = "spacemesh"
Scheme sets the URI scheme for the node string format.
Variables ¶
var ErrFailedToCreate = errors.New("failed to create local test node")
ErrFailedToCreate is returned when we fail to create a node
Functions ¶
func GenerateTestNode ¶
GenerateTestNode generates a local test node without persisting data to local store and with default config value.
func GenerateTestNodeWithConfig ¶
GenerateTestNodeWithConfig creates a local test node without persisting data to local store.
func GetUnboundedPort ¶
GetUnboundedPort returns a port that is for sure unbounded or an error.
Types ¶
type ID ¶
type ID [32]byte
ID is the public key represented as a fixed size 32 byte array.
type Info ¶ added in v0.1.11
Info represents a p2p node that we know about.
func GenerateRandomNodeData ¶
func GenerateRandomNodeData() *Info
GenerateRandomNodeData generates a remote random node data for testing.
func GenerateRandomNodesData ¶
GenerateRandomNodesData generates remote nodes data for testing.
func ParseNode ¶
ParseNode parses a node designator.
There are two basic forms of node designators
- incomplete nodes, which only have the public key (node ID)
- complete nodes, which contain the public key and IP/Port information
For incomplete nodes, the designator must look like one of these
spacemesh://<base58 node id> <hex node id>
For complete nodes, the node ID is encoded in the username portion of the URL, separated from the host by an @ sign. The hostname can only be given as an IP address, DNS domain names are not allowed. The port in the host name section is the TCP listening port. If the TCP and UDP (discovery) ports differ, the UDP port is specified as query parameter "disc".
In the following example, the node URL describes a node with IP address 10.3.58.6, TCP listening port 7513 and UDP discovery port 7513.
spacemesh://<base58 node id>@10.3.58.6:7513?disc=7513
type LocalNode ¶
type LocalNode struct {
// contains filtered or unexported fields
}
LocalNode is a public-private key pair used locally.
func LoadIdentity ¶
LoadIdentity loads a specific nodeid from the disk at the given path
func NewNodeIdentity ¶
NewNodeIdentity creates a new local node without attempting to restore node from local store.
func ReadFirstNodeData ¶
ReadFirstNodeData reads node data from the data folder. Reads a random node from the data folder if more than one node data file is persisted. To load a specific node on startup - users need to pass the node id using a cli arg.
func (*LocalNode) PersistData ¶
PersistData save node's data to local disk in `path`.
func (LocalNode) PrivateKey ¶
func (n LocalNode) PrivateKey() p2pcrypto.PrivateKey
PrivateKey returns this node's private key.