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

Unable to use QUIC Transport with SwarmBuilder #3179

Closed
Firaenix opened this issue Nov 30, 2022 · 7 comments · Fixed by #4120
Closed

Unable to use QUIC Transport with SwarmBuilder #3179

Firaenix opened this issue Nov 30, 2022 · 7 comments · Fixed by #4120

Comments

@Firaenix
Copy link

Summary

Following the example at https://docs.rs/libp2p/latest/libp2p/quic/index.html, I tried to use the QUIC transport to create a Swarm object. However
Example code:
image

Expected behaviour

I would expect the quic::Connection struct (Which implements StreamMuxer) to be boxed up and accepted as a transport for the SwarmBuilder parameter.

Actual behaviour

I get the following compile-time error:
image

Version

libp2p 0.50

@thomaseizinger
Copy link
Contributor

For the time being, you need to box up the Connection object yourself. See the tests on how to:

fn create_transport<P: Provider>() -> (PeerId, Boxed<(PeerId, StreamMuxerBox)>) {
let keypair = generate_tls_keypair();
let peer_id = keypair.public().to_peer_id();
let transport = quic::GenTransport::<P>::new(quic::Config::new(&keypair))
.map(|(p, c), _| (p, StreamMuxerBox::new(c)))
.boxed();
(peer_id, transport)
}

@Firaenix
Copy link
Author

Firaenix commented Dec 2, 2022

Great! Thats very helpful, thank you. I was wondering if there was something like that.

@thomaseizinger
Copy link
Contributor

I think we should rework the API of Swarm to do the boxing internally so this is not necessary.

@thomaseizinger thomaseizinger added priority:nicetohave decision-pending Marks issues where a decision is pending before we can move forward. labels Dec 12, 2022
@thomaseizinger
Copy link
Contributor

Related #3186. Adding a T: Transport type parameter and doing the boxing internally would solve this issue but creates a lot of type parameter and trait bound noise because we have SwarmBuilder and Swarm today. We should streamline the creation of a Swarm first to minimise the impact of this type parameter change.

@libp2p/rust-libp2p-maintainers Thoughts?

@mxinden
Copy link
Member

mxinden commented Dec 14, 2022

No opinion here. Doing the boxing in Swarm or SwarmBuilder sounds fine to me.

@thomaseizinger
Copy link
Contributor

Using QUIC and WebRTC together with other transports is a bit clunky at the moment:

https://github.com/libp2p/test-plans/blob/c916d4b247d40d20fee995ea070779365426814a/ping/rust/src/bin/testplan_0510.rs#L24-L40

@thomaseizinger
Copy link
Contributor

With #3588 merged, there is now only a single place to (SwarmBuilder) where we are accepting a transport::Boxed. I'd like to see if we can solve this issue by accepting a T: Transport instead, therefore doing the boxing internally and allow every Transport to be passed to SwarmBuilder.

@thomaseizinger thomaseizinger added help wanted difficulty:moderate and removed decision-pending Marks issues where a decision is pending before we can move forward. labels Mar 20, 2023
@mergify mergify bot closed this as completed in #4120 Oct 10, 2023
mergify bot pushed a commit that referenced this issue Oct 10, 2023
Introduce the new `libp2p::SwarmBuilder`. Users should use the new `libp2p::SwarmBuilder` instead of the now deprecated `libp2p::swarm::SwarmBuilder`. See `libp2p::SwarmBuilder` docs on how to use the new builder.

Fixes #3657.
Fixes #3563.
Fixes #3179.

Pull-Request: #4120.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants