Documentation
¶
Overview ¶
Package routing implements Kademlia hash tables with XOR distance metrics.
Index ¶
- Constants
- func GetBucketIndexFromDifferingBit(id1, id2 []byte) int
- type HashTable
- func (ht *HashTable) DoesNodeExistInBucket(bucket int, node []byte) bool
- func (ht *HashTable) GetAllNodesInBucketCloserThan(bucket int, id []byte) [][]byte
- func (ht *HashTable) GetClosestContacts(num int, target []byte, ignoredNodes []*node.Node) *RouteSet
- func (ht *HashTable) GetRandomIDFromBucket(bucket int) []byte
- func (ht *HashTable) GetRefreshTimeForBucket(bucket int) time.Time
- func (ht *HashTable) GetTotalNodesInBucket(bucket int) int
- func (ht *HashTable) Lock()
- func (ht *HashTable) MarkNodeAsSeen(node []byte)
- func (ht *HashTable) ResetRefreshTimeForBucket(bucket int)
- func (ht *HashTable) TotalNodes() int
- func (ht *HashTable) Unlock()
- type IterateType
- type RouteNode
- type RouteSet
- func (rs *RouteSet) Append(node *RouteNode)
- func (rs *RouteSet) AppendMany(nodes []*RouteNode)
- func (rs *RouteSet) Contains(node *RouteNode) bool
- func (rs *RouteSet) FirstNode() *node.Node
- func (rs *RouteSet) Len() int
- func (rs *RouteSet) Less(i, j int) bool
- func (rs *RouteSet) Nodes() []*node.Node
- func (rs *RouteSet) Remove(node *RouteNode)
- func (rs *RouteSet) RemoveMany(nodes []*RouteNode)
- func (rs *RouteSet) Swap(i, j int)
Constants ¶
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 )
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 ¶
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 ¶
NewHashTable creates new HashTable.
func (*HashTable) DoesNodeExistInBucket ¶
DoesNodeExistInBucket checks if given Node exists in given bucket.
func (*HashTable) GetAllNodesInBucketCloserThan ¶
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 ¶
GetRandomIDFromBucket returns random node ID from given bucket.
func (*HashTable) GetRefreshTimeForBucket ¶
GetRefreshTimeForBucket returns Time when given bucket must be refreshed.
func (*HashTable) GetTotalNodesInBucket ¶
GetTotalNodesInBucket returns number of Nodes in bucket.
func (*HashTable) MarkNodeAsSeen ¶
MarkNodeAsSeen marks given Node as seen.
func (*HashTable) ResetRefreshTimeForBucket ¶
ResetRefreshTimeForBucket resets refresh timer for given bucket.
func (*HashTable) TotalNodes ¶
TotalNodes returns total number of nodes in HashTable.
type RouteNode ¶
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 ¶
NewRouteNode creates new RouteNode.
func RouteNodesFrom ¶
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 (*RouteSet) AppendMany ¶
AppendMany adds a list of RouteNodes to RouteSet.
func (*RouteSet) RemoveMany ¶
RemoveMany removes list of RoutNodes from RouteSet