-
Notifications
You must be signed in to change notification settings - Fork 961
Use if-watch instead of local_ip_address
#8662
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
base: unstable
Are you sure you want to change the base?
Conversation
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.
Actually I think this doesn't work.
I think this uses if-addrs under the hood anyway:
https://github.com/libp2p/if-watch/blob/master/src/fallback.rs
| pub fn is_ipv6_supported() -> bool { | ||
| // If IPv6 is supported | ||
| let Ok(std::net::IpAddr::V6(local_ip)) = local_ipv6() else { | ||
| let Ok(watcher) = IfWatcher::new() else { |
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.
I think this is initialized empty and so we would have to force a resync somehow
|
Some required checks have failed. Could you please take a look @macladson? 🙏 |
ackintosh
left a comment
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 @macladson! It seems preferable to use if-addrs directly, since that's what if-watch uses under the hood.
I actually misunderstood the feature paths, it only uses |
|
Let me clarify: I guess the reason is that In our case, we simply want to get a list of network interfaces, so using |
still, if we can avoid another dependency and just use |
|
|
||
| // Ensure all addresses are added. | ||
| loop { | ||
| match watcher.poll_if_event(&mut ctx) { |
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.
So the code was panicking since tokio::IfWatcher requires a runtime. Adding this either to the function itself or piping in an existing runtime from elsewhere feels way overkill to me.
I have switched to smol::IfWatcher which doesn't need an existing runtime, and I think it technically works now. The downside is, the smol feature added a bunch of extra deps so it totally defeats the purpose of this change.
So with that in mind, I am heavily leaning in favour of the original PR with if-addrs (#8659).
Unless anyone has a cleaner solution that I missed?
Proposed Changes
This is an alternative to #8659 which just uses
if-watchwhich we already depend on transitively throughlibp2p.