Commit b21d4ad
fix: Accept single words as valid hostnames (#3591)
## 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](#3551)
lands).
While I was at it, I also made a few cleanups and improvements:
- Removed the `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.
- Added a test that establishes a connection using hostname resolution.
- Simplified the logic around connections and avoid bypassing the
`Connect` method when connecting to a hostname.
- Deprecated `ConnectionAddressData.ServerEndPoint`. We don't use it
anymore, it doesn't work with hostnames, and it's not providing any
value over just calling `NetworkEndpoint.Parse`. And worst of all: its
capitalization of "endpoint" doesn't match what we use elsewhere.
- Modified the listen address logic so that if a domain name is used, by
default if remote connections are allowed we will listen on :: (the IPv6
"any" address) instead of 0.0.0.0. This can still be overridden using
`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
- Fixed: Fixed an issue where `UnityTransport` would not accept single
words as valid hostnames (notably "localhost").
- Changed: Marked `UnityTransport.ConnectionAddressData.ServerEndPoint`
as obsolete. It can't work when using hostnames as the server address,
and its functionality can easily be replicated using
`NetworkEndpoint.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.
---------
Co-authored-by: Michał Chrobot <[email protected]>
Co-authored-by: Noel Stephens <[email protected]>1 parent 5f9463a commit b21d4ad
File tree
7 files changed
+108
-161
lines changed- com.unity.netcode.gameobjects
- Runtime
- Transports/UTP
- Tests
- Editor
- Transports
- Runtime
- Transports
7 files changed
+108
-161
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | | - | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
Lines changed: 37 additions & 94 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | 10 | | |
14 | 11 | | |
15 | 12 | | |
| |||
235 | 232 | | |
236 | 233 | | |
237 | 234 | | |
238 | | - | |
| 235 | + | |
239 | 236 | | |
240 | 237 | | |
241 | 238 | | |
| |||
245 | 242 | | |
246 | 243 | | |
247 | 244 | | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | 245 | | |
254 | 246 | | |
255 | 247 | | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
273 | 255 | | |
274 | 256 | | |
275 | 257 | | |
| |||
281 | 263 | | |
282 | 264 | | |
283 | 265 | | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
| 266 | + | |
292 | 267 | | |
293 | 268 | | |
294 | 269 | | |
295 | 270 | | |
296 | 271 | | |
297 | 272 | | |
298 | 273 | | |
299 | | - | |
| 274 | + | |
300 | 275 | | |
301 | 276 | | |
302 | 277 | | |
303 | 278 | | |
304 | 279 | | |
305 | 280 | | |
306 | 281 | | |
307 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
308 | 285 | | |
309 | | - | |
| 286 | + | |
310 | 287 | | |
311 | 288 | | |
312 | 289 | | |
| |||
667 | 644 | | |
668 | 645 | | |
669 | 646 | | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | 647 | | |
681 | 648 | | |
682 | 649 | | |
| |||
687 | 654 | | |
688 | 655 | | |
689 | 656 | | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
697 | 662 | | |
698 | | - | |
699 | | - | |
| 663 | + | |
700 | 664 | | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
712 | 671 | | |
713 | | - | |
714 | | - | |
| 672 | + | |
| 673 | + | |
715 | 674 | | |
| 675 | + | |
716 | 676 | | |
717 | 677 | | |
718 | 678 | | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | 679 | | |
729 | 680 | | |
730 | 681 | | |
| |||
737 | 688 | | |
738 | 689 | | |
739 | 690 | | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
740 | 699 | | |
741 | 700 | | |
742 | 701 | | |
743 | 702 | | |
744 | 703 | | |
745 | | - | |
746 | 704 | | |
747 | 705 | | |
748 | | - | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | | - | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | 706 | | |
760 | | - | |
761 | | - | |
762 | | - | |
763 | | - | |
764 | 707 | | |
765 | 708 | | |
766 | 709 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | 71 | | |
77 | 72 | | |
78 | 73 | | |
| |||
Lines changed: 34 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | 135 | | |
141 | 136 | | |
142 | 137 | | |
| |||
156 | 151 | | |
157 | 152 | | |
158 | 153 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | 154 | | |
178 | 155 | | |
179 | 156 | | |
| |||
206 | 183 | | |
207 | 184 | | |
208 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
209 | 218 | | |
210 | 219 | | |
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | 41 | | |
47 | 42 | | |
48 | 43 | | |
| |||
0 commit comments