libp2p-hs-0.1.0.0: Haskell implementation of the libp2p networking stack
Safe HaskellNone
LanguageGHC2021

Network.LibP2P.DHT.RoutingTable

Description

k-Bucket routing table for the Kademlia DHT.

Organizes peers into 256 buckets by XOR distance prefix length. Each bucket holds up to k=20 peers, ordered by last-seen time (head = least-recently-seen, tail = most-recently-seen).

Synopsis

Documentation

data KBucket Source #

A k-bucket holding up to k peers. Ordered by last-seen: head = LRS (least recently seen), tail = MRS.

Constructors

KBucket 

Instances

Instances details
Show KBucket Source # 
Instance details

Defined in Network.LibP2P.DHT.RoutingTable

data RoutingTable Source #

Full routing table: 256 k-buckets indexed by prefix length. Uses sparse IntMap — only non-empty buckets are stored.

Constructors

RoutingTable 

Fields

Instances

Instances details
Show RoutingTable Source # 
Instance details

Defined in Network.LibP2P.DHT.RoutingTable

newRoutingTable :: PeerId -> RoutingTable Source #

Create a new empty routing table for the given local peer.

emptyBucket :: KBucket Source #

An empty k-bucket.

insertPeer :: BucketEntry -> RoutingTable -> (RoutingTable, InsertResult) Source #

Insert a peer into the routing table.

Rules: 1. Self is never inserted (returns Updated as no-op). 2. If peer already exists in the bucket, move it to tail → Updated. 3. If bucket has space, append to tail → Inserted. 4. If bucket is full, return BucketFull with the LRS peer ID.

removePeer :: PeerId -> RoutingTable -> RoutingTable Source #

Remove a peer from the routing table.

closestPeers :: DHTKey -> Int -> RoutingTable -> [BucketEntry] Source #

Find the n closest peers to a target key, sorted by XOR distance. Searches across all buckets.

bucketForPeer :: DHTKey -> RoutingTable -> Int Source #

Compute the bucket index for a peer key relative to the local key. This is the common prefix length (0-255).

bucketSize :: Int -> RoutingTable -> Int Source #

Get the number of entries in a specific bucket.

allPeers :: RoutingTable -> [BucketEntry] Source #

Get all peers across all buckets.