node

package
v0.0.0-...-bc2601f Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 CheckUserPort

func CheckUserPort(port uint32) bool

CheckUserPort tries to listen on a port and check whether is usable or not

func GenerateTestNode

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

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

func GenerateTestNodeWithConfig

func GenerateTestNodeWithConfig(t *testing.T, config config.Config) (*LocalNode, Node)

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.

func StringFromNode

func StringFromNode(n Node) string

StringFromNode generates a string that represent a node in the network in following format: 126.0.0.1:3572/r9gJRWVB9JVPap2HKnduoFySvHtVTfJdQ4WG8DriUD82.

func XOR

func XOR(a, b []byte) []byte

XOR is a helper method used to return a byte slice which is the XOR of 2 provided byte slices.

Types

type DhtID

type DhtID []byte

DhtID is a dht-compatible DhtID using the XOR keyspace.

func NewDhtID

func NewDhtID(key []byte) DhtID

NewDhtID creates a new dht id from provided binary data.

func NewDhtIDFromBase58

func NewDhtIDFromBase58(s string) DhtID

NewDhtIDFromBase58 creates a new dht DhtID from provided base58 encoded binary data.

func NewDhtIDFromHex

func NewDhtIDFromHex(s string) (DhtID, error)

NewDhtIDFromHex creates a new dht DhtID from provided hex-encoded string.

func (DhtID) Closer

func (id DhtID) Closer(id1 DhtID, id2 DhtID) bool

Closer returns true if id1 is closer to id3 than id2 using XOR arithmetic.

func (DhtID) CommonPrefixLen

func (id DhtID) CommonPrefixLen(o DhtID) int

CommonPrefixLen returns the common shared prefix length in BITS of the binary numbers represented by the ids. tradeoff the pretty func we had with this more efficient one. (faster than libp2p and eth)

func (DhtID) Distance

func (id DhtID) Distance(id1 DhtID) *big.Int

Distance returns the distance between DhtID and id1 encoded as a big int.

func (DhtID) Equals

func (id DhtID) Equals(other DhtID) bool

Equals returns true iff other equals the DhtID.

func (DhtID) Less

func (id DhtID) Less(o DhtID) bool

Less returns true iff the binary number represented by DhtID is less than the number represented by o.

func (DhtID) Pretty

func (id DhtID) Pretty() string

Pretty returns a readable string of the DhtID.

func (DhtID) SortByDistance

func (id DhtID) SortByDistance(ids []DhtID) []DhtID

SortByDistance ids based on xor-distance from DhtID.

func (DhtID) String

func (id DhtID) String() string

func (DhtID) Xor

func (id DhtID) Xor(o DhtID) DhtID

Xor returns a XOR of the DhtID with o.

func (DhtID) ZeroPrefixLen

func (id DhtID) ZeroPrefixLen() int

ZeroPrefixLen returns the zero prefix length of the binary number represnted by DhtID in bits.

type LocalNode

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

LocalNode implementation.

func NewNodeIdentity

func NewNodeIdentity(config config.Config, address string) (*LocalNode, error)

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

func (*LocalNode) NetworkID

func (n *LocalNode) NetworkID() uint32

NetworkID returns the local node's network id (testnet/mainnet, etc..)

func (*LocalNode) PrivateKey

func (n *LocalNode) PrivateKey() crypto.PrivateKey

PrivateKey returns this node's private key.

type Node

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

Node is the basic node identity struct

var EmptyNode Node

EmptyNode represents an uninitialized node

func GenerateRandomNodeData

func GenerateRandomNodeData() Node

GenerateRandomNodeData generates a remote random node data for testing.

func GenerateRandomNodesData

func GenerateRandomNodesData(n int) []Node

GenerateRandomNodesData generates remote nodes data for testing.

func New

func New(key crypto.PublicKey, address string) Node

New creates a new remotenode identity from a public key and an address

func NewNodeFromString

func NewNodeFromString(data string) (Node, error)

NewNodeFromString creates a remote identity from a string in the following format: 126.0.0.1:3572/r9gJRWVB9JVPap2HKnduoFySvHtVTfJdQ4WG8DriUD82 .

func SortByDhtID

func SortByDhtID(nodes []Node, id DhtID) []Node

SortByDhtID Sorts a Node array by DhtID id, returns a sorted array

func Union

func Union(list1 []Node, list2 []Node) []Node

Union returns a union of 2 lists of nodes.

func (Node) Address

func (n Node) Address() string

Address returns the ip address of the node

func (Node) DhtID

func (n Node) DhtID() DhtID

DhtID creates a dhtid from the public key

func (Node) Pretty

func (n Node) Pretty() string

Pretty returns a pretty string from the node's info

func (Node) PublicKey

func (n Node) PublicKey() crypto.PublicKey

PublicKey returns the public key of the node

func (Node) String

func (n Node) String() string

String returns a string representation of the node's public key

Jump to

Keyboard shortcuts

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