node

package
v0.0.0-...-42befb5 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToNodeInfo

func ToNodeInfo(nodes []RemoteNodeData, filterID string) []*pb.NodeInfo

ToNodeInfo returns marshaled protobufs node infos slice from a slice of RemoteNodeData.

filterId: node id to exclude from the result.

Types

type PeerDistance

type PeerDistance struct {
	Node     RemoteNodeData
	Distance dht.ID
}

PeerDistance defines a distance from a node expressed as a dht id.

type PeerSorter

type PeerSorter []*PeerDistance

PeerSorter is a sort.Interface of RemoteNodeData by XOR distance.

func CopyPeersFromList

func CopyPeersFromList(target dht.ID, dest PeerSorter, src *list.List) PeerSorter

CopyPeersFromList copies peers from the list and returns a PeerSorter for the list.

func (PeerSorter) Len

func (p PeerSorter) Len() int

func (PeerSorter) Less

func (p PeerSorter) Less(a, b int) bool

func (PeerSorter) Swap

func (p PeerSorter) Swap(a, b int)

type RemoteNodeData

type RemoteNodeData interface {
	ID() string    // base58 encoded node key/id
	IP() string    // node tcp listener e.g. 127.0.0.1:3038
	Bytes() []byte // node raw id bytes

	DhtID() dht.ID // dht id must be uniformly distributed for XOR distance to work, hence we hash the node key/id to create it

	GetLastFindNodeCall(nodeID string) time.Time // time of last find node call sent to node
	SetLastFindNodeCall(nodeID string, t time.Time)

	Pretty() string
}

RemoteNodeData defines basic remote node data. Outside of swarm local node works with RemoteNodeData and not with Peers. Peers should only be used internally by swarm.

func FromNodeInfos

func FromNodeInfos(nodes []*pb.NodeInfo) []RemoteNodeData

FromNodeInfos converts a list of NodeInfo to a list of RemoteNodeData.

func NewRemoteNodeData

func NewRemoteNodeData(id string, ip string) RemoteNodeData

NewRemoteNodeData creates a new RemoteNodeData.

func NewRemoteNodeDataFromString

func NewRemoteNodeDataFromString(data string) RemoteNodeData

NewRemoteNodeDataFromString creates a remote node from a string in the following format: 126.0.0.1:3572/QmcjTLy94HGFo4JoYibudGeBV2DSBb6E4apBjFsBGnMsWa .

func PickFindNodeServers

func PickFindNodeServers(nodes []RemoteNodeData, nodeID string, count int) []RemoteNodeData

PickFindNodeServers picks up to count server who haven't been queried recently.

nodeId - the target node id of this find node operation.

Used in KAD node discovery.

func SortClosestPeers

func SortClosestPeers(peers []RemoteNodeData, target dht.ID) []RemoteNodeData

SortClosestPeers sorts peers based on distance from target.

func Union

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

Union returns a union of 2 lists of nodes.

Jump to

Keyboard shortcuts

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