routing

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package routing implements Kademlia hash tables with XOR distance metrics.

Index

Constants

View Source
const (
	// IterateStore is iteration type for Store requests.
	IterateStore = IterateType(iota)

	// IterateBootstrap is iteration type for Bootstrap requests.
	IterateBootstrap

	// IterateFindNode is iteration type for FindNode requests.
	IterateFindNode

	// IterateFindValue is iteration type for FindValue requests.
	IterateFindValue
)
View Source
const (
	// ParallelCalls is a small number representing the degree of parallelism in insolar calls.
	ParallelCalls = 3

	// KeyBitSize is the size in bits of the keys used to identify nodes and store and
	// retrieve data; in basic Kademlia this is 160, the length of a SHA1.
	KeyBitSize = 160

	// MaxContactsInBucket the maximum number of contacts stored in a bucket.
	MaxContactsInBucket = 20
)

Variables

This section is empty.

Functions

func GetBucketIndexFromDifferingBit

func GetBucketIndexFromDifferingBit(id1, id2 []byte) int

GetBucketIndexFromDifferingBit returns appropriate bucket number for two node IDs.

Types

type HashTable

type HashTable struct {
	// The local node.
	Origin *node.Node

	// Routing table a list of all known nodes in the insolar
	// Nodes within buckets are sorted by least recently seen e.g.
	// [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
	//  ^                                                           ^
	//  └ Least recently seen                    Most recently seen ┘
	RoutingTable [][]*RouteNode // 160x20
	// contains filtered or unexported fields
}

HashTable represents the hash-table state.

func NewHashTable

func NewHashTable(id node.ID, address *node.Address) (*HashTable, error)

NewHashTable creates new HashTable.

func (*HashTable) DoesNodeExistInBucket

func (ht *HashTable) DoesNodeExistInBucket(bucket int, node []byte) bool

DoesNodeExistInBucket checks if given Node exists in given bucket.

func (*HashTable) GetAllNodesInBucketCloserThan

func (ht *HashTable) GetAllNodesInBucketCloserThan(bucket int, id []byte) [][]byte

GetAllNodesInBucketCloserThan returns all nodes from given bucket that are closer to id then our node.

func (*HashTable) GetClosestContacts

func (ht *HashTable) GetClosestContacts(num int, target []byte, ignoredNodes []*node.Node) *RouteSet

GetClosestContacts returns RouteSet with num closest Nodes to target.

func (*HashTable) GetRandomIDFromBucket

func (ht *HashTable) GetRandomIDFromBucket(bucket int) []byte

GetRandomIDFromBucket returns random node ID from given bucket.

func (*HashTable) GetRefreshTimeForBucket

func (ht *HashTable) GetRefreshTimeForBucket(bucket int) time.Time

GetRefreshTimeForBucket returns Time when given bucket must be refreshed.

func (*HashTable) GetTotalNodesInBucket

func (ht *HashTable) GetTotalNodesInBucket(bucket int) int

GetTotalNodesInBucket returns number of Nodes in bucket.

func (*HashTable) Lock

func (ht *HashTable) Lock()

Lock locks internal table mutex.

func (*HashTable) MarkNodeAsSeen

func (ht *HashTable) MarkNodeAsSeen(node []byte)

MarkNodeAsSeen marks given Node as seen.

func (*HashTable) ResetRefreshTimeForBucket

func (ht *HashTable) ResetRefreshTimeForBucket(bucket int)

ResetRefreshTimeForBucket resets refresh timer for given bucket.

func (*HashTable) TotalNodes

func (ht *HashTable) TotalNodes() int

TotalNodes returns total number of nodes in HashTable.

func (*HashTable) Unlock

func (ht *HashTable) Unlock()

Unlock unlocks internal table mutex.

type IterateType

type IterateType int

IterateType is type of iteration.

type RouteNode

type RouteNode struct {
	*node.Node
}

RouteNode represents a node in the insolar locally a separate struct due to the fact that we may want to add some metadata here later such as RTT, or LastSeen time.

func NewRouteNode

func NewRouteNode(node *node.Node) *RouteNode

NewRouteNode creates new RouteNode.

func RouteNodesFrom

func RouteNodesFrom(nodes []*node.Node) []*RouteNode

RouteNodesFrom creates list of RouteNodes from a list of Nodes.

type RouteSet

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

RouteSet is used in order to sort a list of arbitrary nodes against a comparator. These nodes are sorted by xor distance.

func NewRouteSet

func NewRouteSet() *RouteSet

NewRouteSet creates new RouteSet.

func (*RouteSet) Append

func (rs *RouteSet) Append(node *RouteNode)

Append adds single RouteNode to RouteSet.

func (*RouteSet) AppendMany

func (rs *RouteSet) AppendMany(nodes []*RouteNode)

AppendMany adds a list of RouteNodes to RouteSet.

func (*RouteSet) Contains

func (rs *RouteSet) Contains(node *RouteNode) bool

Contains checks if RouteSet contains given RouteNode.

func (*RouteSet) FirstNode

func (rs *RouteSet) FirstNode() *node.Node

FirstNode returns first Node from RouteSet.

func (*RouteSet) Len

func (rs *RouteSet) Len() int

Len returns number of nodes in RouteSet.

func (*RouteSet) Less

func (rs *RouteSet) Less(i, j int) bool

Less is a sorting function for RouteSet.

func (*RouteSet) Nodes

func (rs *RouteSet) Nodes() []*node.Node

Nodes returns list of RouteSet nodes.

func (*RouteSet) Remove

func (rs *RouteSet) Remove(node *RouteNode)

Remove removes node from RouteSet.

func (*RouteSet) RemoveMany

func (rs *RouteSet) RemoveMany(nodes []*RouteNode)

RemoveMany removes list of RoutNodes from RouteSet

func (*RouteSet) Swap

func (rs *RouteSet) Swap(i, j int)

Swap swaps two nodes in RouteSet.

Jump to

Keyboard shortcuts

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