libp2p / go-libp2p-examples

Example libp2p applications
MIT License
339 stars 145 forks source link

Chat with mdns does not work on different devices #62

Closed JackBekket closed 5 years ago

JackBekket commented 5 years ago

Can't start a chat on a two different devices in one local network (wi-fi)

They are not see each other

first device is linux, second is windows

JackBekket commented 5 years ago

Has tested on my home WLAN, if I try to test between two different devices ubuntu-ubuntu - it works perfect

However, it's not working if I try to connect between ubuntu-windows

I'm not sure yet, that it could be OS related, or firewall related, but it doesn't work out of the box so far

JackBekket commented 5 years ago

Has tried on different windows devices

1 - seem's like it's not even finding peers in network

2 - found a peer, but fail with connection, says

"stream open failed dial backoff"

both of it windows 10

JackBekket commented 5 years ago

Probably I need to build .exe file with some specific parameters?

yusefnapora commented 5 years ago

Hey @JackBekket, it sounds like when you run the example on Windows, you're never able to connect to peers? Are Windows peers able to connect to each other?

If it's possible for you to temporarily disable your firewall for testing, you could try to see if that's a factor. You can also add the compiled example's .exe file to the firewall whitelist instead of turning the whole thing off.

yusefnapora commented 5 years ago

Meanwhile, I'll try to run the examples on Windows and see what I encounter :)

JackBekket commented 5 years ago

Now just have tried to open example on Windows and Linux machines

Program on windows device didn't said anything, it's looks like it doesn't even try to find any peers

Program on linux machine succesfully find windows peer, but it seem's it can't connect to windows machine

Connection failed: dial attempt failed: <peer.ID Qm*LSfUPD> --> <peer.ID Qm*7CJv5P> dial attempt failed: dial tcp4 169.254.59.123:4001: i/o timeout
Stream open failed dial backoff
yusefnapora commented 5 years ago

I was just able to reproduce this at home. The example when running on Windows never seems to discover other nodes.

I did see that the mDNS record was published:

Screen Shot 2019-05-23 at 2 47 08 PM

The meetme entry at the bottom was published from the Windows machine. And when I run the example on my Mac, I can discover the mDNS entry, but then I get a failure as well:

$ ./chat-with-mdns
[*] Listening on: 0.0.0.0 with port: 4001

[*] Your Multiaddress Is: /ip4/0.0.0.0/tcp/4001/p2p/QmNUAZFGofVCUEhMkJ18hSPQ6oKT66UMnBFag6kZNZG9jV
Found peer: {<peer.ID Qm*GzgR8w> [/ip4/127.0.0.1/tcp/4002]} , connecting
Connection failed: dial attempt failed: <peer.ID Qm*NZG9jV> --> <peer.ID Qm*GzgR8w> dial attempt failed: dial tcp4 127.0.0.1:4002: connect: connection refused
Stream open failed dial backoff

This line stands out:

Found peer: {<peer.ID Qm*GzgR8w> [/ip4/127.0.0.1/tcp/4002]} , connecting

The peer id is from the Windows node, but the multiaddr is for the loopback interface (127.0.0.1).

This makes me suspect that on Windows, the mDNS record is getting published with the loopback address instead of the correct IP.

Aha! As I was writing this up, I noticed that the example has a -host flag, where you can set the listen address explicitly. If I set the flag to the IP address of my Windows machine like this:

.\chat-with-mdns.exe -host 10.0.1.18

Then I can find it from my Mac and connect.

@JackBekket will you try setting the -host flag to your IP address on the Windows box and see if that helps? If so, we still need to investigate why it's publishing the unusable addresses, but at least we'll know what's going on.

JackBekket commented 5 years ago

@yusefnapora It seems you were right, it helped!

also, I have successfully ported mdns to an android device, and it surprisingly works well!