1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-15 22:56:30 +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:
lidgren
2011-04-27 17:42:32 +00:00
parent bd58c6400d
commit b575f72186
2 changed files with 26 additions and 2 deletions

View File

@@ -89,6 +89,15 @@ namespace Lidgren.Network
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)
{
// user or library thread

View File

@@ -463,8 +463,23 @@ namespace Lidgren.Network
{
if (hs.Key.Address.Equals(senderEndpoint.Address))
{
LogWarning("Detected possible host port switch! TODO: Create new connection and continue handshake");
return;
if (hs.Value.m_connectionInitiator)
{
//
// 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;
}
}
}
}