Documentation
¶
Overview ¶
package kbucket implements a kademlia 'k-bucket' routing table.
Index ¶
- Variables
- func Closer(a, b peer.ID, key string) bool
- func CommonPrefixLen(a, b ID) int
- func SortClosestPeers(peers []peer.ID, target ID) []peer.ID
- type CplRefresh
- type ID
- type Option
- type PeerInfo
- type PeerSelectionFunc
- type PeerState
- type PeerValidationFunc
- type RoutingTable
- func (rt *RoutingTable) Close() error
- func (rt *RoutingTable) Find(id peer.ID) peer.ID
- func (rt *RoutingTable) GenRandPeerID(targetCpl uint) (peer.ID, error)
- func (rt *RoutingTable) GetTrackedCplsForRefresh() []CplRefresh
- func (rt *RoutingTable) HandlePeerAlive(p peer.ID) (evicted peer.ID, err error)
- func (rt *RoutingTable) HandlePeerDead(p peer.ID)
- func (rt *RoutingTable) HandlePeerDisconnect(p peer.ID)
- func (rt *RoutingTable) IsBucketFull(cpl uint) bool
- func (rt *RoutingTable) ListPeers() []peer.ID
- func (rt *RoutingTable) NPeersForCpl(cpl uint) int
- 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) ResetCplRefreshedAtForID(id ID, newTime time.Time)
- func (rt *RoutingTable) Size() int
Constants ¶
This section is empty.
Variables ¶
var Defaults = func(o *options) error { o.tableCleanup.peerValidationTimeout = 30 * time.Second o.tableCleanup.interval = 2 * time.Minute o.tableCleanup.peersForValidationFnc = func(peers []PeerInfo) []PeerInfo { var selectedPeers []PeerInfo for _, p := range peers { if p.State == PeerStateMissing { selectedPeers = append(selectedPeers, p) } } return selectedPeers } return nil }
Defaults are the default options. This option will be automatically prepended to any options you pass to the Routing Table constructor.
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
var ErrPeerRejectedHighLatency = errors.New("peer rejected; latency too high")
var ErrPeerRejectedNoCapacity = errors.New("peer rejected; insufficient capacity")
Functions ¶
func CommonPrefixLen ¶ added in v0.1.0
Types ¶
type CplRefresh ¶ added in v0.2.3
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 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 Option ¶ added in v0.3.1
type Option func(*options) error
Option is the Routing Table functional option type.
func PeerValidationFnc ¶ added in v0.3.0
func PeerValidationFnc(f PeerValidationFunc) Option
PeerValidationFnc configures the Peer Validation function used for RT cleanup. Not configuring this disables Routing Table cleanup.
func PeerValidationTimeout ¶ added in v0.3.0
PeerValidationTimeout sets the timeout for a single peer validation during cleanup.
func PeersForValidationFnc ¶ added in v0.3.0
func PeersForValidationFnc(f PeerSelectionFunc) Option
PeersForValidationFnc configures the function that will be used to select the peers that need to be validated during cleanup.
func TableCleanupInterval ¶ added in v0.3.0
TableCleanupInterval configures the interval between two runs of the Routing Table cleanup routine.
type PeerSelectionFunc ¶ added in v0.3.0
PeerSelectionFunc is the signature of a function that selects zero or more peers from the given peers based on some criteria.
type PeerState ¶ added in v0.3.0
type PeerState int
PeerState is the state of the peer as seen by the Routing Table.
type PeerValidationFunc ¶ added in v0.3.0
PeerValidationFunc is the signature of a function that determines the validity a peer for Routing Table membership.
type RoutingTable ¶
type RoutingTable struct {
// 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 peerstore.Metrics, opts ...Option) (*RoutingTable, error)
NewRoutingTable creates a new routing table with a given bucketsize, local ID, and latency tolerance. Passing a nil PeerValidationFunc disables periodic table cleanup.
func (*RoutingTable) Close ¶ added in v0.3.0
func (rt *RoutingTable) Close() error
Close shuts down the Routing Table & all associated processes. It is safe to call this multiple times.
func (*RoutingTable) Find ¶
func (rt *RoutingTable) Find(id peer.ID) peer.ID
Find a specific peer by ID or return nil
func (*RoutingTable) GenRandPeerID ¶ added in v0.2.1
func (rt *RoutingTable) GenRandPeerID(targetCpl uint) (peer.ID, error)
GenRandPeerID generates a random peerID for a given Cpl
func (*RoutingTable) GetTrackedCplsForRefresh ¶ added in v0.2.3
func (rt *RoutingTable) 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 (*RoutingTable) HandlePeerAlive ¶ added in v0.3.0
HandlePeerAlive should be called when the caller detects that a peer is alive. This could be a successful incoming/outgoing connection with the peer or even a successful message delivery to/from the peer. This enables the RT to update it's internal state to mark the peer as active.
func (*RoutingTable) HandlePeerDead ¶ added in v0.3.0
func (rt *RoutingTable) HandlePeerDead(p peer.ID)
HandlePeerDead should be called when the caller is sure that a peer is dead/not dialable. It evicts the peer from the Routing Table and also removes it as a replacement candidate if it is one.
func (*RoutingTable) HandlePeerDisconnect ¶ added in v0.3.0
func (rt *RoutingTable) HandlePeerDisconnect(p peer.ID)
HandlePeerDisconnect should be called when the caller detects a disconnection with the peer. This enables the Routing Table to mark the peer as missing.
func (*RoutingTable) IsBucketFull ¶ added in v0.3.1
func (rt *RoutingTable) IsBucketFull(cpl uint) bool
IsBucketFull returns true if the Logical bucket for a given Cpl is full
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) NPeersForCpl ¶ added in v0.3.1
func (rt *RoutingTable) NPeersForCpl(cpl uint) int
NPeersForCPL returns the number of peers we have for a given Cpl
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) ResetCplRefreshedAtForID ¶ added in v0.2.3
func (rt *RoutingTable) ResetCplRefreshedAtForID(id ID, newTime time.Time)
ResetCplRefreshedAtForID resets the refresh time for the Cpl of the given ID.
func (*RoutingTable) Size ¶
func (rt *RoutingTable) Size() int
Size returns the total number of peers in the routing table
