NAT punch server based on LiteNetLib for TugBoat/Fishnet use. Example command line client included for experimentation and testing.
Clients identify as either a game host or a game client and present a token/key that identifies the game they want to join. The Facillitator introduces them to the server for that game and visa versa and the library punches the holes for p2p. This does not require either the game server or the game clients to be free of NAT or port forwarded.
Implementing: STUN/TURN/ICE, but without the TURN fallback for now. Future plans are to encorporate UPNP and create a relay server for TURN as well and add fallback with a ICE moderator.
Done: Create a standalone NAT Punchthrough Facillitator/Server based on LiteNetLibDone: Create a client for testingDone: Manually test multiple game servers and clients.multiple clients and session keyspass traffic to test punchthrough
Implement UPnPadd multiple services to daemon ( nat puch, facillitator, my ip service)- (in progress) Faccilitator ICE (up to relay step)
- (in progress) Create a Unity project that uses this library
- Create Automated Tests against the punchthrough server that:
- Test multiple clients
- Test multiple session keys
- validate traffic can pass
- Detect Symetrical NAT and warn - punt to relay directly
- (investigating) Create a client library that aligns with the TugBoat transport
- (investigation) embed this in TugBoat
The repo is organized as a Solution, with multiple projects. It should import into any C# IDE without a problem. The LiteNetLib and Mono.NAT projects are added as a source submodule due to differing platform compile flags and ensuring the right version.
-
After you have cloned the repo you will want to do the following commands in the root of the project to pull in the LiteNetLib.
git fetch; git submodule init; git submodule update
-
Please .gitignore your IDE poop if you plan on submitting a merge request
-
Build however you like building
dotnet build
from the project root works just fine
-
Run the Facillitator either in your IDE or via command line
cd NATPunchFacillitator
dotnet run NATPunchFacillitator -- <serverPort> <serverAddress>
- or run with defaults:
dotnet run
-
Run the client either in your idea or via command line
- you must run at least two clients with the same token, one in client mode the other in game server mode, to see the punchthrough conversation happen
- command line
dotnet run NATPunchClient -- <gameToken> <server|client> <optional:serverPort> <optional:serverAddress>
- defaults are in the code and may change, run without arguments for defaults
- The arguements are optionsl, but you must include the arguements in the stated order
Setting up a multiple NAT network test environment using VirtualBox, Ubuntu Server and pfSense (router software).
You can set up multiple VirtualBox VMs in linux host / firewall pairs and run your Faccilitator on your regular host to similate things. You can then make connections from the clients on each of the virtualbox guests behind their NAT router to that facilitator.
Note you can do this with Parallels or VMWare as well, I've tested with Parallels and have switched over to it from virtualbox because it's faster and more stable (but not free). If you use parallels you will likely not be able to installed pfSense until you tell the bootloader to use efi (do the opposite of these instructions to disable EFI - ie enable efi by useing 'vm.bios.efi=1' in the bios boot flag section of boot order config in the vm ).
Decent Guide to setting up NAT Networks using VirtualBox
How I do it with VirtualBox (free):
- use ubuntu linux server and the command line mode for the clients for testing.
- create n number of Internal Networks with different network ip blocks
- create a base disk image with dotnet and base vm to clone
- clone the git project and compile
- note: probably best to clone it from your dev machine directly using ssh, so you don't have to push all the incremental changes during testing to the master then pull from there. but.. you do you.
- clone the base vm using linked n times.
- assign a different Internal Network to each of the vms
- Create n number of pfsense community edition (free) vms using the same 'create a base, then linked clones of it' technique.
- place the LAN interface of the pfsense on one of the private networks and the second WAN interface in bridged mode ( this will assign a independant ip address on your network, which is required for accurate testing.
- Important pfSense is a Symetrical NAT router by default, but it can be configured to not be. Do so, unless you are testing symetrical nat detection.
- run tests manually from command line on each of the vms as needed.
- https://github.com/RevenantX/LiteNetLib/blob/master/LibSample/HolePunchServerTest.cs
- https://anyconnect.com/stun-turn-ice/
- https://mirror-networking.gitbook.io/docs/transports/litenetlib-transport
- https://www.atmosera.com/blog/creating-a-daemon-with-net-core-part-1/
- https://dev.to/deagahelio/getting-started-with-litenetlib-2fok
- https://github.com/falahati/WindowsFirewallHelper