feat(transport): allow ListenerId to be user-controlled#3567
feat(transport): allow ListenerId to be user-controlled#3567mergify[bot] merged 34 commits intolibp2p:masterfrom
ListenerId to be user-controlled#3567Conversation
|
Can you run rustfmt? I'll have a look at the code over the next days. It is a breaking change so we'll likely hold off a bit on merging that to reduce the rate of breaking changes. |
Agree with that. |
thomaseizinger
left a comment
There was a problem hiding this comment.
I am in favor of this but it is a breaking change so we can't merge it immediately.
|
Test failure should go away once you update to latest master. |
This comment was marked as resolved.
This comment was marked as resolved.
thomaseizinger
left a comment
There was a problem hiding this comment.
I'd like to move away from random ListenerIds and instead use the same pattern we used for ConnectionIds: a static atomic counter.
core/src/transport.rs
Outdated
| pub use self::optional::OptionalTransport; | ||
| pub use self::upgrade::Upgrade; | ||
|
|
||
| static NEXT_LISTENER_ID: AtomicU64 = AtomicU64::new(1); |
There was a problem hiding this comment.
Should we change this to AtomicUsize and use usize in ListenerId instead?
There was a problem hiding this comment.
I don't think it really matters, happy to leave it as a u64. What do you think?
There was a problem hiding this comment.
I think we can leave it
There was a problem hiding this comment.
Adding to the above the argument of portability.
PowerPC and MIPS platforms with 32-bit pointers do not have AtomicU64 or AtomicI64 types.
https://doc.rust-lang.org/std/sync/atomic/index.html#portability
Thus slight preference for AtomicUsize from my end. Also consistent with ConnectionId.
ListenerId to be user-controlled
|
Looking forward to this! I updated the PR description to reflect why we are doing this. Once the remaining comments are resolved, I'd also like @mxinden to have a look at this although I do think we are in agreement here. |
thomaseizinger
left a comment
There was a problem hiding this comment.
LGTM, thanks for the effort!
I would like @mxinden to also review this.
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
|
This pull request has merge conflicts. Could you please resolve them @dariusc93? 🙏 |
mxinden
left a comment
There was a problem hiding this comment.
Minor comments. This is good to go from my end. Thank you for the work @dariusc93!
core/src/transport.rs
Outdated
| pub use self::optional::OptionalTransport; | ||
| pub use self::upgrade::Upgrade; | ||
|
|
||
| static NEXT_LISTENER_ID: AtomicU64 = AtomicU64::new(1); |
There was a problem hiding this comment.
Adding to the above the argument of portability.
PowerPC and MIPS platforms with 32-bit pointers do not have AtomicU64 or AtomicI64 types.
https://doc.rust-lang.org/std/sync/atomic/index.html#portability
Thus slight preference for AtomicUsize from my end. Also consistent with ConnectionId.
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Max Inden <mail@max-inden.de>
Approvals have been dismissed because the PR was updated after the send-it label was applied.
Description
Transport::listen_onis an asynchronous operation. It returns immediately but the actual process of establishing a listening socket happens as part ofTransport::pollwhich will return one or moreTransportEvents related to a particularlisten_oncall.Currently,
listen_onreturns aListenerIdwhich allows the user of theTransportinterface to correlate the events with a particularlisten_oncall. This "user" is theSwarmruntime. Currently, a user of libp2p establishes a new listening socket by talking to theSwarm::listen_oninterface and it is not possible to do the same thing via theNetworkBehaviourtrait.Within the
NetworkBehaviourtrait, we emit commands to theSwarmlikeToSwarm::Dial. These commands don't have a "return value" like a synchronous function does and thus, if we were to add aToSwarm::ListenOncommand, it could not receive theListenerIdfrom theTransport.To fix this and to be consistent with our coding guidelines we change the interface of
Transport::listen_onto require the user to pass in aListenerId. This will allow us to construct a command in aNetworkBehaviourthat remembers this ID which enables precise tracking of which events containing aListenerIdcorrelate which a particularlisten_oncommand.This is especially important in the context of listening on wildcard addresses like
0.0.0.0because we end up binding to multiple network interfaces and thus emit multiple events for a singlelisten_oncall.Notes
Links to any relevant issues
Open Questions
Transport::listen_onreturn aListenerId? This PR doesnt have it return it since its redundant now, but not sure if anybody else feel the same way.Change checklist