Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
### Changed

- Changed 3rd-party `XXHash` (32 & 64) implementation with an in-house reimplementation (#2310)
- The default listen address of `UnityTransport` is now 0.0.0.0. (#2307)
- When `NetworkConfig.EnsureNetworkVariableLengthSafety` is disabled `NetworkVariable` fields do not write the additional `ushort` size value (_which helps to reduce the total synchronization message size_), but when enabled it still writes the additional `ushort` value. (#2298)
- Optimized bandwidth usage by encoding most integer fields using variable-length encoding. (#2276)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private enum State
// frame at 60 FPS. This will be a large over-estimation in any realistic scenario.
private const int k_MaxReliableThroughput = (NetworkParameterConstants.MTU * 32 * 60) / 1000; // bytes per millisecond

private static ConnectionAddressData s_DefaultConnectionAddressData = new ConnectionAddressData { Address = "127.0.0.1", Port = 7777, ServerListenAddress = string.Empty };
private static ConnectionAddressData s_DefaultConnectionAddressData = new ConnectionAddressData { Address = "127.0.0.1", Port = 7777, ServerListenAddress = "0.0.0.0" };

#pragma warning disable IDE1006 // Naming Styles

Expand Down Expand Up @@ -303,9 +303,9 @@ public struct ConnectionAddressData
public ushort Port;

/// <summary>
/// IP address the server will listen on. If not provided, will use 'Address'.
/// IP address the server will listen on. If not provided, will use 0.0.0.0.
/// </summary>
[Tooltip("IP address the server will listen on. If not provided, will use 'Address'.")]
[Tooltip("IP address the server will listen on. If not provided, will use 0.0.0.0.")]
[SerializeField]
public string ServerListenAddress;

Expand All @@ -330,7 +330,21 @@ private static NetworkEndpoint ParseNetworkEndpoint(string ip, ushort port)
/// <summary>
/// Endpoint (IP address and port) server will listen/bind on.
/// </summary>
public NetworkEndpoint ListenEndPoint => ParseNetworkEndpoint((ServerListenAddress?.Length == 0) ? Address : ServerListenAddress, Port);
public NetworkEndpoint ListenEndPoint
{
get
{
if (ServerListenAddress?.Length == 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this log Debug.LogError($"Invalid network endpoint: {ip}:{port}."); in the case where the server listen address is empty?

I don't see an actual test case for this conditional - do we have one for an empty address versus a malformed one?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather, line 339 (accessing ServerEndPoint) would log this in this case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if both the 'Address' and 'Listen Address' fields are left empty, it will log an error. Although that scenario was never supported before. The previous behavior if leaving 'Listen Address' empty was to use 'Address'. I can add a special case where if both are left empty, we revert to 0.0.0.0 as the listen address.

There are no specific tests for leaving the listen address empty, but that is what a lot of tests actually end up doing, since it's the default when calling SetConnectionData without explicitly setting a listen address.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a change that avoids an error if both 'Address' and 'Listen Address' are empty (we'll then default to 0.0.0.0). Also added a test case for this particular scenario.

{
var ep = ServerEndPoint.Family == NetworkFamily.Ipv4 ? NetworkEndpoint.AnyIpv4 : NetworkEndpoint.AnyIpv6;
return ep.WithPort(Port);
}
else
{
return ParseNetworkEndpoint(ServerListenAddress, Port);
}
}
}
}

/// <summary>
Expand Down Expand Up @@ -529,14 +543,14 @@ private bool ServerBindAndListen(NetworkEndpoint endPoint)
int result = m_Driver.Bind(endPoint);
if (result != 0)
{
Debug.LogError("Server failed to bind");
Debug.LogError("Server failed to bind. This is usually caused by another process being bound to the same port.");
return false;
}

result = m_Driver.Listen();
if (result != 0)
{
Debug.LogError("Server failed to listen");
Debug.LogError("Server failed to listen.");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ public void UnityTransport_RestartSucceedsAfterFailure()
UnityTransport transport = new GameObject().AddComponent<UnityTransport>();
transport.Initialize();

transport.SetConnectionData("127.0.0.", 4242);
transport.SetConnectionData("127.0.0.", 4242, "127.0.0.");
Assert.False(transport.StartServer());

LogAssert.Expect(LogType.Error, "Invalid network endpoint: 127.0.0.:4242.");
LogAssert.Expect(LogType.Error, "Server failed to bind");
LogAssert.Expect(LogType.Error, "Server failed to bind. This is usually caused by another process being bound to the same port.");

transport.SetConnectionData("127.0.0.1", 4242);
transport.SetConnectionData("127.0.0.1", 4242, "127.0.0.1");
Assert.True(transport.StartServer());

transport.Shutdown();
Expand Down