Expand description
Wire message types for the cdn/dht/v1 Kademlia content DHT (ADR 022).
cdn/dht/v1 is the primary content discovery mechanism: nodes publish
(hash → NodeId) records to the K closest peers in keyspace, and clients
iteratively look up providers in O(log N) hops. This module defines the
wire surface only — routing-table, record-store, scheduler, and rate-limit
logic live in decdn-node.
§Authentication model
StoreRequest has no per-record signature. The receiver instead checks
that holder equals the authenticated NodeId of the inbound QUIC
connection (NodeIds are 32-byte Ed25519 public keys; iroh’s QUIC handshake
binds the connection to that key). This depends on records being pushed
directly by the holder to the K-closest nodes and never relayed
peer-to-peer — if a future scheme introduces peer relay of records, a
per-record signature MUST be reintroduced together with an in-scope sender
timestamp in the signed body (ADR 022 §STORE Flow).
§BatchStore wire types
BatchStoreRequest / BatchStoreAck are part of cdn/dht/v1 at
DhtMessage discriminants 4 and 5, ahead of FindNode /
FindNodeResponse at 6 and 7 to match ADR 022’s variant order. They
carry the bandwidth optimization in which one holder publishes many
hashes to one receiver in a single RPC (ADR 022 §STORE Flow Batched
STORE). The receiver-side admission and two-stage rate-limit
accounting live in decdn-node; every DHT node implements them, so
there is no per-hash fallback or support negotiation.
§Bounded-Vec deserialization
Network responses with Vec fields are bounded at decode time via
#[serde(deserialize_with = ...)] hooks that enforce the wire-level
caps below. The framing layer caps the whole message at 16 MiB
(crate::framing::MAX_MESSAGE_SIZE), but the per-field caps stop
peers from forcing the responder to allocate up to a megabyte of
32-byte NodeIds (or up to ~16M / 8B booleans) inside one frame.
Pattern mirrors ProbeResponseBody::rate_per_mb.
Structs§
- Batch
Store Ack - Per-hash acknowledgement for a
BatchStoreRequest(ADR 022 §STORE Flow).results[i]corresponds toBatchStoreRequest.entries[i]. - Batch
Store Request - Batched publication of multiple content records from one holder to one
receiver (ADR 022 §STORE Flow). A bandwidth optimization over
nseparateStoreRequests: the re-publish scheduler groups due hashes by receiver and sends each its set in one of these. Admission and two-stage rate-limit accounting live in thedecdn-nodehandler. - Closer
Nodes - A bounded list of the K closest
NodeIds a responder returns in acloser_nodesfield (ADR 022 §Routing Table). WrapsVec<NodeId>and enforces theMAX_CLOSER_NODESinvariant at construction — bothCloserNodes::try_newand the boundedDeserializeimpl reject oversize lists, so an over-capcloser_nodescannot exist in memory or on the wire.#[repr(transparent)]+#[serde(transparent)]keep the encoding byte-identical to a bareVec<NodeId>. - Closer
Nodes Error - Error returned by
CloserNodes::try_newwhen the list exceedsMAX_CLOSER_NODES. - Find
Node Request - Kademlia node lookup — used during routing-table bootstrap and bucket
refresh (ADR 022 §Bootstrap, §Routing Table). Distinct from
FindValueRequestin that the target is aNodeId, not a content hash, and no provider lookup is performed. - Find
Node Response - Response to a
FindNodeRequest(ADR 022 §Message Types). - Find
Value Request - Query for providers of a specific content hash (ADR 022 §Message Types).
- Find
Value Response - Response to a
FindValueRequest(ADR 022 §Message Types). - Find
Value Response Ext - Optional
FindValueResponseextension fields, carried as trailing bytes after the message via the two-phase pattern (ADR 013 §Tier 1; seeencode_find_value_response/parse_find_value_response_ext). - Provider
- A known holder of a content hash, plus which
Coverageblocks it reports being able to serve (range-keyed discovery). Carried inFindValueResponse::providers. - Store
Ack - Acknowledgement for a
StoreRequest(ADR 022 §Message Types). - Store
Request - Publish a content record: “I hold this hash” (ADR 022 §Message Types,
§STORE Flow). Sent by the holder to each of the K+3 nodes closest to
hashin keyspace. - Store
Request Ext - Optional
StoreRequestextension fields, carried as trailing bytes after the message via the two-phase pattern (ADR 013 §Tier 1; seeencode_store_request/parse_store_request_ext).
Enums§
- DhtMessage
- Top-level protocol enum for
cdn/dht/v1. Variant order matches ADR 022 §Message Types and is frozen per ADR 013.
Constants§
- MAX_
BATCH_ STORE_ HASHES - Wire-level maximum number of hashes a
BatchStoreRequestmay carry (ADR 022 §STORE Flow — “Batch size is bounded at 256 hashes”). Applies symmetrically toBatchStoreAck::results(one bool per request hash, same cap so a malicious responder can’t reply with an oversize ack). Enforced at the wire boundary; ADR 022 spells out that oversize batches close the stream withMALFORMED_MESSAGE(0x03) — the decode-time reject here surfaces as that error code via the framing layer. - MAX_
CLOSER_ NODES - Wire-level maximum number of
NodeIds in acloser_nodesfield, equal to the Kademlia bucket size K=20 (ADR 022 §Routing Table). Applies to bothFindValueResponse::closer_nodesandFindNodeResponse::closer_nodes. Enforced by theCloserNodestype — at construction (CloserNodes::try_new) and at the wire boundary (itsDeserialize). - MAX_
PROVIDERS_ PER_ HASH - Wire-level maximum number of providers a
FindValueResponsemay carry (ADR 022 §Content Records and TTL). Bounds the response size at the~2.3 KBceiling documented in ADR 022 §DHT Bandwidth Analysis.
Functions§
- encode_
find_ value_ response - Encode a
DhtMessage::FindValueResponsewith its optional trailingFindValueResponseExt(ADR 013 §Tier 1, two-phase). - encode_
store_ request - Encode a
DhtMessage::Storewith its optional trailingStoreRequestExt(ADR 013 §Tier 1, two-phase). Typed per variant, as above. - parse_
find_ value_ response_ ext - Parse the trailing
FindValueResponseExtbytes returned as the remainder bycrate::decode_messageafter aDhtMessage::FindValueResponse. - parse_
store_ request_ ext - Parse the trailing
StoreRequestExtbytes returned as the remainder bycrate::decode_messageafter aDhtMessage::Store.