Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement server types and P2P connection helper #123

Merged
merged 37 commits into from
Feb 9, 2024

Conversation

trippyone
Copy link
Contributor

@trippyone trippyone commented Jan 10, 2024

  • Implemented server types to allow a match host to use relay (websocket on 6970) or P2P (UDP on 6972) networking. This configuration is defined in com.sit.core.cfg and and transmitted to the coop match instance.

  • Implemented NatPunchHelper which is just a relay server to communicate public end points and nat punch requests.

  • NAT punching uses a public endpoint created by a STUN query. This is necessary because the backend server might be on the same network as the match host and therefore we can't get a public endpoint locally.

  • Removed all configs related to IPs in com.sit.core.cfg. The server will listen on all adapters including ipv6.

From now on, three ports will need to be forwarded on the backend server host: 6969, 6970 and 6971. 6972 needs to be forwarded on the match host instead because of P2P networking. If forwarding is not possible, NAT punching will be attempted to establish connection.

TODO:

  • Add upnp mapping
  • Implement upnp requests in P2P Helper
  • Logic to attempt nat traversal, upnp or direct port forwarding connection before giving up.
  • Add security to the p2p helper

- Implemented server types to allow a match host to use relay (websocket on 6970) or P2P (UDP on 6972) networking. This configuration is defined in coopConfig.json and transmitted to the coop match instance.

- Implemented a P2P Connection Helper to allow for NAT punching and UPNP mapping. This only applies to P2P networking. The P2P Helper is communicating with the backend server using websocket on port 6971, configurable in coopConfig.json.

- NAT punching uses a public endpoint created by a STUN query. This is necessary because the backend server might be on the same network as the match host and therefore we can't get a public endpoint locally.

- Removed all configs related to IPs and ports in com.sit.core.cfg. The ports are now configured in coopConfig.json and the server will listen on all adapters.

From now on, three ports will need to be forwarded on the backend server host: 6969, 6970 and 6971. 6972 needs to be forwarded on the match host instead because of P2P networking. If forwarding is not possible, NAT punching will be attempted to establish connection.

TODO:
- Add upnp mapping
- Implement upnp requests in P2P Helper
- Logic to attempt nat traversal, upnp or direct port forwarding connection before giving up.
- Add security to the p2p helper
Copy link

trippyone and others added 28 commits January 10, 2024 16:36
- Removed configs from coopConfig.json.
- Added configs back to com.sit.core.cfg.
- Adjusted logic to use the config from com.sit.core.cfg.
- Made the Nat punching process streamlined between GameClientUDP/GameServerUDP
- Refactored some of the code
- Server connection info now lives in the CoopGame instance.
- Using /coop/server/connectionInfo route to set and get server connection info.
- P2PConnectionHelper is now NatPunchHelper and is only used to perform nat punching.
- Refactoring of the code to make other nat traversal processes easier to implement.
- Removed STUN nuget package and added the references in the project to get rid of the DLL
- Added Open.NAT references
- Changed configs to add ServerType, NatTraversalMethod and added enums for them
- Added UPNP mapping in GameServerUDP

What is left to do:

- Support the enums properly when sending to server and back to clients
- Test nat punch and upnp and make sure we can connect
- Code refactoring
As the title says.

What is left to do:

- Change the configs to actual UI settings for the host (server type, server nat. Ip and port will be automatically generated)
- Manage local connection for routers which doesn't support hairpin.
- Keep nat punch/upnp connection alive until a client joins.
- Test a lot to ensure every single scenario works properly (relay, p2p and different nat traversal methods).
- NatPunchHelper is now NatHelper
- NatHelper now uses json to provide information between client and server.
- NatHelper is a class that creates different nat traversal methods and communicate it between server and clients. Requires port 6971 to be port forwarded by the server. It is now the main process in providing connection to server for clients.
- The client will request different endpoints from the server and attempt to connect to them all. First one that succeeds will be the one used by the client. It might generate connection errors during that process. Getting around that would be quite complex so I consider that on a low priority for now.
- Some refactoring and improvements

Notes
- Still need to define ServerType on the UI when hosting to avoid needing to set the value in com.sit.core.cfg.
- Further testing is required to ensure this process works for most people.
- Only do STUN (nat punching) if UPNP failed
- Added "remote" endpoint which NatHelper will replace with the local or external IP of the host. This is done using the NatHelper's socket information when host sends a packet to NatHelper.
- Added a check to disconnect if we connected more than once. This happens if more than one endpoint is reached.
- Cleaned up the code a bit and improved the logic.
This reverts commit 1675b79.
paulov-t and others added 8 commits February 2, 2024 16:21
- Removed P2P port from config. Relay is still in config.
- Added port in host game UI (p2p only).
- Send port to coop match (CreateMatch)
- Receive port from coop match (JoinMatch)
- Logic improvements to connection handling in GameClientUDP
- Added broadcast packet for local connection
- Some refactoring in Nat Helper to use IPEndPoint instead of strings
@paulov-t paulov-t merged commit 07293ee into master Feb 9, 2024
1 check passed
@paulov-t paulov-t deleted the server-config-and-p2p-helper branch March 11, 2024 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants