-
Notifications
You must be signed in to change notification settings - Fork 957
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
Adds support for handling interface changes to mdns behaviour. #1830
Conversation
62ce8d4
to
014ea9e
Compare
Updated ip-watch to work on windows too and tested that it handles changing networks. |
28adc9a
to
e015f6d
Compare
e015f6d
to
b7f33f6
Compare
Just noticed an issue, it returns routes on linux but interfaces on windows. Looks like @Demi-Marie intended to query routes? Unless there is a reason for that, I'll change the linux implementation of |
2938a06
to
36c997c
Compare
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.
Just noticed an issue, it returns routes on linux but interfaces on windows. Looks like @Demi-Marie intended to query routes? Unless there is a reason for that, I'll change the linux implementation of if-watch to query ip's. This means that the prefix is 32 on linux and the network prefix on windows.
Since I'm neither familiar with the details of ip-watch
nor if-watch
, could you elaborate on the observed difference and the changes you made? I'm generally just assuming that these libraries "do the right thing" for the purpose of network interface monitoring as desired for MDNS.
protocols/mdns/src/service.rs
Outdated
} | ||
if let IpAddr::V4(addr) = inet.addr() { | ||
log::trace!("leaving multicast on iface {}", addr); | ||
if let Err(err) = socket.leave_multicast_v4(&multicast, &addr) { |
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.
As mentioned in an earlier comment, I think it would be good to get clarity on whether doing this on an interface that is down makes any sense. If this is just a no-op in this situation, there is no reason to do it and if it is an error it causes unnecessary noise in the logs. If you're sure that doing this on an interface that is down is useful and only errors when there is an error other than the interface being down, I'm fine with it.
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.
Well it doesn't cause an error on linux or windows. I'll try to investigate more deeply especially on linux, but we are supporting any platform that rust compiles to I guess.
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'll try to investigate more deeply especially on linux, [..]
Just curious, did you come to a conclusion on the matter?
@mxinden If you could also take a quick look at these changes, since you've worked on this code before, it would be much appreciated. |
They do the right thing now. I switched the rtnetlink code to use |
Thanks for the link. There are some things about the implementation of
This is the first time I'm looking at |
It only needs to
EDIT: you're right, the correct thing to do is send an |
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.
The direct changes in this pull request look good to me. Thanks for making libp2p-mdns
more robust. On the side I am very much in favor of getting rid of the async-std/tokio macros.
I want to highlight once more that this switches libp2p-mdns
from previously using either tokio or async-std to async-io
wrapping an std udp socket. In case there is anyone objecting to this change, please raise your concerns here.
I still have to take a deeper look at the introduced if-watch
dependency.
Some maintainance stuff that might be good to do before merging is replacing the old net2 crate with socket2 as used in the tcp transport and remove the wasm-time dependency in favor of async-io, as mdns doesn't run in browsers anyway. |
Well |
The diff itself looks good to me, but as @mxinden said, even if we don't have dedicated tests or CI checks for it at the moment, in principle rust-libp2p certainly has the ambition to support MacOS, hence including a library that is known to lack support is not really an option. Whenever we get tickets here that rust-libp2p does not compile for some platform, especially when it is as common as MacOS, we necessarily need to look into it. Without access to the right system for testing (I don't have or use MacOS either) we still need to make a best-effort and deal with issues in collaboration with users that do use these platforms as they come up. So we need an approach here (via |
Fixed in 0.1.6, now has a fallback that polls in 10s intervals. Also has ci that tests on linux/windows/macos and builds on android/ios |
@dvc94ch You don't need to keep this branch mergeable, e.g. by merging master and resolving conflicts. We typically resolve conflicts and update versions and changelogs just before, respectively after merging the PR, after approval. The only thing that is advisable is to eventually stop rebasing / force-pushing to PR branches, in order not to cause unnecessary problems when we want to make final adjustments to the branch before merging. |
@mxinden Thanks for your feedback. I intend to merge and probably release a new version of |
any thoughts on the tcp pr so far? I didn't find a good way to spawn the if_task in an executor agnostik way, the |
I didn't get a chance to look at it yet in any detail but intend to do so by next week. |
Thanks @dvc94ch ! Looks really awesome, especially that we react to interface changes. One thing that struck me when skimming through the changes: Just joining the multicast group on all interfaces is enough to make sure, messages go out on each interface?! I mean it kinda makes sense, but my research indicated otherwise. Anyhow, I really like that PR! |
Can you elaborate on what your research indicates is required? It has worked for me on linux and windows using the following test procedure:
I don't know about multiple interfaces |
I see, different use case! In my case I really had multiple interfaces at the same time and according to some man page (would have to dig that one up again), when binding via multicast address or 0.0.0.0 you start receiving on all interfaces, but outgoing messages will be transmitted to the default interface (which is usually the one with the default gw with the highest priority) - in any case that matched my experience as well so far. I will retry with your implementation and will report any issues :-) |
In any case one can change the outgoing interface, so in my implementation I just iterated over all interfaces, changed the outgoing interface to the current one and sent out the message on each one. |
Actually memory served me wrong. There is a platform specific call for sending, which allows specifying the interface that should be used. |
so it doesn't work? can you open a PR for it, I assume the changes should be pretty small now? |
Well, considering that you have not tested that particular case, I am pretty sure it won't, but I will test it and will provide a PR if that assumption is correct. The changes should be rather minimal. The only issue is that it depends on platform specific functionality, so this complicates matters. MacOS might be fine, but I have no idea about Windows. |
My devices only have a wifi adapter. I can help test that it doesn't break anything. Feel free to cc me on the PR. |
Thanks @dvc94ch ! |
Currently the mdns behaviour will panic if no adapter is available. To test on linux use the following commands:
Depends on paritytech/ip-watch#1cc @Demi-Marie @rklaehn