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) DoesHostExistInBucket(bucket int, host []byte) bool
- func (ht *HashTable) GetAllHostsInBucketCloserThan(bucket int, id []byte) [][]byte
- func (ht *HashTable) GetClosestContacts(num int, target []byte, ignoredHosts []*host.Host) *RouteSet
- func (ht *HashTable) GetRandomIDFromBucket(bucket int) []byte
- func (ht *HashTable) GetRefreshTimeForBucket(bucket int) time.Time
- func (ht *HashTable) GetTotalHostsInBucket(bucket int) int
- func (ht *HashTable) Lock()
- func (ht *HashTable) MarkHostAsSeen(host []byte)
- func (ht *HashTable) ResetRefreshTimeForBucket(bucket int)
- func (ht *HashTable) TotalHosts() int
- func (ht *HashTable) Unlock()
- type IterateType
- type RouteHost
- type RouteSet
- func (rs *RouteSet) Append(host *RouteHost)
- func (rs *RouteSet) AppendMany(hosts []*RouteHost)
- func (rs *RouteSet) Contains(host *RouteHost) bool
- func (rs *RouteSet) FirstHost() *host.Host
- func (rs *RouteSet) Hosts() []*host.Host
- func (rs *RouteSet) Len() int
- func (rs *RouteSet) Less(i, j int) bool
- func (rs *RouteSet) Remove(host *RouteHost)
- func (rs *RouteSet) RemoveMany(hosts []*RouteHost)
- 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 // IterateFindHost is iteration type for FindHost requests. IterateFindHost // IterateFindValue is iteration type for FindValue requests. IterateFindValue )
const ( // ParallelCalls is a small number representing the degree of parallelism in network calls. ParallelCalls = 3 // KeyBitSize is the size in bits of the keys used to identify hosts 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 host IDs.
Types ¶
type HashTable ¶
type HashTable struct { // The local host. Origin *host.Host // Routing table a list of all known hosts in the network // Hosts within buckets are sorted by least recently seen e.g. // [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ] // ^ ^ // └ Least recently seen Most recently seen ┘ RoutingTable [][]*RouteHost // 160x20 // contains filtered or unexported fields }
HashTable represents the hash-table state.
func NewHashTable ¶
NewHashTable creates new HashTable.
func (*HashTable) DoesHostExistInBucket ¶
DoesHostExistInBucket checks if given Host exists in given bucket.
func (*HashTable) GetAllHostsInBucketCloserThan ¶
GetAllHostsInBucketCloserThan returns all hosts from given bucket that are closer to id then our host.
func (*HashTable) GetClosestContacts ¶
func (ht *HashTable) GetClosestContacts(num int, target []byte, ignoredHosts []*host.Host) *RouteSet
GetClosestContacts returns RouteSet with num closest Hosts to target.
func (*HashTable) GetRandomIDFromBucket ¶
GetRandomIDFromBucket returns random host ID from given bucket.
func (*HashTable) GetRefreshTimeForBucket ¶
GetRefreshTimeForBucket returns Time when given bucket must be refreshed.
func (*HashTable) GetTotalHostsInBucket ¶
GetTotalHostsInBucket returns number of Hosts in bucket.
func (*HashTable) MarkHostAsSeen ¶
MarkHostAsSeen marks given Host as seen.
func (*HashTable) ResetRefreshTimeForBucket ¶
ResetRefreshTimeForBucket resets refresh timer for given bucket.
func (*HashTable) TotalHosts ¶
TotalHosts returns total number of hosts in HashTable.
type RouteHost ¶
RouteHost represents a host in the network 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 NewRouteHost ¶
NewRouteHost creates new RouteHost.
func RouteHostsFrom ¶
RouteHostsFrom creates list of RouteHosts from a list of Hosts.
type RouteSet ¶
type RouteSet struct {
// contains filtered or unexported fields
}
RouteSet is used in order to sort a list of arbitrary hosts against a comparator. These hosts are sorted by xor distance.
func (*RouteSet) AppendMany ¶
AppendMany adds a list of RouteHosts to RouteSet.
func (*RouteSet) RemoveMany ¶
RemoveMany removes list of RoutHosts from RouteSet