Why use both public and private endpoints when establishing peer-to-peer sessions?

Started by
4 comments, last by Dave Weinstein 10 years, 11 months ago
I read about establishing peer-to-peer sessions but what I don't understand is why the clients should try to send using both the public and private endpoints. If A and B has the same public IP isn't it always best to use the private endpoints and otherwise always use the public endpoints?
Advertisement

Take a look at the following scenario:

client A at local network 192.168.1.1:8080

client B at same local network 192.168.1.2:8080

behind global NAT 2.2.2.2

and

server at global network 1.1.1.1:9000

now A and B send requests to server and getting the following public endpoint:

client A: 2.2.2.2:9000

client B: 2.2.2.2:9001

The problem is, if client A tries to contact client B by 2.2.2.2:9001 it would send a message through the router to itself, which will most likely not work. In this case it just needs to use its local (aka private) endpoint (192.168.1.2:8080) to contact it. Therefor you send requests to both, private (if behind the same NAT) and public (if behind other NAT).

I understand what you say. What I don't get is why A don't compare the public endpoints of A and B and if they have the same IP use the private endpoint to contact B, otherwise use the public endpoint to contact B.

Yes, it is totally possible, and sometimes preferrable, for A to talk to B using the private IP address. The main problem is establishing that A and B are, in fact, both on the same private network. If their public IP is the same, then that's a good clue.

In fact, certain NAT gateways don't support "hairpin NAT" -- if A tries to talk to B using the B public IP/port, the router just drops the packet, rather than properly forwarding and re--re-writing it. Thus, you may *have* to support the direct mode for these kinds of clients if you want a very robust NAT traversal solution.

enum Bool { True, False, FileNotFound };

why A don't compare the public endpoints of A and B and if they have the same IP use the private endpoint to contact B

The client do not know its own public endpoint, only the server know it. Either the server would check if two clients have the same public endpoint and send therefor only the private endpoint to the client, or the server sends the clients public endpoint to the client itself. But all this is more complex and very theoretically, just testing if one of the two possible endpoints works is more practically.

No, it's an excellent question. There is no reason to probe both, and given that internal networks share a common address space, I'd say it is bad form.

NAT tunneling is mediated by the Matchmaker anyway. Have each client report its internal IP address and port when it contacts the Matchmaker. When coordinating matches, if the external IP is the same, the Matchmaker returns the external IP/Port that it determined for the parties, otherwise it returns the internal version. No additional information is sent, and no duplicate connecting is needed.

This topic is closed to new replies.

Advertisement