libp2p / libp2p/rust-libp2p

core: Remove `Transport::{Dial,ListenUpgrade}` in favor of using trait objects

Open
#3,347 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

difficulty:moderate help wanted priority:nicetohave
Dominant language
Rust
Stars
5.6k
Forks
1.3k
Avg merge
8h 47m
Merged PRs (30d)
19

Description

Context

Whilst toying around with https://github.com/libp2p/rust-libp2p/issues/2650 which was motivated by trying to solve the merge conflicts in https://github.com/libp2p/rust-libp2p/pull/3254, I came across our EitherFuture type. This one exists because the trait bounds on Transport::Dial and Transport::ListenUpgrade force the designated type to "transpose" the output. In other words, with Either implementing Transport, the output of Dial is required to be Result<Either<A, B>, ...> instead of Either<Result<A, ..>, Result<B, ..>>. This makes sense but is not compatible with a general implementation of Future on a type like Either. Thus, we need to provide our own, specialized type for this.

Proposal

Should we remove the associated types Dial and ListenUpgrade in favor of always using BoxFuture?

Benefits

  • Less code to maintain
  • Simplified interface
  • Smaller public API of Transport implementations

Drawbacks

  • Forces all Transports to be Send
  • More allocations as part of creating new network connections

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the Transport trait, its Dial and ListenUpgrade associated types, and the EitherFuture type described in the issue. Trace the affected Transport implementations and determine whether replacing those associated types with BoxFuture preserves the stated behavior and addresses the listed trade-offs; done means the proposal is implemented consistently across the public API.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.