Kademlia DHT: Implementation Status and Gaps. #1075
Replies: 1 comment
-
|
Thank you so much with all of the progress on py-libp2p. There are 3 features that I'm looking add to the to-do list and help work on and conceptualize Required ValidatorCurrently, records are only validated if the key is prepended with py-libp2p/libp2p/kad_dht/kad_dht.py Line 778 in e7dde5e What I'm proposing is we do one of the following:
Record Subkey, Expiration Date, and
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
This report analyzes the current state of the Kademlia DHT implementation in py-libp2p by comparing it against the official libp2p Kademlia DHT specification.
Report Date: November 30, 2025
Repository: libp2p/py-libp2p
Executive Summary
1. Core Parameters & Definitions
✅ Fully Implemented
k)BUCKET_SIZE = 20)common.pyα)ALPHA = 3)MAXIMUM_BUCKETS = 256)QUERY_TIMEOUT = 10)α = 10, but py-libp2p usesα = 3. This may result in slower lookups but lower network overhead.2. DHT Operations
2.1 Peer Routing (FIND_NODE)
PeerRouting.find_closest_peers_network()MAX_PEER_LOOKUP_ROUNDS = 20Status: ✅ Fully Implemented
2.2 Value Storage (
PUT_VALUE)KadDHT.put_value()ValueStore.put()NamespacedValidatorDEFAULT_TTL = 24 hoursStatus: ✅ Fully Implemented
2.3 Value Retrieval (
GET_VALUE)ValueStorebefore networkQimplementationNamespacedValidator.validate()Select()Validator.select()interface existsStatus:⚠️ Partially Implemented - Missing quorum support and entry correction
2.4 Content Provider Advertisement (
ADD_PROVIDER)find_closest_peers_network()ProviderStore.provide()provider_id != peer_idProviderStore.add_provider()PROVIDER_RECORD_REPUBLISH_INTERVAL = 22 * 60 * 60PROVIDER_RECORD_EXPIRATION_INTERVAL = 48 * 60 * 60PROVIDER_ADDRESS_TTL = 30 * 60Status: ✅ Fully Implemented
2.5 Content Provider Discovery (
GET_PROVIDERS)ProviderStorefirstProviderStore.find_providers()closerPeerswhen no providers foundStatus: ✅ Fully Implemented
2.6 Bootstrap Process
KadDHT.run()starts refreshROUTING_TABLE_REFRESH_INTERVAL = 60(1 min for testing)RTRefreshManagerexists but only for non-empty bucketsrefresh_routing_table()looks up own IDQUERY_TIMEOUTStatus:⚠️ Partially Implemented - Spec recommends 10-minute refresh; implementation uses 1 minute
3. RPC Messages (Protobuf)
3.1 Message Format
varint.encode()/decode()kademlia_pb2.pygenerated from.proto3.2 Message Types
FIND_NODE (4)GET_VALUE (1)PUT_VALUE (0)GET_PROVIDERS (3)ADD_PROVIDER (2)PING (5)3.3 Protobuf Schema Comparison
Spec Fields:
py-libp2p Implementation: ✅ Matches spec with additions for signed peer records
Record.keyRecord.valueRecord.timeReceivedMessage.typeMessage.keyMessage.recordMessage.closerPeersMessage.providerPeersMessage.clusterLevelRawPeer.signedRecordMessage.senderRecordStatus: ✅ Fully Compatible - Includes spec-compliant extensions for signed peer records
4. Routing Table
4.1 K-Bucket Implementation
KBucketclass with ordered peersOrderedDictwith timestampsbucket_size = BUCKET_SIZE_ping_peer()called before evictionKBucket.split()and_split_bucket()4.2 Routing Table Management
find_local_closest_peers()add_peer(),remove_peer()PeerInfowith addressesget_stale_peers()with threshold_periodic_peer_refresh()MAXIMUM_BUCKETS = 256Status:⚠️ Partially Implemented - Uses simplified range-based bucket selection
5. Client and Server Mode
DHTMode.CLIENT,DHTMode.SERVERhandle_stream()only processes if SERVERswitch_mode()methodStatus:⚠️ Partially Implemented - Missing remote peer mode detection
6. Entry Validation
ValidatorinterfaceValidatorbase classValidator.validate()methodValidator.select()methodNamespacedValidatorpk) validatorPublicKeyValidatorclassput_value()callsvalidate()Status:⚠️ Partially Implemented - Missing IPNS validator
7. Protocol Identification
/ipfs/kad/1.0.0PROTOCOL_ID = TProtocol("/ipfs/kad/1.0.0")/ipfsPROTOCOL_PREFIX = TProtocol("/ipfs")host.set_stream_handler(PROTOCOL_ID, ...)8. Signed Peer Records
senderRecordandsignedRecordfieldsmaybe_consume_signed_record()consume_peer_record()with TTLenv_to_send_in_RPC()helperStatus: ✅ Fully Implemented
9. Missing Features Summary
🔴 Critical Missing Features
Quorum Support for Value Retrieval
Qfor value consistencyEntry Correction
Remote Peer Mode Detection
IPNS Validator
🟡 Minor Missing/Different Features
Alpha Parameter Value
α = 10, Implementation:α = 3Routing Table Refresh Interval
XOR-Trie Based Routing
10. Implementation Quality
Strengths
kad_dht.py,routing_table.py,peer_routing.py,value_store.py,provider_store.py)triofor concurrencyAreas for Improvement
ALPHAconfigurable11. Recommendations
High Priority
Implement Quorum Support
Add Entry Correction
Implement IPNS Validator
Medium Priority
Remote Peer Mode Detection
/ipfs/kad/1.0.0via IdentifyConfigurable Parameters
Low Priority
12. Compatibility Matrix
Conclusion
The py-libp2p Kademlia DHT implementation covers approximately 75-80% of the specification. The core DHT operations (peer routing, value storage/retrieval, provider management) are functional and wire-compatible with other libp2p implementations.
Key gaps to address:
These gaps primarily affect advanced use cases and IPFS-specific functionality. For basic DHT operations and peer discovery, the current implementation is production-ready.
Report generated by analyzing py-libp2p source code against libp2p/specs/kad-dht specification
Beta Was this translation helpful? Give feedback.
All reactions