| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
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
- data LookupResult
- = FoundPeers ![BucketEntry]
- | FoundValue !DHTRecord ![BucketEntry]
- | FoundProviders ![ProviderEntry] ![BucketEntry]
- iterativeFindNode :: DHTNode -> DHTKey -> IO [BucketEntry]
- iterativeGetValue :: DHTNode -> Validator -> ByteString -> IO (Either String DHTRecord)
- iterativeGetProviders :: DHTNode -> ByteString -> IO [ProviderEntry]
- bootstrap :: DHTNode -> [PeerId] -> IO ()
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 Network.LibP2P.DHT.Lookup Methods showsPrec :: Int -> LookupResult -> ShowS # show :: LookupResult -> String # showList :: [LookupResult] -> ShowS # | |
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.