I'm trying to realize a hybrid peer to peer network into practice.
While I do have theoretical knowledge about this matter, I lack
practical knowledge. The solutions I thought of all feel like hacks
to me, so I present this issue in order to receive feedback.
Consider the given network-model below:
We thus have a set of clients (Bob, Alice, Frank) and a Server singleton.
Assume that in the initial state, Server has no knowledge of the clients (their IP might chance),
while all the clients do know the Server's IP (as it is static). Further we assume
the usage of IPv4.
In order for arbitrary client to discover other clients a query must occur to the server. This is straight-forward.
For clients to be able to listen to eachother, a listening port is used, say 6700.
Now for the two problems, and the solutions I thought of:
1. Intra-subnet communication
Bob wants to communicate with Frank. As we are past the initialisation stage,
all clients know eachother's IP addresses. The listening ports are known aswel (6700).
(!!!)However as both clients are behind a router, NAT will most likely assign a different port.
How is this port of the NAT table discovered?
Since all clients perform a query to the main server, the main server will receive a structure with
ip-address and port to send a message back to. Assuming the client does not close the socket, this port will
always be available for receiving packets, even from other clients?
I am aware TCP uses sequence numbers, and the receiving client might expect a certain number and not accept
packets from other clients all together...
2. Inter-subnet communication
Bob wants to communicate with Alice. Assume the issues of (1) are resolved, and NAT maps Alice's listening port
of 6700 (internal) to 55555(external). Is Bob able to send a packet to 184.108.40.206:55555 and expect it to
arrive at Alice (assuming reliable packet transfer)?