go-libp2p-kbucket: github.com/libp2p/go-libp2p-kbucket Index | Files | Directories

package kbucket

import "github.com/libp2p/go-libp2p-kbucket"

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

Index

Package Files

bucket.go bucket_prefixmap.go sorting.go table.go table_refresh.go util.go

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

var ErrPeerRejectedHighLatency = errors.New("peer rejected; latency too high")
var ErrPeerRejectedNoCapacity = errors.New("peer rejected; insufficient capacity")

func Closer Uses

func Closer(a, b peer.ID, key string) bool

Closer returns true if a is closer to key than b is

func CommonPrefixLen Uses

func CommonPrefixLen(a, b ID) int

func SortClosestPeers Uses

func SortClosestPeers(peers []peer.ID, target ID) []peer.ID

Sort the given peers by their ascending distance from the target. A new slice is returned.

type ID Uses

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 Uses

func ConvertKey(id string) ID

ConvertKey creates a DHT ID by hashing a local key (String)

func ConvertPeerID Uses

func ConvertPeerID(id peer.ID) ID

ConvertPeerID creates a DHT ID by hashing a Peer ID (Multihash)

type PeerInfo Uses

type PeerInfo struct {
    Id  peer.ID

    // LastUsefulAt is the time instant at which the peer was last "useful" to us.
    // Please see the DHT docs for the definition of usefulness.
    LastUsefulAt time.Time

    // LastSuccessfulOutboundQueryAt is the time instant at which we last got a
    // successful query response from the peer.
    LastSuccessfulOutboundQueryAt time.Time

    // AddedAt is the time this peer was added to the routing table.
    AddedAt time.Time
    // contains filtered or unexported fields
}

PeerInfo holds all related information for a peer in the K-Bucket.

type RoutingTable Uses

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 Uses

func NewRoutingTable(bucketsize int, localID ID, latency time.Duration, m peerstore.Metrics, usefulnessGracePeriod time.Duration,
    df *peerdiversity.Filter) (*RoutingTable, error)

NewRoutingTable creates a new routing table with a given bucketsize, local ID, and latency tolerance.

func (*RoutingTable) Close Uses

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 Uses

func (rt *RoutingTable) Find(id peer.ID) peer.ID

Find a specific peer by ID or return nil

func (*RoutingTable) GenRandPeerID Uses

func (rt *RoutingTable) GenRandPeerID(targetCpl uint) (peer.ID, error)

GenRandPeerID generates a random peerID for a given Cpl

func (*RoutingTable) GetDiversityStats Uses

func (rt *RoutingTable) GetDiversityStats() []peerdiversity.CplDiversityStats

GetDiversityStats returns the diversity stats for the Routing Table if a diversity Filter is configured.

func (*RoutingTable) GetPeerInfos Uses

func (rt *RoutingTable) GetPeerInfos() []PeerInfo

GetPeerInfos returns the peer information that we've stored in the buckets

func (*RoutingTable) GetTrackedCplsForRefresh Uses

func (rt *RoutingTable) GetTrackedCplsForRefresh() []time.Time

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) ListPeers Uses

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) MarkAllPeersIrreplaceable Uses

func (rt *RoutingTable) MarkAllPeersIrreplaceable()

MarkAllPeersIrreplaceable marks all peers in the routing table as irreplaceable This means that we will never replace an existing peer in the table to make space for a new peer. However, they can still be removed by calling the `RemovePeer` API.

func (*RoutingTable) NPeersForCpl Uses

func (rt *RoutingTable) NPeersForCpl(cpl uint) int

NPeersForCPL returns the number of peers we have for a given Cpl

func (*RoutingTable) NearestPeer Uses

func (rt *RoutingTable) NearestPeer(id ID) peer.ID

NearestPeer returns a single peer that is nearest to the given ID

func (*RoutingTable) NearestPeers Uses

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 Uses

func (rt *RoutingTable) Print()

Print prints a descriptive statement about the provided RoutingTable

func (*RoutingTable) RemovePeer Uses

func (rt *RoutingTable) RemovePeer(p peer.ID)

RemovePeer should be called when the caller is sure that a peer is not useful for queries. For eg: the peer could have stopped supporting the DHT protocol. It evicts the peer from the Routing Table.

func (*RoutingTable) ResetCplRefreshedAtForID Uses

func (rt *RoutingTable) ResetCplRefreshedAtForID(id ID, newTime time.Time)

ResetCplRefreshedAtForID resets the refresh time for the Cpl of the given ID.

func (*RoutingTable) Size Uses

func (rt *RoutingTable) Size() int

Size returns the total number of peers in the routing table

func (*RoutingTable) TryAddPeer Uses

func (rt *RoutingTable) TryAddPeer(p peer.ID, queryPeer bool, isReplaceable bool) (bool, error)

It returns a boolean value set to true if the peer was newly added to the Routing Table, false otherwise. It also returns any error that occurred while adding the peer to the Routing Table. If the error is not nil, the boolean value will ALWAYS be false i.e. the peer wont be added to the Routing Table it it's not already there.

A return value of false with error=nil indicates that the peer ALREADY exists in the Routing Table.

func (*RoutingTable) UpdateLastSuccessfulOutboundQueryAt Uses

func (rt *RoutingTable) UpdateLastSuccessfulOutboundQueryAt(p peer.ID, t time.Time) bool

UpdateLastSuccessfulOutboundQuery updates the LastSuccessfulOutboundQueryAt time of the peer. Returns true if the update was successful, false otherwise.

func (*RoutingTable) UpdateLastUsefulAt Uses

func (rt *RoutingTable) UpdateLastUsefulAt(p peer.ID, t time.Time) bool

UpdateLastUsefulAt updates the LastUsefulAt time of the peer. Returns true if the update was successful, false otherwise.

Directories

PathSynopsis
generate
keyspace
peerdiversity

Package kbucket imports 18 packages (graph) and is imported by 41 packages. Updated 2020-09-04. Refresh now. Tools for package owners.