since our game is p2p, one vs one game, we are planning to implement our game in a peer to peer manner wherein there is no central game server but instead the users will just host it on his phone and the challenger will just connect to his him thru sockets.
There will be a central database to handle stats, authentication, etc. (implemented thru firebase).
more or less looks like this
So here are the flow in a nutshell.
1. when user logs in to the game, his IP address will be logged in the firebase database.
2. the user is presented with a list of users online to challenge. when use clicks on a player, the user issues a challenge.
when the challenged player accepts the challenge, the user connects to him directly.
Now, my issue.
This works if both or all users are in the same network since their IP will be unique, but if say for example, we are playing across internet,
there is a chance that 1 or two users will have the same IP (when using public IP) when two players are in the same network (ex: office wifi)
Situation 1:
both user1 and user2 uses mobile data, both of them has public IP (no issue)
Situation 2:
user1 uses mobile data, user2 uses office wifi, user2 shared the same public IP to his officemate.
user1 and user2 play against each other with no issue, but what happen if,
say user3 who shares the same wifi with user2 also wants to connect and challenge somebody in the game,
he uses the same IP address therefore there is an issue if we somebody needs to connect to that IP address since two users share the same public IP.
Also, to help the discussion we are using native (linux) sockets in C++ in both iOS and Android.
Any tips on how to handle this? How does applications working with peer to peer handle this?