You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-06 02:11:06 +09:00
IPv6: Space Wizard Edition.
This PR fixes the IPv6 support *properly*. The two previous PRs, #123 and #126, both made a mess out of it: PR #123 implemented IPv6 by breaking non-dualstack IPv4 support. PR #126 fixed IPv4 support by breaking non-dualstack IPv6 support. This change fixes the mess entirely. IPv4, IPv6 and IPv6-dual-stack are now all independently supported and work as expected. Namely IPv4 can't receive IPv6, IPv6 can only receive IPv4 if NetPeerConfiguration.DualStack is set. You can still have an IPv6-only socket. I'll leave some review comments on the PR for less-immediately obvious changes.
This commit is contained in:
@@ -132,14 +132,19 @@ namespace Lidgren.Network
|
||||
m_socket.SendBufferSize = m_configuration.SendBufferSize;
|
||||
m_socket.Blocking = false;
|
||||
|
||||
if(m_configuration.DualStack && m_configuration.LocalAddress.AddressFamily == AddressFamily.InterNetworkV6)
|
||||
if (m_configuration.DualStack)
|
||||
{
|
||||
if (m_configuration.LocalAddress.AddressFamily != AddressFamily.InterNetworkV6)
|
||||
{
|
||||
LogWarning("Configuration specifies Dual Stack but does not use IPv6 local address; Dual stack will not work.");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_socket.DualMode = true;
|
||||
}
|
||||
}
|
||||
|
||||
var localAddress = m_configuration.DualStack
|
||||
? m_configuration.LocalAddress.MapToIPv6()
|
||||
: m_configuration.LocalAddress;
|
||||
|
||||
var ep = (EndPoint)new NetEndPoint(localAddress, reBind ? m_listenPort : m_configuration.Port);
|
||||
var ep = (EndPoint)new NetEndPoint(m_configuration.LocalAddress, reBind ? m_listenPort : m_configuration.Port);
|
||||
m_socket.Bind(ep);
|
||||
|
||||
try
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
|
||||
using System.Net.Sockets;
|
||||
#if !__NOIPENDPOINT__
|
||||
using NetEndPoint = System.Net.IPEndPoint;
|
||||
#endif
|
||||
@@ -121,8 +121,14 @@ namespace Lidgren.Network
|
||||
m_connections = new List<NetConnection>();
|
||||
m_connectionLookup = new Dictionary<NetEndPoint, NetConnection>();
|
||||
m_handshakes = new Dictionary<NetEndPoint, NetConnection>();
|
||||
var address = config.DualStack ? IPAddress.IPv6Any : IPAddress.Any;
|
||||
m_senderRemote = (EndPoint)new NetEndPoint(address, 0);
|
||||
if (m_configuration.LocalAddress.AddressFamily == AddressFamily.InterNetworkV6)
|
||||
{
|
||||
m_senderRemote = (EndPoint)new IPEndPoint(IPAddress.IPv6Any, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_senderRemote = (EndPoint)new IPEndPoint(IPAddress.Any, 0);
|
||||
}
|
||||
m_status = NetPeerStatus.NotRunning;
|
||||
m_receivedFragmentGroups = new Dictionary<NetConnection, Dictionary<int, ReceivedFragmentGroup>>();
|
||||
}
|
||||
|
||||
@@ -344,7 +344,9 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the library should use IPv6 dual stack mode
|
||||
/// Gets or sets a value indicating whether the library should use IPv6 dual stack mode.
|
||||
/// If you enable this you should make sure that the <see cref="LocalAddress"/> is an IPv6 address.
|
||||
/// Cannot be changed once NetPeer is initialized.
|
||||
/// </summary>
|
||||
public bool DualStack
|
||||
{
|
||||
@@ -354,10 +356,6 @@ namespace Lidgren.Network
|
||||
if (m_isLocked)
|
||||
throw new NetException(c_isLockedMessage);
|
||||
m_dualStack = value;
|
||||
if (m_dualStack && m_localAddress.Equals(IPAddress.Any))
|
||||
m_localAddress = IPAddress.IPv6Any;
|
||||
if (!m_dualStack && m_localAddress.Equals(IPAddress.IPv6Any))
|
||||
m_localAddress = IPAddress.Any;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user