-
Notifications
You must be signed in to change notification settings - Fork 961
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
transports/tcp: simplify IfWatcher integration #2813
Conversation
With if-watch `2.0.0` `IfWatcher::new` is not async anymore, hence the `IfWatch` wrapping logic is obsolete.
- In case of `InAddr::One` we can use `self.listen_addr`. - In case of `InAddr::Any` we can use `IfWatcher::iter`.
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.
This looks like a really cool simplification!
This seems fine to me. |
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.
This is a really great improvement!
I've added some stylistic comments.
I've only just noticed now. I think that is a good idea! |
Note: I've edited your description so we don't actually close libp2p/if-watch#21 with merging this. |
@elenaf9 let me know if you want me to take another look here. |
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.
Great improvement!
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.
Looks good to me.
Have you tested this pull request with both tokio
and async-std
as a runtime using a wildcard IP address?
If yes, this is ready to merge from my end.
let listener: TcpListener = socket.into(); | ||
let local_addr = listener.local_addr()?; | ||
|
||
if local_addr.ip().is_unspecified() { |
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.
shouldn't we check if port is unspecified too?
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.
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.
an unspecified port results in a single randomly chosen port.
Well, I am not sure what the OS does when it can not find a unique port number that is free on all interfaces. I am guessing that it will choose a different port number per interface. Though still only one per interface.
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.
That was my first thought as well. But while an unspecified IP results in one IP per (potentially future) interface, an unspecified port results in a single randomly chosen port.
Yes exactly.
Yes, though on my local machine (linux). But our CI also tests both runtimes in the tcp test, which includes tests with wildcard addresses. But those tests only test the tcp transport directly and not within a swarm. |
I think this is fine as is. Thanks. |
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.
Thanks for thinking this all the way through!
See corresponding change in tcp transport: libp2p#2813.
CI failure is unrelated. #2869 released v0.48.0. Thus this pull request updates the version to v0.49.0. Problem is, that https://github.com/libp2p/test-plans still operates with v0.48.0. As far as I can tell this is a chicken-and-egg problem. We can't merge with a green CI here as the Testground tests are failing. We can not merge a patch to libp2p/test-plans as the version of libp2p/rust-libp2p is not yet bumped to v0.49.0. I don't think this is a big issue. Will need to think about how to solve it long term. //CC @laurentsenta in case you have an idea. I will merge here. I will create a pull request against libp2p/test-plans next. |
See release of v0.48.0 in libp2p/rust-libp2p#2869. Master bump to v0.49.0 in libp2p/rust-libp2p#2813
See release of v0.48.0 in libp2p/rust-libp2p#2869. Master bump to v0.49.0 in libp2p/rust-libp2p#2813
See release of v0.48.0 in libp2p/rust-libp2p#2869. Master bump to v0.49.0 in libp2p/rust-libp2p#2813
See release of v0.48.0 in libp2p/rust-libp2p#2869. Master bump to v0.49.0 in libp2p/rust-libp2p#2813
Description
Update to
if-watch
versionv2.0.0
, which allows us to simplify our integration in the tcp transport quite a bit:IfWatcher::new
is not async anymore we do not need theIfWatch
wrapper and related logic anymoreif_watch::IfWatcher
for both runtimes. According to this discussion, this should be ok now: transports/quic: Add implementation based onquinn-proto
#2289 (comment).However, I just saw now that for
cfg(not(any(target_os = "ios", target_os = "linux", target_os = "macos", target_os = "windows")))
if-watch
still usesasync-io
. Given that this won't apply for the vast majority of users I'd say this is acceptable. Alternative is to do feature request: expose tokio vs async-global-executor feature flags if-watch#21 before continuing here.InAddr
and instead manage theIfWatcher
directly in theTcpListenStream
. In case ofInAddr::One
directly push anTransportEvent::NewAddress
into our event queue when creating the listener.Related discussions: #2289 (comment).
Open Questions
We could removeInAddr
completely and in case ofInAddr::One
just directly push anTransportEvent::NewAddress
into our event queue when creating the listener. See elenaf9@c4f2124. But not sure if that really simplifies things. I guess for other transports that don't have whole port-reuse logic this might make more sense.Edit: Done now in 64a3165.
Change checklist