Skip to content
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

Fix windows libp2p #29

Merged
merged 2 commits into from
Aug 7, 2022
Merged

Conversation

cpuchip
Copy link

@cpuchip cpuchip commented Jul 27, 2022

Adding to @davidflowerday's PR I've made this platform specific so windows/others uses SetMulticastInterface and linux/darwin uses ControlMessage, I've also updated server.go to include a fix for this problem as well.

I was having issues getting this library to even work on windows, only mDNS services I registered on localhost would show up in my browse/lookup requests, after digging in I found @davidflowerday's PR and a few other comments on other forks.

I've tests this fix on Windows and and linux (WSL) and both seem to be in good shape, I can resolve and register mDNS service both on and off box and see them. I do not have a mac ( Intel or Arm ) to test this on unfortunately.

from @davidflowerday's PR:
I'm attempting to use go-chromecast on Windows which leverages this library. Unfortunately, mDNS wasn't working. I was able to fix it by replacing the code that used ControlMessage in WriteTo() with a call to SetMulticastInterface() instead. I think this may be related to issues grandcat#54 grandcat#69 and grandcat#75. I've tested this change on Windows and Linux and I will test on macOS shortly as well. I only changed client.go but it's possible a similar change is needed in server.go as well.

In the docs for the ipv4 package under Bugs there is this note:

On Windows, the ControlMessage for ReadFrom and WriteTo methods of PacketConn is not implemented.

I've also submitted this as a PR to the upstream grandcat/zerconf though I'm less hopeful it'll be accepted there. Your fork here seems to be more active! which is why I also submitted it here.

Additionally, the ipv4 docs on Multicasting here show an example using SetMulticastInterface() as I've done in this PR which suggests to me that this is an OK way to handle this issue, but if you'd prefer something else I'd be happy to change it.

Thanks for making zeroconf and for considering this PR.

var wcm ipv4.ControlMessage
for ifi := range c.ifaces {
wcm.IfIndex = c.ifaces[ifi].Index
switch runtime.GOOS {
case "darwin", "ios", "linux":

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this special-casing darwin, ios and linux, and not windows?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I was looking at all the examples of using SetMulticastInterface I saw this example on Google's own Golang docs
https://pkg.go.dev/golang.org/x/net/ipv4#example-RawConn-AdvertisingOSPFHello

I believe it comes down to ControlMessage only being implemented on linux/iOS/darwin mac based platforms and none others. It didn't make sense to specifically call out windows. See https://pkg.go.dev/golang.org/x/net/ipv4#PacketConn.WriteTo

@BigLep BigLep linked an issue Aug 5, 2022 that may be closed by this pull request
Copy link

@marten-seemann marten-seemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look wrong to me. I'd feel more comfortable if we had better test cases for this, but unfortunately, this is really hard to test.

@marten-seemann marten-seemann merged commit 586e7c5 into libp2p:master Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Browse and Register do not work past localhost on Windows 10/11
3 participants