20070708 - Breaking Firewalls
If the world ran only on static IPs with no firewalls, doing P2P connections would be easy.
Now when was anything worthwhile easy? Connecting the rest of the world requires breaking through firewalls and dealing with dynamic IP addresses.
- End point = 6 bytes.
- Public end point is what server sees as ip:port for client.
- Private end point is what client sees as ip:port for self.
- All clients connect to server and server responds with public end point.
- So all clients know their public end point.
- Clients also give private end point to server.
- NATs might mangle private end point in UDP packet so encript it.
Here is how S (server or peer) can connect A (peer) to B (peer). This works both on local LAN and across the wide open internet with NAT and firewalls.
- A is connected with S.
- B is connected with S.
- S sends private and public end points of A to B.
- S sends private and public end points of B to A.
- A sends packets to private and public end points of B.
- B sends packets to private and public end points of A.
- A locks in ip:port it sees from B.
- B locks in ip:port it sees from A.
Keep in mind that NAT (network address translation) might result in a different public end point on each connection attempt,
so during steps 5 and 6, they might have to IP/port scan by attempting multiple public end points seeded from the public end point sent in steps 3 and 4.