-
Notifications
You must be signed in to change notification settings - Fork 190
Description
Description
What I'm proposing is we either force all DHT records to be put through the namespace validator, or create a bool variable such as strict_namespace_validator when initializing the KadDHT where if it's true, all records, put and get, will be validated no matter the format.
Motivation
For some networks, the ability to validate all records is essential. Many applications require strict control over which keys may be stored, whether for security, correctness, or protocol-level rules. If unvalidated keys can bypass custom logic, peers may end up storing arbitrary or malformed data that violates the network’s intended behavior.
By supporting validation for every record, implementations can:
- Enforce permissioned keyspaces: Nodes can reject keys outside the allowed schema, key logic, or namespace.
- Improve security: Prevent accidental or malicious insertion of unexpected data.
- Ensure protocol correctness: Peers can enforce application-specific invariants (e.g., commit–reveal flows, unique key patterns, signed records).
- Align closer with go-libp2p and rust-libp2p behavior (I believe)
Current Implementation
In the current implementation in put_value in kad_dht.py, the validator logic only triggers when a record has a "/" prepended to the record key.
Here's the line in question:
py-libp2p/libp2p/kad_dht/kad_dht.py
Line 772 in 0039e60
| if key.decode("utf-8").startswith("/"): |
Are you planning to do it yourself in a pull request ?
Maybe