libp2p / go-libp2p-examples

Example libp2p applications
MIT License
339 stars 145 forks source link

chat-with-rendezvous connection error #70

Open cfvescovo opened 5 years ago

cfvescovo commented 5 years ago

Hi, I fired up a simple-bootstrap-node on a server of mine. Then a friend of mine in another city and I compiled chat-with-rendezvous as described and ran it (./chat -peer <string/from/bootstrap/node> -rendezvous testing). Our consoles connect successfully to the bootstrap-node and print "Announcing ourselves" and then we get either nothing (literally nothing) or some warnings (they find each other but can't connect).

cfvescovo commented 5 years ago

@lbordino (the friend)

cfvescovo commented 5 years ago

@bigs Any suggestion?

bigs commented 5 years ago

@BaldEagleX02 Are either of you behind NAT? If so, you won't be able to get a connection between the two of you. I'd recommend passing in an explicit listen address, enabling port-forwarding in your router, and trying again. Keep in mind that DHT-based discovery can take some time to kick in. You'll know you've successfully found each other when you see a print message from this line.

cfvescovo commented 5 years ago

I modified the log level to debug and then I saw that we discovered each other (after the program printed "Searching for peers..." I saw "Found another peer" or something similar). We aren't behind NAT as we have static public IPs from our provider. We tried with ports opened but it didn't work. We haven't tried with the listen option yet.

cfvescovo commented 5 years ago

@bigs However I hope that this library works with NAT too, as it handles hole-punching (#4)

cfvescovo commented 5 years ago

It works with UPnP (A client behind NAT and B client with static IP and UPnP). However, it doesn't work with both clients behind NAT and/or ports closed

bigs commented 5 years ago

Given the configuration of that specific example, you'll have to set the listen option to reflect your public IP and an accessible port. Another approach would be to enable port mapping via the NATPortMap option in the call to libp2p.New.

Edit: To clarify, since your libp2p node doesn't know that it's publicly dialable, it won't publish any addresses to the rendezvous point.

cfvescovo commented 4 years ago

Yeah, in fact this example works very well with UPnP enabled (router and program) but if I am behind NAT (e.g. a mobile connection) I don't know any accessible port. I have to use hole punching to know at least one and I was wondering if it will be implemented in this library. Obviously it would require a server. Take a look at this example: https://github.com/wilfreddenton/udp-hole-punching It seems very well structured and, as its name suggests, implements hole punching.

Thank you for your support!