@@ -336,7 +336,12 @@ more Peer IDs providing the corresponding content. Instead of storing the
336336content itself, the DHT stores provider records pointing to the peers hosting
337337the content.
338338
339- A Provider Record is identified by the multihash contained by the CID.
339+ A Provider Record is identified by the multihash contained by the CID. It
340+ functions as an append-only list, where multiple providers can add themselves
341+ as content hosts. Since strict consistency across the network is not required,
342+ different DHT servers MAY store slightly different sets of providers, but the
343+ lookup mechanism ensures that clients can still discover multiple sources
344+ efficiently.
340345
341346### Content Kademlia Identifier
342347
@@ -398,22 +403,97 @@ for the Client
398403### Content Provider Lookup
399404
400405To find providers for a given CID, a node initiates a lookup using the
401- GET_PROVIDERS RPC. This process follows the same approach as a FIND_NODE
406+ ` GET_PROVIDERS ` RPC. This process follows the same approach as a ` FIND_NODE `
402407lookup, but with one key difference: if a DHT server holds a matching provider
403408record, it MUST include it in the response.
404409
405410Clients MAY terminate the lookup early if they are satisfied with the returned
406411providers. If a node does not find any provider records and is unable to
407- discover closer DHT servers after querying the β closest reachable servers, the
408- request is considered a failure.
412+ discover closer DHT servers after querying the ` β ` closest reachable servers,
413+ the request is considered a failure.
409414
410- ## DHT Record Storage
415+ ## Value Storage and Retrieval
416+
417+ The IPFS Kademlia DHT allows users to store and retrieve records directly
418+ within the DHT. These records serve as key-value mappings, where the key and
419+ value are defined as arrays of bytes. Each record belongs to a specific
420+ keyspace, which defines its type and structure.
421+
422+ The IPFS Kademlia DHT supports two types of records, each stored in its own
423+ keyspace:
424+
425+ 1 . ** Public Key Records** (` /pk/ ` ) – Used to store public keys that cannot be
426+ derived from Peer IDs.
427+ 2 . ** IPNS Records** (` /ipns/ ` ) – Used for decentralized naming and content
428+ resolution.
429+
430+ Records MUST meet validity criteria specific to their record type before being
431+ stored or updated. DHT Servers MUST verify the validity of each record before
432+ accepting it.
433+
434+ ### Routing
435+
436+ The Kademlia Identifier of a record is derived by applying the SHA256 hash
437+ function to the record’s key and using the resulting digest in binary format.
438+
439+ To store a value in the DHT, a client first finds the ` k ` closest peers to the
440+ record’s Kademlia Identifier using ` GetClosestPeers ` . The client then sends a
441+ ` PUT_VALUE ` RPC to each of these peers, including the ` key ` and the ` record ` .
442+ DHT servers MUST validate the record based on its type before accepting it.
443+
444+ Retrieving values from the DHT follows a process similar to provider record
445+ lookups. Clients send a ` GET_VALUE ` RPC, which directs the search toward the
446+ ` k ` closest nodes to the target ` key ` . If a DHT Server holds a matching
447+ ` record ` , it MUST include it in its response. The conditions for terminating
448+ the lookup depend on the specific record type.
449+
450+ ### Public Keys
451+
452+ Some public keys are too large to be embedded within libp2p Peer IDs ([ keys
453+ larger than 42
454+ bytes] ( https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#peer-ids ) ).
455+ In such cases, the Peer ID is derived from the hash of the public key, but the
456+ full key still needs to be accessible. To facilitate retrieval, public keys MAY
457+ be stored directly in the DHT under the ` /pk/ ` keyspace.
458+
459+ 1 . Key: ` /pk/<PeerID> ` (binary Peer ID format).
460+ 2 . Value: The full public key (in binary format).
461+
462+ #### Validation
463+
464+ DHT servers MUST verify that the Peer ID derived from the full public key
465+ matches the Peer ID encoded in the key. If the derived Peer ID does not match,
466+ the record MUST be rejected.
411467
412468### IPNS
413469
414- ### Resiliency
470+ IPNS (InterPlanetary Naming System) allows peers to publish mutable records
471+ that point to content in IPFS. These records MAY be stored in the DHT under the
472+ ` /ipns/ ` namespace.
473+
474+ Record format and validation is documented in the [ IPNS
475+ specification] ( https://specs.ipfs.tech/ipns/ipns-record/ ) . IPNS records are
476+ limited in size to
477+ [ 10KiB] ( (https://specs.ipfs.tech/ipns/ipns-record/#record-size-limit) ) .
478+
479+ #### Quorum
415480
416- ### Validators
481+ A quorum is the minimum number of distinct responses a client must collect from
482+ DHT Servers to determine a valid result. Since different DHT Servers may store
483+ different versions of an IPNS record, a client fetches the record from multiple
484+ DHT Servers to increase the likelihood of retrieving the most recent version.
485+
486+ For IPNS lookups, the default quorum value is ` 16 ` , meaning the client attempts
487+ to collect responses from at least ` 16 ` DHT Servers out of ` 20 ` before
488+ determining the best available record.
489+
490+ #### Entry Correction
491+
492+ Because some DHT servers may store outdated versions of a record, clients need
493+ to ensure that the latest valid version is propagated. After obtaining a
494+ quorum, the client MUST send the most recent valid record to any of the ` k `
495+ closest DHT Servers to the record’s Kademlia Identifier that did not return the
496+ latest version.
417497
418498## RPC Messages
419499
@@ -571,6 +651,8 @@ Make a `FIND_NODE` request and inspect response before adding node to RT. Follow
571651* JS: [ libp2p/kad-dht] ( https://github.com/libp2p/js-libp2p/tree/main/packages/kad-dht )
572652* Rust: [ libp2p-kad] ( https://github.com/libp2p/rust-libp2p/tree/master/protocols/kad )
573653
654+ ---
655+
574656## References
575657
576658[ 0] : Maymounkov, P., & Mazières, D. (2002). Kademlia: A Peer-to-Peer Information System Based on the XOR Metric. In P. Druschel, F. Kaashoek, & A. Rowstron (Eds.), Peer-to-Peer Systems (pp. 53–65). Berlin, Heidelberg: Springer Berlin Heidelberg. [ DOI] ( https://doi.org/10.1007/3-540-45748-8_5 ) [ pdf] ( https://www.scs.stanford.edu/~dm/home/papers/kpos.pdf )
0 commit comments