Skip to content

refactor: Simplify peer identity types (PeerId cleanup) #2170

@sanity

Description

@sanity

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 PeerKeyLocation when you need both identity and address
  • ~137 compile errors to fix

Option B: Remove PeerId entirely

  • Replace with TransportPublicKey for identity
  • Replace with SocketAddr for address
  • Replace with PeerKeyLocation for 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

[AI-assisted - Claude]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-developer-xpArea: developer experienceA-networkingArea: Networking, ring protocol, peer discoveryE-easyExperience needed to fix/implement: Easy / not muchT-enhancementType: Improvement to existing functionality

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions