Skip to content

refactor: handle transient connections at type level #2115

@sanity

Description

@sanity

Background

PR #2105 introduced transient connection tracking for gateways using runtime validation. This works but could be made safer and less error-prone using Rust's type system.

Proposal

As suggested by @iduartgomez in #2105 (comment):

I think we can handle transient connections at the type level and that would make all this stuff safer and less error prone, but that will require some further changes/refactoring so will do that in a separate PR in the future

Current Implementation

Transient connections are tracked via:

  • Runtime checks in ConnectionManager::register_transient()
  • Manual budget tracking with RwLock<DashMap<PeerId, TransientEntry>>
  • TTL expiration checked at registration time

Type-Level Approach

Use Rust's type system to enforce transient connection constraints at compile time:

  • Separate connection types (e.g., Connection<Permanent> vs Connection<Transient>)
  • Type-safe budget management
  • Compile-time guarantees about connection lifecycle

References

[AI-assisted - Claude]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-networkingArea: Networking, ring protocol, peer discoveryE-hardExperience needed to fix/implement: Hard / a lotS-needs-designStatus: Needs architectural design or RFCT-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