helium / erlang-libp2p

An Erlang implementation of libp2p swarms
https://helium.github.io/erlang-libp2p
Apache License 2.0
120 stars 33 forks source link

Investigate TCP hole punching with SO_REUSEADDR #26

Closed Vagabond closed 6 years ago

Vagabond commented 6 years ago

The go implementation of libp2p uses REUSEADDR to do TCP hole punching as described here:

http://www.bford.info/pub/net/p2pnat/index.html

This allows you to dial and listen on the same port, which means that, potentially, inbound connections to the NAT on the external port will end up back at the listener.

I think the key thing to change would be to make sure the swarm sets {reuseaddr, true} on the TCP sockets and that a dial on the swarm sets the {port, Port} option to the same port as the listener for the swarm is bound to. This should be a relatively simple change but, combined with STUN, should allow for more NAT traversals than simply relying on nat-upnp.

madninja commented 6 years ago

Fixed with #31