haskell-distributed / network-transport-tcp

TCP Realisation of Network.Transport
http://haskell-distributed.github.com
BSD 3-Clause "New" or "Revised" License
30 stars 27 forks source link

Unaddressable transports/endpoints (behind NAT, for instance) #61

Closed avieth closed 7 years ago

avieth commented 7 years ago

This makes it feasible to run a transport on a machine that isn't addressable from the network in which its peers live. Endpoints on this transport can connect to the addressable peers, but the peers can only connect to that endpoint if there's already a socket opened. Endpoints on the same unaddressable transport cannot connect to each-other, even though it's technically possible.

Unaddressable endpoints are given (random) UUIDv4 addresses. When an addressable endpoint receives a connection from an unaddressable peer, it generates one to identify that peer locally (highly unlikely that any other peer would make sense of that address). This is the address found on the ConnectionOpened event.

The connection request protocol (for the socket, not for lightweight connections) is changed: sending a 0-length address (just the length-prefix 0x00000000) means no address is coming. Anything else will be read and parsed to an EndPointAddress. This is backwards compatible assuming empty ByteString is not a valid EndPointAddress.

avieth commented 7 years ago

Rebased, ready for another review.

facundominguez commented 7 years ago

LGTM It has some conflicts.

avieth commented 7 years ago

@facundominguez Conflicts resolved. I squashed everything and then threw on one more commit implementing the simplification that you pointed out.

avieth commented 7 years ago

One test failed. I think this patch fixes it https://github.com/haskell-distributed/network-transport-tests/pull/13 let me know if you agree.

facundominguez commented 7 years ago

Thanks @avieth!