-
Notifications
You must be signed in to change notification settings - Fork 456
fix: Accept single words as valid hostnames #3591
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
base: develop-2.0.0
Are you sure you want to change the base?
Conversation
@@ -7,7 +7,7 @@ | |||
|
|||
using System; | |||
using System.Collections.Generic; | |||
#if HOSTNAME_RESOLUTION_AVAILABLE && UTP_TRANSPORT_2_4_ABOVE | |||
#if HOSTNAME_RESOLUTION_AVAILABLE | |||
using System.Text.RegularExpressions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests failed because initial standards check failed with an error about this line error IDE0005: Using directive is unnecessary.
so I guess that this can be completely removed (worth confirming so I just left the comment instead of removing it already)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other then that it's a really nice PR and description!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for having a look at the failure! We indeed don't need to use regexes anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from my side, I would still wait for Noel or Emma to also approve/comment
FYI the CMB Service Test failure is a know issue that Noel is addressing |
Purpose of this PR
The regex we used to validate hostnames did not accept single words as valid hostnames. But single words can be valid hostnames. The most common is of course "localhost" but one can edit one's hosts file to define any word as something the local resolver will resolve to an IP address.
This PR addresses this by removing any validation of the provided hostname. We could modify the validity check to accept single words too, but the regex is pretty indigestible already and it's simpler to just let the resolver fail if the user provided garbage. UTP will signal this through a disconnection event with an appropriate reason (which we'll be able to map to a nice error message once this PR lands).
While I was at it, I also made a few cleanups and improvements:
UTP_TRANSPORT_2_4_ABOVE
define. NGO depends on UTP 2.4.0 so it can be safely assumed that users will have it installed. No need to conditionally compile the code that depends on it.Connect
method when connecting to a hostname.ConnectionAddressData.ServerEndPoint
. We don't use it anymore, it doesn't work with hostnames, and it's not providing any value over just callingNetworkEndpoint.Parse
. And worst of all: its capitalization of "endpoint" doesn't match what we use elsewhere.SetConnectionData
. The reason for this change is that the resolver in UTP prioritizes IPv6 addresses over IPv4. So if we listen on IPv4 by default, we're likely to get issues if the resolver then ends up with an IPv6 address. In current versions of UTP for instance, this causes errors on Windows (a fix is on the way). I'm looking into changing the behavior of the resolver to prefer IPv4, but that's an engine change so might take a while to land. In the meantime defaulting to IPv6 seems like the best approach.Changelog
UnityTransport
would not accept single words as valid hostnames (notably "localhost").UnityTransport.ConnectionAddressData.ServerEndPoint
as obsolete. It can't work when using hostnames as the server address, and its functionality can easily be replicated usingNetworkEndpoint.Parse
.Documentation
No documentation changes or additions were necessary.
Testing & QA
Tested with manual and automated tests.
Backport
Hostname resolution is only supported in UTP 2.4+ and Unity 6.1+, so no backport necessary.