Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(swarm)!: don't be generic over Transport #3272

Merged
merged 7 commits into from
Dec 23, 2022

Conversation

thomaseizinger
Copy link
Contributor

Description

Ever since we moved Pool into libp2p-swarm, we always use it with the same Transport: Boxed. It is thus unnecessary for us to be overly generic over what kind of Transport we are using. This allows us to remove a few type parameters from the implementation which overall simplifies things.

This is technically a breaking change because I am removing a type parameter from two exported type aliases:

  • PendingInboundConnectionError
  • PendingOutboundConnectionError

Those have always only be used with std::io::Error in our API but it is still a breaking change.

Notes

Discovered as part of working on #2824.

Links to any relevant issues

Open Questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

swarm/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM seems like a nice simplification, thanks Thomas!

@@ -79,9 +79,8 @@ impl ExecSwitch {
}

/// A connection `Pool` manages a set of connections for each peer.
pub struct Pool<THandler, TTrans>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think of making this pub (crate) instead? I know that it doesn't change anything as pool is not public but it helps visually understand that the type is shared across the crate (as opposed to just being private, which it can't be). pool is also pub (crate).
(this suggestion also applies to PoolEvent)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I think I'd prefer to not use pub(crate) but I could be convinced otherwise.

It would be nice if we can assume that:

  • All modules are private
  • pub types therefore don't leak into the public API
  • pub(crate) is therefore a workaround because rhe module isn't private for some reason

I am not fully convinced it is a good idea though, might cause a lot of complexity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish Rust had a way to whitelist what is in the public API of a crate and fail to compile if something is being added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we decide that every pub type follows the convention used in #3238 we could use pub (crate) only inside the the crate itself to distinguish from the actually pub types on the main lib.rs for example, one issue with the assumptions above for example is that we have pub mod but in the end no strong opinion, I can understand your POV as well and share the same frustrations.

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in favor of this change.

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Leaving this open for the above discussion by @jxs.

@thomaseizinger
Copy link
Contributor Author

thomaseizinger commented Dec 22, 2022

Looks good to me. Leaving this open for the above discussion by @jxs.

In case you both don't mind, I am sending this to master so work on #3254 can continue. Let's keep the discussion going though! :)

@mergify mergify bot merged commit 5782a96 into master Dec 23, 2022
@thomaseizinger thomaseizinger deleted the 2824-no-generic-transport-pool branch February 24, 2023 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants