node

package
v0.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DiscoveryPortParam = "disc"
View Source
const SCHEME = "spacemesh"

Variables

View Source
var ErrFailedToCreate = errors.New("failed to create local test node")

ErrFailedToCreate is returned when we fail to create a node

Functions

func GenerateTestNode

func GenerateTestNode(t *testing.T) (LocalNode, *NodeInfo)

GenerateTestNode generates a local test node without persisting data to local store and with default config value.

func GenerateTestNodeWithConfig

func GenerateTestNodeWithConfig(t *testing.T) (LocalNode, *NodeInfo)

GenerateTestNodeWithConfig creates a local test node without persisting data to local store.

func GetUnboundedPort

func GetUnboundedPort() (int, error)

GetUnboundedPort returns a port that is for sure unbounded or an error.

Types

type ID

type ID [32]byte

func (ID) Bytes

func (d ID) Bytes() []byte

func (ID) PublicKey

func (d ID) PublicKey() p2pcrypto.PublicKey

func (ID) String

func (d ID) String() string

type LocalNode

type LocalNode struct {
	// contains filtered or unexported fields
}

LocalNode implementation.

func LoadIdentity

func LoadIdentity(path, nodeid string) (LocalNode, error)

func NewNodeIdentity

func NewNodeIdentity() (LocalNode, error)

NewNodeIdentity creates a new local node without attempting to restore node from local store.

func ReadFirstNodeData

func ReadFirstNodeData(path string) (LocalNode, error)

Read 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

func (n *LocalNode) PersistData(path string) error

Persist node's data to local store.

func (LocalNode) PrivateKey

func (n LocalNode) PrivateKey() p2pcrypto.PrivateKey

PrivateKey returns this node's private key.

func (LocalNode) PublicKey

func (n LocalNode) PublicKey() p2pcrypto.PublicKey

type NodeInfo

type NodeInfo struct {
	ID
	IP            net.IP
	ProtocolPort  uint16 // TCP
	DiscoveryPort uint16 // UDP
}

NodeInfo is a discovery parsed structure to store a node's address and key.

func GenerateRandomNodeData

func GenerateRandomNodeData() *NodeInfo

GenerateRandomNodeData generates a remote random node data for testing.

func GenerateRandomNodesData

func GenerateRandomNodesData(n int) []*NodeInfo

GenerateRandomNodesData generates remote nodes data for testing.

func NewNode

func NewNode(id p2pcrypto.PublicKey, ip net.IP, proto, disc uint16) *NodeInfo

NewNode creates a new node. It is mostly meant to be used for testing purposes.

func ParseNode

func ParseNode(rawurl string) (*NodeInfo, error)

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

func (NodeInfo) String

func (n NodeInfo) String() string

The string representation of a Node is a URL. Please see ParseNode for a description of the format.

func (NodeInfo) Valid

func (n NodeInfo) Valid() error

checks whether n is a valid complete node.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL