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

Network.LibP2P.DHT.Lookup

Description

Iterative lookup algorithms for the Kademlia DHT.

Implements FIND_NODE, GET_VALUE, and GET_PROVIDERS iterative lookups per docs/09-dht.md. Uses STM for shared state and async for concurrent queries (alpha=10 parallelism).

Candidates are maintained as a list sorted by XOR distance to the target key, ensuring the closest peers are always queried first.

Bootstrap performs a self-lookup followed by per-bucket random refresh.

Synopsis

Lookup results

data LookupResult Source #

Result of an iterative lookup.

Instances

Instances details
Show LookupResult Source # 
Instance details

Defined in Network.LibP2P.DHT.Lookup

Iterative lookups

iterativeFindNode :: DHTNode -> DHTKey -> IO [BucketEntry] Source #

Iterative FIND_NODE: find the k closest peers to a target key.

Algorithm: 1. Seed candidates with k closest from local routing table 2. Query up to alpha unqueried candidates in parallel 3. Merge returned closerPeers into candidates 4. Terminate when top-k candidates all queried or no unqueried remain

iterativeGetValue :: DHTNode -> Validator -> ByteString -> IO (Either String DHTRecord) Source #

Iterative GET_VALUE: find a value by key, with convergence repair.

Same as FIND_NODE but also tracks the best value found and which peers returned it. On completion, sends PUT_VALUE to peers with outdated values.

iterativeGetProviders :: DHTNode -> ByteString -> IO [ProviderEntry] Source #

Iterative GET_PROVIDERS: find providers for a content key.

Bootstrap

bootstrap :: DHTNode -> [PeerId] -> IO () Source #

Bootstrap the DHT: connect to seeds, self-lookup, per-bucket refresh.