feat(kad-dht): implement IPNS validator for DHT record validation#1161
Open
asmit27rai wants to merge 29 commits intolibp2p:mainfrom
Open
feat(kad-dht): implement IPNS validator for DHT record validation#1161asmit27rai wants to merge 29 commits intolibp2p:mainfrom
asmit27rai wants to merge 29 commits intolibp2p:mainfrom
Conversation
- Add IPNS protobuf definition (IpnsEntry message) - Implement IPNSValidator class following IPNS spec - Integrate IPNS validator with DHT (apply_fallbacks, validate_config) - Add cbor2 dependency for DAG-CBOR decoding - Add comprehensive tests (19 test cases) Closes libp2p#1157 Signed-off-by: asmit27rai <raiasmit10@gmail.com>
Contributor
|
@asmit27rai Please fix the CI CD issues. |
Contributor
|
@asmit27rai the lint ci nonetype errors are fixed, The pyrefly type checker wasn't properly narrowing the type of self.validator after the isinstance check, because instance attributes can theoretically be reassigned between the check and usage. So I Assigned self.validator to a local variable after the type guard. This helps the type checker understand that the local variable validator is definitively a NamespacedValidator and cannot be modified, allowing safe access to _validators. # Use a local variable to help type checker narrow the type
validator = self.validator
# Add missing default validators
if "pk" not in validator._validators:
validator._validators["pk"] = PublicKeyValidator()
if "ipns" not in validator._validators:
validator._validators["ipns"] = IPNSValidator()The last remaining ci check is not related to yours it is already addressed and I'm currently working on a fix for that, For more info read this discussion #1166 |
Contributor
Author
|
@sumanjeet0012 You can review it. |
…ces" This reverts commit ae34859.
- Add ParsedIPNSRecord dataclass for structured record inspection - Add ValidityType enum for type-safe validity type constants - Add configurable expiration checking (check_expiration parameter) - Add validate_with_details() method returning parsed record data - Add comprehensive CBOR structure validation: - Required field checks (Value, Validity, ValidityType, Sequence) - Type validation for all CBOR fields - Range checks for sequence and TTL (non-negative, uint64 max) - Empty value detection - RFC3339 timestamp format validation with regex - Value prefix warnings for non-standard paths - Improve error messages with more descriptive context - Add constants for CBOR field names to reduce typos - Extract _parse_rfc3339() helper for reusable timestamp parsing - Improve select() method with proper datetime comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implement IPNS (InterPlanetary Naming System) validator for the Kademlia DHT, enabling py-libp2p to validate IPNS records according to the IPNS Record Specification.
IPNS provides mutable pointers to content-addressed data, essential for interoperability with IPFS nodes using go-libp2p and js-libp2p.
Changes
New Files
libp2p/records/pb/ipns.proto- IPNS protobuf definitionlibp2p/records/pb/ipns_pb2.py- Generated protobuf codelibp2p/records/pb/__init__.py- Package exportslibp2p/records/ipns.py-IPNSValidatorclass implementationtests/core/records/test_ipns_validator.py- Comprehensive tests (19 cases)Modified Files
libp2p/kad_dht/kad_dht.py- DHT integrationpyproject.toml- Addedcbor2dependencyImplementation Details
IPNSValidator validates records per IPNS spec §5.3:
signatureV2anddataare presentpubKeyfield or inlined Ed25519 in IPNS name)dataas DAG-CBORpubkey.verify("ipns-signature:" + cbor_data, signatureV2)Validityexpiration (RFC3339 timestamp with nanosecond support)