kbucket

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2020 License: LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

package kbucket implements a kademlia 'k-bucket' routing table.

Index

Constants

This section is empty.

Variables

View Source
var ErrPeerRejectedHighLatency = errors.New("peer rejected; latency too high")
View Source
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) Has

func (b *Bucket) Has(id common.PeerId) bool

func (*Bucket) Len

func (b *Bucket) Len() int

func (*Bucket) MoveToFront

func (b *Bucket) MoveToFront(id common.PeerId)

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)

func (*Bucket) Remove

func (b *Bucket) Remove(id common.PeerId) bool

func (*Bucket) Split

func (b *Bucket) Split(cpl int, target common.PeerId) *Bucket

Split splits a buckets peers into two buckets, the methods receiver will have peers with CPL equal to cpl, the returned bucket will have peers with CPL greater than cpl (returned bucket has closer peers) CPL ==> CommonPrefixLen

type CplRefresh

type CplRefresh struct {
	Cpl           uint
	LastRefreshAt time.Time
}

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

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

func (*RouteTable) Update

func (rt *RouteTable) Update(peerID common.PeerId, addr string) error

Update adds or moves the given peer to the front of its respective bucket

Jump to

Keyboard shortcuts

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