| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
LibP2P.DHT.Lookup
Description
Iterative lookup algorithms for the Kademlia DHT.
Implements FIND_NODE, GET_VALUE, and GET_PROVIDERS iterative lookups per specs/kad-dht. 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
- data LookupResult
- = FoundPeers ![BucketEntry]
- | FoundValue !DHTRecord ![BucketEntry]
- | FoundProviders ![ProviderEntry] ![BucketEntry]
- iterativeFindNode :: DHTNode -> PeerId -> IO [BucketEntry]
- iterativeGetValue :: DHTNode -> Validator -> ByteString -> IO (Either String DHTRecord)
- iterativeGetProviders :: DHTNode -> ByteString -> IO [ProviderEntry]
- bootstrap :: DHTNode -> [PeerId] -> IO ()
- startBootstrap :: DHTNode -> [PeerId] -> Int -> IO ()
- defaultBootstrapIntervalMicros :: Int
Lookup results
data LookupResult Source #
Result of an iterative lookup.
Constructors
| FoundPeers ![BucketEntry] | |
| FoundValue !DHTRecord ![BucketEntry] | |
| FoundProviders ![ProviderEntry] ![BucketEntry] |
Instances
| Show LookupResult Source # | |
Defined in LibP2P.DHT.Lookup Methods showsPrec :: Int -> LookupResult -> ShowS # show :: LookupResult -> String # showList :: [LookupResult] -> ShowS # | |
Iterative lookups
iterativeFindNode :: DHTNode -> PeerId -> IO [BucketEntry] Source #
Iterative FIND_NODE: find the k closest peers to a target peer.
Per specs/kad-dht, the FIND_NODE wire key must be the target's binary Peer ID; XOR distance is computed over SHA-256 digests, so only local comparisons use the hashed key.
Bounded by dhtQueryTimeout (default 10s). Outstanding parallel
queries are cancelled when the deadline expires.
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: insert seeds, self-lookup, refresh every non-empty bucket.
Startup is explicit: call bootstrap or startBootstrap. newDHTNode
does not start a loop, matching go-libp2p's IpfsDHT.Bootstrap.
The whole run is bounded by dhtQueryTimeout (default 10s).
startBootstrap :: DHTNode -> [PeerId] -> Int -> IO () Source #
Start a periodic bootstrap loop. Runs one refresh immediately, then
every intervalMicros. Cancelled by stopDHTNode.
defaultBootstrapIntervalMicros :: Int Source #
Default periodic bootstrap interval: 10 minutes (specs/kad-dht).