node

package
v0.0.0-...-bcff216 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package node defines simple data structures to represent p2p node identities.

Index

Constants

View Source
const DiscoveryPortParam = "disc"

DiscoveryPortParam is the param used to define the port used for discovery.

View Source
const Scheme = "libonomy"

Scheme sets the URI scheme for the node string format.

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, *Info)

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, *Info)

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

ID is the public key represented as a fixed size 32 byte array.

func (ID) Bytes

func (d ID) Bytes() []byte

Bytes returns the ID as byte slice.

func (ID) PublicKey

func (d ID) PublicKey() p2pcrypto.PublicKey

PublicKey returns the public key as the PublicKey interface.

func (ID) String

func (d ID) String() string

String returns a base58 string representation of the ID.

type Info

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

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

func GenerateRandomNodesData(n int) []*Info

GenerateRandomNodesData generates remote nodes data for testing.

func NewNode

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

NewNode creates a new Info from public key, ip and ports.

func ParseNode

func ParseNode(rawurl string) (*Info, 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

libonomy://<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.

libonomy://<base58 node id>@127.0.0.1:7513?disc=7513

func (Info) String

func (n Info) String() string

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

func (Info) Valid

func (n Info) Valid() error

Valid checks whether n is a valid complete node.

type LocalNode

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

LocalNode is a public-private key pair used locally.

func LoadIdentity

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

LoadIdentity loads a specific nodeid from the disk at the given path

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)

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

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

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.

func (LocalNode) PublicKey

func (n LocalNode) PublicKey() p2pcrypto.PublicKey

PublicKey returns the node's public key

Jump to

Keyboard shortcuts

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