Documentation ¶
Overview ¶
package kbucket implements a kademlia 'k-bucket' routing table.
Index ¶
- Variables
- func Closer(a, b peer.ID, key string) bool
- func SortClosestPeers(peers []peer.ID, target ID) []peer.ID
- type Bucket
- func (b *Bucket) Has(id peer.ID) bool
- func (b *Bucket) Len() int
- func (b *Bucket) MoveToFront(id peer.ID)
- func (b *Bucket) Peers() []peer.ID
- func (b *Bucket) PopBack() peer.ID
- func (b *Bucket) PushFront(p peer.ID)
- func (b *Bucket) Remove(id peer.ID)
- func (b *Bucket) Split(cpl int, target ID) *Bucket
- type ID
- type RoutingTable
- func (rt *RoutingTable) Find(id peer.ID) peer.ID
- func (rt *RoutingTable) ListPeers() []peer.ID
- func (rt *RoutingTable) NearestPeer(id ID) peer.ID
- func (rt *RoutingTable) NearestPeers(id ID, count int) []peer.ID
- func (rt *RoutingTable) Print()
- func (rt *RoutingTable) Remove(p peer.ID)
- func (rt *RoutingTable) Size() int
- func (rt *RoutingTable) Update(p peer.ID)
Constants ¶
This section is empty.
Variables ¶
var ErrLookupFailure = errors.New("failed to find any peer in table")
Returned if a routing table query returns no results. This is NOT expected behaviour
Functions ¶
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket holds a list of peers.
func (*Bucket) MoveToFront ¶
type ID ¶
type ID []byte
ID for IpfsDHT is in the XORKeySpace
The type dht.ID signifies that its contents have been hashed from either a peer.ID or a util.Key. This unifies the keyspace
func ConvertKey ¶
ConvertKey creates a DHT ID by hashing a local key (String)
func ConvertPeerID ¶
ConvertPeerID creates a DHT ID by hashing a Peer ID (Multihash)
type RoutingTable ¶
type RoutingTable struct { // kBuckets define all the fingers to other nodes. Buckets []*Bucket // notification functions PeerRemoved func(peer.ID) PeerAdded func(peer.ID) // contains filtered or unexported fields }
RoutingTable defines the routing table.
func NewRoutingTable ¶
func NewRoutingTable(bucketsize int, localID ID, latency time.Duration, m pstore.Metrics) *RoutingTable
NewRoutingTable creates a new routing table with a given bucketsize, local ID, and latency tolerance.
func (*RoutingTable) Find ¶
func (rt *RoutingTable) Find(id peer.ID) peer.ID
Find a specific peer by ID or return nil
func (*RoutingTable) ListPeers ¶
func (rt *RoutingTable) ListPeers() []peer.ID
ListPeers takes a RoutingTable and returns a list of all peers from all buckets in the table.
func (*RoutingTable) NearestPeer ¶
func (rt *RoutingTable) NearestPeer(id ID) peer.ID
NearestPeer returns a single peer that is nearest to the given ID
func (*RoutingTable) NearestPeers ¶
func (rt *RoutingTable) NearestPeers(id ID, count int) []peer.ID
NearestPeers returns a list of the 'count' closest peers to the given ID
func (*RoutingTable) Print ¶
func (rt *RoutingTable) Print()
Print prints a descriptive statement about the provided RoutingTable
func (*RoutingTable) Remove ¶
func (rt *RoutingTable) Remove(p peer.ID)
Remove deletes a peer from the routing table. This is to be used when we are sure a node has disconnected completely.
func (*RoutingTable) Size ¶
func (rt *RoutingTable) Size() int
Size returns the total number of peers in the routing table
func (*RoutingTable) Update ¶
func (rt *RoutingTable) Update(p peer.ID)
Update adds or moves the given peer to the front of its respective bucket If a peer gets removed from a bucket, it is returned