Skip to main content

Module client

Module client 

Source
Expand description

Client-side cdn/dht/v1 request primitives.

The handler in crate::handlers::dht is the server half — it receives FindNode / FindValue / Store / BatchStore requests and writes responses. This module is the client half: outbound requests issued by the bootstrap path (initial FindNode(self.node_id)), the republish scheduler (a per-hash Store on eager publish and one BatchStore per receiver on the periodic drain), and the iterative requester-side FindValue lookup in crate::dht::lookup.

Each call:

  1. Connects to the peer’s EndpointAddr with ALPN cdn/dht/v1.
  2. Opens a bi stream.
  3. Writes one framed wire::DhtMessage request.
  4. Reads one framed response, decodes, and returns it.
  5. Closes the connection with 0u32 (no app error).

The signatures mirror the server-side message types: callers provide the request fields, get back the response struct. Error handling surfaces via anyhow::Result; a peer that closes the stream with an ADR 013 application error code (rate-limited, malformed) surfaces as an anyhow error the caller logs and retries on its next cycle.

Constants§

DHT_CLIENT_TIMEOUT
Per-request hard timeout for outbound DHT exchanges. Shorter than the sum of the server-side accept-bi timeout (5s) and read timeout (5s) in crate::handlers::dht so a hung peer doesn’t wedge a republish sweep.

Functions§

batch_store
Send a single BatchStore request to target and return the ack (ADR 022 §STORE Flow Batched STORE). One bool per request hash comes back in request order. Used by the re-publish scheduler, which groups a drain cycle’s hashes by receiver and sends each receiver its set via this. Every DHT node implements BatchStore, so there is no per-hash fallback.
find_node
Send a single FindNode request to target and return the response.
find_value
Send a single FindValue request to target and return the response.
store
Send a single Store request to target and return the ack.