-
-
Notifications
You must be signed in to change notification settings - Fork 107
Open
Labels
A-developer-xpArea: developer experienceArea: developer experienceA-networkingArea: Networking, ring protocol, peer discoveryArea: Networking, ring protocol, peer discoveryE-easyExperience needed to fix/implement: Easy / not muchExperience needed to fix/implement: Easy / not muchT-enhancementType: Improvement to existing functionalityType: Improvement to existing functionality
Description
Background
Part of #2164 (peer identity restructuring). The behavioral fixes for NAT traversal are complete in PRs #2167 and #2169, but the type system still has some redundancy.
Current State
We have overlapping types for identifying peers:
| Type | Contains | Purpose |
|---|---|---|
PeerId |
{addr: SocketAddr, pub_key: TransportPublicKey} |
Legacy bundle |
PeerKeyLocation |
{pub_key, peer_addr: PeerAddr, location} |
Combined info + location |
SocketAddr |
Network address | Routing |
TransportPublicKey |
Cryptographic key | Identity |
The Issue
PeerId bundles address and identity together, but:
- Identity (
pub_key) is immutable and unique - Address (
SocketAddr) can change (NAT, roaming)
This conflation was the root cause of NAT issues fixed in #2164. The behavioral fix is done (connection-based routing), but the type still exists and is used in ~256 places.
Proposed Cleanup
Option A: Make PeerId a type alias for TransportPublicKey
pub type PeerId = TransportPublicKey;- Use
PeerKeyLocationwhen you need both identity and address - ~137 compile errors to fix
Option B: Remove PeerId entirely
- Replace with
TransportPublicKeyfor identity - Replace with
SocketAddrfor address - Replace with
PeerKeyLocationfor combined - Similar effort to Option A
Scope
- ~256 usages across 20+ files
- Main files:
p2p_protoc.rs,connection_manager.rs,handshake.rs - Estimated: 2-3 hours of mechanical refactoring
Priority
Low - the behavioral fixes are complete and tested. This is purely type system hygiene.
Related
- Depends on: refactor(routing): add upstream_addr for connection-based routing #2167, refactor(connect): remove from/sender fields from ConnectMsg #2169 (should be merged first)
- Part of: refactor: Restructure peer identity and address handling #2164
[AI-assisted - Claude]
Metadata
Metadata
Assignees
Labels
A-developer-xpArea: developer experienceArea: developer experienceA-networkingArea: Networking, ring protocol, peer discoveryArea: Networking, ring protocol, peer discoveryE-easyExperience needed to fix/implement: Easy / not muchExperience needed to fix/implement: Easy / not muchT-enhancementType: Improvement to existing functionalityType: Improvement to existing functionality
Type
Projects
Status
Triage