1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-06 02:11:06 +09:00

Added improved NAT punch.

Clients that request an introduction now first request a confirmation from
the server to make sure unconnected messages can be sent in both
directions before attempting to make a connection. Similarly the server
automatically sends a confirmation to the client to reduce the possiblity
that either one of the endpoints has issues with sending messages to the
other.
This commit is contained in:
Frank Versnel
2016-02-15 16:36:12 +01:00
parent c8e2b011e0
commit 27b3d8e386
3 changed files with 70 additions and 21 deletions

View File

@@ -120,7 +120,7 @@ namespace Lidgren.Network
m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
if (reBind)
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, (int)1);
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, (int)1);
m_socket.ReceiveBufferSize = m_configuration.ReceiveBufferSize;
m_socket.SendBufferSize = m_configuration.SendBufferSize;
@@ -244,7 +244,7 @@ namespace Lidgren.Network
Heartbeat();
NetUtility.Sleep(10);
lock (m_initializeLock)
{
try
@@ -412,7 +412,7 @@ namespace Lidgren.Network
switch (sx.SocketErrorCode)
{
case SocketError.ConnectionReset:
// connection reset by peer, aka connection forcibly closed aka "ICMP port unreachable"
// connection reset by peer, aka connection forcibly closed aka "ICMP port unreachable"
// we should shut down the connection; but m_senderRemote seemingly cannot be trusted, so which connection should we shut down?!
// So, what to do?
LogWarning("ConnectionReset");
@@ -629,6 +629,14 @@ namespace Lidgren.Network
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess))
HandleNatPunch(ptr, senderEndPoint);
return;
case NetMessageType.NatIntroductionConfirmRequest:
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess))
HandleNatPunchConfirmRequest(ptr, senderEndPoint);
return;
case NetMessageType.NatIntroductionConfirmed:
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess))
HandleNatPunchConfirmed(ptr, senderEndPoint);
return;
case NetMessageType.ConnectResponse:
lock (m_handshakes)