You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-17 15:46:33 +09:00
Receiving (correctly) ConnectResponse from the correct address but wrong port will now mutate the connection to accept it; apparently some routers change outgoing port
This commit is contained in:
@@ -89,6 +89,15 @@ namespace Lidgren.Network
|
|||||||
m_currentMTU = m_peerConfiguration.MaximumTransmissionUnit;
|
m_currentMTU = m_peerConfiguration.MaximumTransmissionUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Change the internal endpoint to this new one. Used when, during handshake, a switch in port is detected (due to NAT)
|
||||||
|
/// </summary>
|
||||||
|
internal void MutateEndpoint(IPEndPoint endpoint)
|
||||||
|
{
|
||||||
|
m_remoteEndpoint = endpoint;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
internal void SetStatus(NetConnectionStatus status, string reason)
|
internal void SetStatus(NetConnectionStatus status, string reason)
|
||||||
{
|
{
|
||||||
// user or library thread
|
// user or library thread
|
||||||
|
|||||||
@@ -463,8 +463,23 @@ namespace Lidgren.Network
|
|||||||
{
|
{
|
||||||
if (hs.Key.Address.Equals(senderEndpoint.Address))
|
if (hs.Key.Address.Equals(senderEndpoint.Address))
|
||||||
{
|
{
|
||||||
LogWarning("Detected possible host port switch! TODO: Create new connection and continue handshake");
|
if (hs.Value.m_connectionInitiator)
|
||||||
return;
|
{
|
||||||
|
//
|
||||||
|
// We are currently trying to connection to XX.XX.XX.XX:Y
|
||||||
|
// ... but we just received a ConnectResponse from XX.XX.XX.XX:Z
|
||||||
|
// Lets just assume the router decided to use this port instead
|
||||||
|
//
|
||||||
|
var hsconn = hs.Value;
|
||||||
|
m_connectionLookup.Remove(hsconn.RemoteEndpoint);
|
||||||
|
|
||||||
|
LogDebug("Detected host port change; rerouting connection to " + senderEndpoint);
|
||||||
|
hsconn.MutateEndpoint(senderEndpoint);
|
||||||
|
m_connectionLookup.Add(senderEndpoint, hsconn);
|
||||||
|
|
||||||
|
hsconn.ReceivedHandshake(now, tp, ptr, payloadByteLength);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user