| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
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
- data KBucket = KBucket {
- bucketEntries :: !(Seq BucketEntry)
- data RoutingTable = RoutingTable {}
- newRoutingTable :: PeerId -> RoutingTable
- emptyBucket :: KBucket
- insertPeer :: BucketEntry -> RoutingTable -> (RoutingTable, InsertResult)
- removePeer :: PeerId -> RoutingTable -> RoutingTable
- closestPeers :: DHTKey -> Int -> RoutingTable -> [BucketEntry]
- bucketForPeer :: DHTKey -> RoutingTable -> Int
- bucketSize :: Int -> RoutingTable -> Int
- allPeers :: RoutingTable -> [BucketEntry]
Documentation
A k-bucket holding up to k peers. Ordered by last-seen: head = LRS (least recently seen), tail = MRS.
Constructors
| KBucket | |
Fields
| |
data RoutingTable Source #
Full routing table: 256 k-buckets indexed by prefix length. Uses sparse IntMap — only non-empty buckets are stored.
Instances
| Show RoutingTable Source # | |
Defined in Network.LibP2P.DHT.RoutingTable Methods showsPrec :: Int -> RoutingTable -> ShowS # show :: RoutingTable -> String # showList :: [RoutingTable] -> ShowS # | |
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.