Tuesday, October 26, 2021

Trying to implement TCP Hole Punching / NAT Traversal

Hey! Does someone have any experience with networking (NAT Reversal / Hole Punching)? I've implemented UDP hole punching in Rust and went to the deep water with the TCP protocol, I've been trying for a couple of days without any sign of success, can someone who has experience in the matter give me some insight?

I'm not sure if it's an issue at the API level (since there are available implementations like the nat_traversal crate), but I seem to do everything by the book.

It goes like that:

• A connects to S

• B Connects to S

• S sends A and B the others public and private addresses + ports (respectively)

• While the client gets the other client's information it starts listening on the same port it used to connect to S

• Trying to connect to the other client

In general the client has 4 threads:

• Connection to S

• Listening for incoming connections (same port that connects to S)

• Connection to B's public endpoints

• Connection to B's private endpoints

I've went with rust for the implementation

It just doesn't work for me and I have no idea why, I've tried many different APIs, that's why the code may seem messy in that way

This is the code for both the server and the client: https://gist.github.com/TheOnlyArtz/c47b651a429301a12c47aeb9ae4253f2

The issue is essentially in the client, the server works as intended



No comments:

Post a Comment