Conversation
Coding-Hen
left a comment
There was a problem hiding this comment.
Would be nice to have some ipv6 support but I have some comments on the code below
Nitrox.Model/Helper/NetHelper.cs
Outdated
| } | ||
|
|
||
| if (ipv6Candidate == null | ||
| && address.AddressFamily == AddressFamily.InterNetworkV6 |
There was a problem hiding this comment.
You could also combine this if with the one above to reduce your code paths but it might be better to have them apart for readability
Nitrox.Model/Helper/NetHelper.cs
Outdated
| if (address.AddressFamily is AddressFamily.InterNetwork or AddressFamily.InterNetworkV6) | ||
| { | ||
| yield return (ip.Address, ni.Name.Replace("VPN", "").Trim()); | ||
| if (address.IsIPv4MappedToIPv6) |
There was a problem hiding this comment.
I believe if you restructure this as an if else and then have it drop out to the return below the ifs then you can move the normalise there and allow the inner works of that to mean you don't have to call it here
Nitrox.Model/Helper/NetHelper.cs
Outdated
| /// </summary> | ||
| public static bool IsPrivate(this IPAddress address) | ||
| { | ||
| address = NormalizeAddress(address); |
There was a problem hiding this comment.
I'm not sure what the benefit of doing this at a high scope is, can we not move this with the range method below as the other range method calls it itself anyway
| string name = parts[0].Trim(); | ||
| return new Entry(name, address, port); | ||
|
|
||
| static string ParseAddressWithOptionalPort(string value, out int parsedPort) |
There was a problem hiding this comment.
I'm not saying there is but I feel like there must be a better c# way of splitting an ipv6 and port off each other than having to do searches for indexes of : in the strings as well. I do know that ipv6 is not an easy thing to parse out with all the :: etc that can go on.
I assume we are then expecting people to put their ipv6 addresses in the server box in a particular format with the [ ] around it do we need to highlight this to them?
There was a problem hiding this comment.
You only use the [] in urls and ssh (for example) when you need to specify the username or need to add :port after the ip. See RFC3986 for more info.
I'll look into splitting the ipv6, but since the user is supposed to put the port in a different box in the ui anyway I don't think this is a big concern.
Nitrox.Model/Helper/NetHelper.cs
Outdated
| { | ||
| if (ip.Address.AddressFamily == AddressFamily.InterNetwork) | ||
| IPAddress address = ip.Address; | ||
| if (address.IsIPv4MappedToIPv6) |
There was a problem hiding this comment.
I think you either don't need this check here or you don't have it in the method you call to avoid doubling up the IsIPv4MappedToIPv6 call
| && !address.IsIPv6LinkLocal | ||
| && !address.IsIPv6Multicast) | ||
| { | ||
| ipv6Candidate = address; |
There was a problem hiding this comment.
Unless I have missed something why would you want to continue looping after assigning here rather than just returning early after assigning the cache
|
Did a play test and it works. Did the test on the test server. Then we tested on my own server. |
|
After this is merged i have a update for server logs and what not here: Kiaos/Nitrox@master...Kiaos:Nitrox:pr-2566 you can check it out. this needs to be merged first. |
Coding-Hen
left a comment
There was a problem hiding this comment.
Just a few comments. Overall looks good though. Will be nice to add ipv6 support
NitroxClient/MonoBehaviours/Gui/MainMenu/ServersList/MainMenuCreateServerPanel.cs
Show resolved
Hide resolved
Test Results244 tests +1 243 ✅ +1 6s ⏱️ ±0s Results for commit 7c35917. ± Comparison against base commit f9ef1f4. This pull request removes 2 and adds 3 tests. Note that renamed tests count towards both. |
IPv6 connectivity is increasingly common (especially on modern home networks). This PR aims to add basic ipv6 support to Nitrox.
These changes let Nitrox host/join over IPv6 while preserving existing IPv4 behavior.
All changes were pretty much just in general networking, so I don't expect anything in game to have changed.
Some hardcoded IPv4 strings were changed to allow ipv6 to show up, but by default everything still shows IPv4. However, this allows IPv6-only networks (if somehow someone was using one of those) to function with nitrox.
A note:
LiteNetLib was still IPv4-only, helper utilities filtered to IPv4, and address handling broke when IPv6 literals or mapped addresses appeared (e.g., discovery showing
::ffff:). This was fixed with changes toNetHelper.cs. These changes also added support for ipv6 to a few helper functions too.Test: Open a server, try connecting to it with
::1(IPv6 loopback). Confirm it works (it should also give you admin perms).A note on authorship: Codex was used to review the code to see where code needed to be changed to use IPv6 and it also directly wrote a few of the helper functions in
NetHelper.cs(mostly the IPv6 local ip detection). As this is pretty common code (not specific to Nitrox or Subnautica), I believe this is ok. I have reviewed and tested all changes.A note on why add IPv6:
IPv6 LAN discovery is NOT added in this PR, that could be future work.