Skip to content

Commit

Permalink
disable MTU discovery by default because some routers can break detec…
Browse files Browse the repository at this point in the history
…tion and connection in result. Remove UseSafeMtu (for this just use MtuOverride).
  • Loading branch information
RevenantX committed Nov 22, 2024
1 parent c81e1b5 commit 60c453d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion LiteNetLib/NetConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static class NetConstants

internal static readonly int[] PossibleMtu =
{
576 - MaxUdpHeaderSize, //minimal (RFC 1191)
//576 - MaxUdpHeaderSize minimal (RFC 1191)
1024, //most games standard
1232 - MaxUdpHeaderSize,
1460 - MaxUdpHeaderSize, //google cloud
Expand All @@ -66,6 +66,7 @@ public static class NetConstants
};

//Max possible single packet size
public static readonly int InitialMtu = PossibleMtu[0];
public static readonly int MaxPacketSize = PossibleMtu[PossibleMtu.Length - 1];
public static readonly int MaxUnreliableDataSize = MaxPacketSize - HeaderSize;

Expand Down
5 changes: 3 additions & 2 deletions LiteNetLib/NetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,10 @@ private struct IncomingData
public int MtuOverride = 0;

/// <summary>
/// Sets initial MTU to lowest possible value according to RFC1191 (576 bytes)
/// Automatically discovery mtu starting from. Use at own risk because some routers can break MTU detection
/// and connection in result
/// </summary>
public bool UseSafeMtu = false;
public bool MtuDiscovery = false;

/// <summary>
/// First peer. Useful for Client mode
Expand Down
9 changes: 4 additions & 5 deletions LiteNetLib/NetPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,12 @@ internal void FinishEndPointChange(IPEndPoint newEndPoint)

internal void ResetMtu()
{
_finishMtu = false;
//finish if discovery disabled
_finishMtu = !NetManager.MtuDiscovery;
if (NetManager.MtuOverride > 0)
OverrideMtu(NetManager.MtuOverride);
else if (NetManager.UseSafeMtu)
SetMtu(0);
else
SetMtu(1);
SetMtu(0);
}

private void SetMtu(int mtuIdx)
Expand Down Expand Up @@ -1406,7 +1405,7 @@ internal void Update(float deltaTime)
_channelSendQueue.Enqueue(channel);
}
}

if (_unreliablePendingCount > 0)
{
int unreliableCount;
Expand Down
Binary file modified LiteNetLibSampleUnity/Assets/LiteNetLib.dll
Binary file not shown.
5 changes: 3 additions & 2 deletions LiteNetLibSampleUnity/Assets/LiteNetLib.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 60c453d

Please sign in to comment.