-
Notifications
You must be signed in to change notification settings - Fork 189
Description
Description
This tracking issue covers multiple enhancements across the libp2p stack to improve how peers connect, route through relays, and discover each other. The goal is to make the networking layer more resilient, especially in NATed or firewalled environments, while improving correctness and modularity.
Scope includes:
- Secure relay reservation and maintenance
- Voucher and signature validation
- Smarter relay selection algorithms
- Proper handling of relayed
/p2p-circuitmultiaddrs - DHT-based peer discovery integration
- Accurate peer metadata including relay multiaddrs
Each task listed below will be tracked via sub-issues and pull requests. Contributors can reference this issue in their PRs using Closes #<this-issue> where appropriate.
Motivation
The primary motivation behind this work is to evolve py-libp2p into a production-grade library, capable of supporting real-world deployments in decentralized applications, research networks, and production systems.
This direction has been discussed and aligned with @paul (and others), and reflects the need for:
- Stability and correctness under real-world network conditions
- Parity with go-libp2p / js-libp2p in key features
- Support for multi-hop, relayed, and NATed connectivity
- A modular, extensible architecture for experimentation and new protocols
To reach this production-ready state, several key features must be implemented, hardened, and tested:
- Reliable relay support – with reservation refresh, multiaddr correctness, and flexible selection logic
- Secure resource validation – with voucher and signature verification to guard access and allocation
- Dynamic peer discovery – using the DHT to locate peers in disconnected or semi-connected topologies
- Proper address handling – including encoding/decoding of relayed multiaddrs, and updating peer metadata
These enhancements not only improve developer and user experience but also unblock downstream use cases such as:
- Building permissionless P2P networks in constrained environments
- Research and prototyping of new p2p protocols in Python
Requirements
📋 TODOs
-
Implement voucher and signature verification in
resources.py
Validate incoming relay vouchers and signatures to ensure proper authorization and prevent misuse. -
Implement initial relay selection logic in
transport.py
Use basic selection (e.g., first-available or round-robin) to choose a relay when dialing. -
Implement DHT-based peer discovery
Use the libp2p DHT to dynamically locate and connect to peers across the network. -
Implement more sophisticated relay selection
Introduce scoring, latency-based metrics, or retry strategies for better relay routing. -
Implement reservation storage and refresh mechanism
Track active relay reservations and refresh them before expiry to support long-lived relayed connections. -
Add relay multiaddrs to peerstore
Store/p2p-circuit/...addresses in the peer metadata to support reconnects and discovery. -
Implement proper multiaddr parsing and handling for relayed connections
Ensure/p2p-circuit/p2p/...paths are correctly parsed, validated, and used during dialing. -
Implement run() method in CircuitV2Listener
Finalize the listener logic to support incoming relayed connections.
Are you planning to do it yourself in a pull request ?
Maybe