Documentation ¶
Overview ¶
package kbucket implements a kademlia 'k-bucket' routing table.
Index ¶
- Variables
- type Bucket
- func (b *Bucket) Has(id common.PeerId) bool
- func (b *Bucket) Len() int
- func (b *Bucket) MoveToFront(id common.PeerId)
- func (b *Bucket) Peers() []common.PeerIDAddressPair
- func (b *Bucket) PopBack() common.PeerIDAddressPair
- func (b *Bucket) PushFront(p common.PeerIDAddressPair)
- func (b *Bucket) Remove(id common.PeerId) bool
- func (b *Bucket) Split(cpl int, target common.PeerId) *Bucket
- type CplRefresh
- type RouteTable
- func (rt *RouteTable) Find(id common.PeerId) (common.PeerIDAddressPair, bool)
- func (rt *RouteTable) GenRandKadId(targetCpl uint) common.PeerId
- func (rt *RouteTable) GetTrackedCplsForRefresh() []CplRefresh
- func (rt *RouteTable) ListPeers() []common.PeerIDAddressPair
- func (rt *RouteTable) NearestPeers(id common.PeerId, count int) []common.PeerIDAddressPair
- func (rt *RouteTable) Print()
- func (rt *RouteTable) Remove(p common.PeerId)
- func (rt *RouteTable) ResetCplRefreshedAtForID(id common.PeerId, newTime time.Time)
- func (rt *RouteTable) Size() int
- func (rt *RouteTable) Update(peerID common.PeerId, addr string) error
Constants ¶
This section is empty.
Variables ¶
var ErrPeerRejectedHighLatency = errors.New("peer rejected; latency too high")
var ErrPeerRejectedNoCapacity = errors.New("peer rejected; insufficient capacity")
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket holds a list of peers.
func (*Bucket) MoveToFront ¶
func (*Bucket) Peers ¶
func (b *Bucket) Peers() []common.PeerIDAddressPair
func (*Bucket) PopBack ¶
func (b *Bucket) PopBack() common.PeerIDAddressPair
func (*Bucket) PushFront ¶
func (b *Bucket) PushFront(p common.PeerIDAddressPair)
type CplRefresh ¶
CplRefresh contains a CPL(common prefix length) with the host & the last time we refreshed that cpl/searched for an ID which has that cpl with the host.
type RouteTable ¶
type RouteTable struct { // kBuckets define all the fingers to other nodes. Buckets []*Bucket // notification callback functions PeerRemoved func(id common.PeerId) PeerAdded func(id common.PeerId) // contains filtered or unexported fields }
RouteTable defines the routing table.
func NewRoutingTable ¶
func NewRoutingTable(bucketsize int, localID common.PeerId) *RouteTable
NewRoutingTable creates a new routing table with a given bucketsize, local ID, and latency tolerance.
func (*RouteTable) Find ¶
func (rt *RouteTable) Find(id common.PeerId) (common.PeerIDAddressPair, bool)
Find a specific peer by ID or return nil
func (*RouteTable) GenRandKadId ¶
func (rt *RouteTable) GenRandKadId(targetCpl uint) common.PeerId
GenRandPeerID generates a random peerID for a given Cpl
func (*RouteTable) GetTrackedCplsForRefresh ¶
func (rt *RouteTable) GetTrackedCplsForRefresh() []CplRefresh
GetTrackedCplsForRefresh returns the Cpl's we are tracking for refresh. Caller is free to modify the returned slice as it is a defensive copy.
func (*RouteTable) ListPeers ¶
func (rt *RouteTable) ListPeers() []common.PeerIDAddressPair
ListPeers takes a RoutingTable and returns a list of all peers from all buckets in the table.
func (*RouteTable) NearestPeers ¶
func (rt *RouteTable) NearestPeers(id common.PeerId, count int) []common.PeerIDAddressPair
func (*RouteTable) Print ¶
func (rt *RouteTable) Print()
Print prints a descriptive statement about the provided RouteTable
func (*RouteTable) Remove ¶
func (rt *RouteTable) Remove(p common.PeerId)
Remove deletes a peer from the routing table. This is to be used when we are sure a node has disconnected completely.
func (*RouteTable) ResetCplRefreshedAtForID ¶
func (rt *RouteTable) ResetCplRefreshedAtForID(id common.PeerId, newTime time.Time)
ResetCplRefreshedAtForID resets the refresh time for the Cpl of the given ID.
func (*RouteTable) Size ¶
func (rt *RouteTable) Size() int
Size returns the total number of peers in the routing table