-
Notifications
You must be signed in to change notification settings - Fork 964
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
{core,swarm}/: Don't require Transport: Clone
and take &mut
#2529
Conversation
Previously `libp2p-swarm` required a `Transport` to be `Clone`. Methods on `Transport`, e.g. `Transport::dial` would take ownership, requiring e.g. a `Clone::clone` before calling `Transport::dial`. The requirement of `Transport` to be `Clone` is no longer needed in `libp2p-swarm`. E.g. concurrent dialing can be done without a clone per dial. This commit removes the requirement of `Clone` for `Transport` in `libp2p-swarm`. As a follow-up methods on `Transport` no longer take ownership, but instead a mutable reference (`&mut self`). On the one hand this simplifies `libp2p-swarm`, on the other it simplifies implementations of `Transport`.
Transport: Clone
and take &mut
I am assuming, based on your reaction, that this would simplify https://github.com/wngr/libp2p-webrtc as well, correct @wngr? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
I like the idea. Also liking the idea of a polling a Transport. Always found it weird that we use a different abstraction here than in the rest of the codebase.
If we end up polling, I think connections created from listen_on
and dial
should be reported by poll
.
Actually I already managed to overcome this restriction. But thanks =) |
At least a little bit, yes. More importantly, it will reduce a cognitive dissonance for me (How many transports are there?). |
This is ready for a review. Any comments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Are you planning to expose a poll
interface from the Transport
later?
transports/websocket/src/lib.rs
Outdated
// T: Transport + Send + 'static, | ||
// T::Output: AsyncRead + AsyncWrite + Unpin + Send + 'static, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete these?
Changelog entry seems to be missing :) |
Yes. That would be my follow up proposal, namely to remove the concept of
I will have to experiment with this. I am not yet sure how much benefit it would be to emit the dial I argue that the change proposed in this pull request is a step forward, whether we do the above follow-up or not. |
Nice, looking forward to that :)
In my latest experiments, I ended up having to delegate to the same code from dial as for each element of the listener stream. More generally, I see it as one of the benefits of libp2p (as a result of multiplexing) that the endpoint (dialer/listener) matters less for the application and thus allows for a more generalized handling of all connections. Cases where you need exactly the connection that the dial future resolves to should be rather rare IMO.
Yep, on board with that! |
…2p#2529) Previously `libp2p-swarm` required a `Transport` to be `Clone`. Methods on `Transport`, e.g. `Transport::dial` would take ownership, requiring e.g. a `Clone::clone` before calling `Transport::dial`. The requirement of `Transport` to be `Clone` is no longer needed in `libp2p-swarm`. E.g. concurrent dialing can be done without a clone per dial. This commit removes the requirement of `Clone` for `Transport` in `libp2p-swarm`. As a follow-up methods on `Transport` no longer take ownership, but instead a mutable reference (`&mut self`). On the one hand this simplifies `libp2p-swarm`, on the other it simplifies implementations of `Transport`.
Previously
libp2p-swarm
required aTransport
to beClone
. Methodson
Transport
, e.g.Transport::dial
would take ownership, requiringe.g. a
Clone::clone
before callingTransport::dial
.The requirement of
Transport
to beClone
is no longer needed inlibp2p-swarm
. E.g. concurrent dialing can be done without a clone perdial.
This commit removes the requirement of
Clone
forTransport
inlibp2p-swarm
. As a follow-up methods onTransport
no longer takeownership, but instead a mutable reference (
&mut self
).On the one hand this simplifies
libp2p-swarm
, on the other itsimplifies implementations of
Transport
.I hope this will significantly simplify #2289. Testing it out next.
As a follow-up we could as well remove the concept of listeners, thus
poll
ing aTransport
instead of aListener
returned byTransport::listen_on
. Still need to give this idea more thought.//CC @kpp