I'm currently working on a project that requires NAT traversal but I seem to be running into difficulty. I have the following setup running for testing:
- R1, Verizon Fios router connected to the internet.
- R2, Belkin router connected on it's WAN port to the switch of R1 via ethernet.
- i, The introductory server, connected via ethernet to R1. R1 forwards port 6666 to i.
- A and B, computers running client software that are connected to R2 over Wifi.
Intro Server and Client Description:
When A and B start their client, the client sends a "HelloPacket" to the external address of R1 (72.82.59.10) on port 6666.
Upon receiving a HelloPacket, the server first checks if it has seen the source address and source port identifier before.
- If not, it first sends each entry in it's table of peer identifiers (source ip/port) to the peer it received the HelloPacket from, and then stores this as a new entry in it's peer table.
- If it has, then it resets the peers timeout so that it knows to keep sending this peers identifier to peers that connect in the future.
After the client initially sends the HelloPacket to the Intro server it can expect to receive packets called IntroPackets from the server if there are peers that have already introduced themselves to the server. These IntroPackets contain both the external and internal ip/port of a peer.
Now that the peer knows of existing peers, it is the newly connected peer's responsibility to send a HelloPacket to the existing peers to let them know of it's existence. This is where I'm having trouble.
I don't have enough reputation to post images but here's a diagram I made in paint of the setup: https://i.stack.imgur.com/7E5I8.png
Here is the order of events and the problem I am running into:
- The intro server is started and listening for UDP packets of type "HelloPacket"
- Peer A starts it's client which in turn sends a HelloPacket to the Intro server at address/port: 72.82.59.10, 6666
- The intro server receives the HelloPacket and adds an entry to it's table and does not send any IntroPackets to peer A as there are no other peers in it's table. The entry in the table resembles the following for Peer A: IP: 72.82.59.10, Port: 1024
- Peer B starts it's client which in turn sends a HelloPacket to the intro server.
- The intro server receives the HelloPacket and adds an entry to it's table. The intro server then sends an IntroPacket to the newly connected peer that contains peer A's address and port. The intro server's table looks like the following at this point:
Peer A: 72.82.59.10, 1024
Peer B: 72.82.59.10, 1025
- Peer B receives the IntroPacket and then attempts to send a hello packet to peer A.
Step 6 is where my design is failing. Peer A never receives the HelloPacket from peer B. It is my understanding that when the router receives a packet with a destination port of 1024 that it will map that to the internal address and port using it's NAT. Is this correct?
I've tried running an external program that just sends datagrams to the external address and port mapped to client A but these to do not seem to be getting through so I don't think it's a timeout issue.
I also know that I should attempt to connect to the internal address and port to see if the clients are behind the same NAT and plan to implement this in the future.
Also, all communication is done reliably using Go-Back-N in both the client and server code.
Questions:
- Am I overlooking something crucial in my design or just not simply understanding NAT traversal with UDP?
- For what reasons would Peer A be able to receive a packet from the server but not Peer B? (As peers are able to receive packets back from the server)
- Does the NAT take the source address into consideration?
Any input is much appreciated!! Thanks!