1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-16 23:26:32 +09:00

Changed all Endpoint to EndPoint for consistency

This commit is contained in:
lidgren
2012-07-06 21:28:13 +00:00
parent b49392182b
commit 1ecf9fd8b8
19 changed files with 101 additions and 102 deletions

View File

@@ -618,7 +618,7 @@ namespace Lidgren.Network
/// <summary> /// <summary>
/// Reads a stored IPv4 endpoint description /// Reads a stored IPv4 endpoint description
/// </summary> /// </summary>
public IPEndPoint ReadIPEndpoint() public IPEndPoint ReadIPEndPoint()
{ {
byte len = ReadByte(); byte len = ReadByte();
byte[] addressBytes = ReadBytes(len); byte[] addressBytes = ReadBytes(len);

View File

@@ -77,10 +77,10 @@ namespace Lidgren.Network
/// <summary> /// <summary>
/// Connect to a remote server /// Connect to a remote server
/// </summary> /// </summary>
/// <param name="remoteEndpoint">The remote endpoint to connect to</param> /// <param name="remoteEndPoint">The remote endpoint to connect to</param>
/// <param name="hailMessage">The hail message to pass</param> /// <param name="hailMessage">The hail message to pass</param>
/// <returns>server connection, or null if already connected</returns> /// <returns>server connection, or null if already connected</returns>
public override NetConnection Connect(IPEndPoint remoteEndpoint, NetOutgoingMessage hailMessage) public override NetConnection Connect(IPEndPoint remoteEndPoint, NetOutgoingMessage hailMessage)
{ {
lock (m_connections) lock (m_connections)
{ {
@@ -90,7 +90,7 @@ namespace Lidgren.Network
return null; return null;
} }
} }
return base.Connect(remoteEndpoint, hailMessage); return base.Connect(remoteEndPoint, hailMessage);
} }
/// <summary> /// <summary>

View File

@@ -111,7 +111,7 @@ namespace Lidgren.Network
// in case we're still in handshake // in case we're still in handshake
lock (m_peer.m_handshakes) lock (m_peer.m_handshakes)
m_peer.m_handshakes.Remove(m_remoteEndpoint); m_peer.m_handshakes.Remove(m_remoteEndPoint);
m_disconnectRequested = false; m_disconnectRequested = false;
m_connectRequested = false; m_connectRequested = false;
@@ -130,7 +130,7 @@ namespace Lidgren.Network
WriteLocalHail(om); WriteLocalHail(om);
m_peer.SendLibrary(om, m_remoteEndpoint); m_peer.SendLibrary(om, m_remoteEndPoint);
m_connectRequested = false; m_connectRequested = false;
m_lastHandshakeSendTime = now; m_lastHandshakeSendTime = now;
@@ -155,9 +155,9 @@ namespace Lidgren.Network
WriteLocalHail(om); WriteLocalHail(om);
if (onLibraryThread) if (onLibraryThread)
m_peer.SendLibrary(om, m_remoteEndpoint); m_peer.SendLibrary(om, m_remoteEndPoint);
else else
m_peer.m_unsentUnconnectedMessages.Enqueue(new NetTuple<System.Net.IPEndPoint, NetOutgoingMessage>(m_remoteEndpoint, om)); m_peer.m_unsentUnconnectedMessages.Enqueue(new NetTuple<System.Net.IPEndPoint, NetOutgoingMessage>(m_remoteEndPoint, om));
m_lastHandshakeSendTime = now; m_lastHandshakeSendTime = now;
m_handshakeAttempts++; m_handshakeAttempts++;
@@ -176,9 +176,9 @@ namespace Lidgren.Network
NetOutgoingMessage om = m_peer.CreateMessage(reason); NetOutgoingMessage om = m_peer.CreateMessage(reason);
om.m_messageType = NetMessageType.Disconnect; om.m_messageType = NetMessageType.Disconnect;
if (onLibraryThread) if (onLibraryThread)
m_peer.SendLibrary(om, m_remoteEndpoint); m_peer.SendLibrary(om, m_remoteEndPoint);
else else
m_peer.m_unsentUnconnectedMessages.Enqueue(new NetTuple<System.Net.IPEndPoint, NetOutgoingMessage>(m_remoteEndpoint, om)); m_peer.m_unsentUnconnectedMessages.Enqueue(new NetTuple<System.Net.IPEndPoint, NetOutgoingMessage>(m_remoteEndPoint, om));
} }
private void WriteLocalHail(NetOutgoingMessage om) private void WriteLocalHail(NetOutgoingMessage om)
@@ -200,7 +200,7 @@ namespace Lidgren.Network
NetOutgoingMessage om = m_peer.CreateMessage(0); NetOutgoingMessage om = m_peer.CreateMessage(0);
om.m_messageType = NetMessageType.ConnectionEstablished; om.m_messageType = NetMessageType.ConnectionEstablished;
om.Write((float)NetTime.Now); om.Write((float)NetTime.Now);
m_peer.SendLibrary(om, m_remoteEndpoint); m_peer.SendLibrary(om, m_remoteEndPoint);
m_handshakeAttempts = 0; m_handshakeAttempts = 0;
@@ -260,7 +260,7 @@ namespace Lidgren.Network
SendDisconnect(reason, false); SendDisconnect(reason, false);
// remove from handshakes // remove from handshakes
m_peer.m_handshakes.Remove(m_remoteEndpoint); // TODO: make this more thread safe? we're on user thread m_peer.m_handshakes.Remove(m_remoteEndPoint); // TODO: make this more thread safe? we're on user thread
} }
internal void ReceivedHandshake(double now, NetMessageType tp, int ptr, int payloadLength) internal void ReceivedHandshake(double now, NetMessageType tp, int ptr, int payloadLength)
@@ -293,7 +293,7 @@ namespace Lidgren.Network
NetIncomingMessage appMsg = m_peer.CreateIncomingMessage(NetIncomingMessageType.ConnectionApproval, (m_remoteHailMessage == null ? 0 : m_remoteHailMessage.LengthBytes)); NetIncomingMessage appMsg = m_peer.CreateIncomingMessage(NetIncomingMessageType.ConnectionApproval, (m_remoteHailMessage == null ? 0 : m_remoteHailMessage.LengthBytes));
appMsg.m_receiveTime = now; appMsg.m_receiveTime = now;
appMsg.m_senderConnection = this; appMsg.m_senderConnection = this;
appMsg.m_senderEndpoint = this.m_remoteEndpoint; appMsg.m_senderEndPoint = this.m_remoteEndPoint;
if (m_remoteHailMessage != null) if (m_remoteHailMessage != null)
appMsg.Write(m_remoteHailMessage.m_data, 0, m_remoteHailMessage.LengthBytes); appMsg.Write(m_remoteHailMessage.m_data, 0, m_remoteHailMessage.LengthBytes);
SetStatus(NetConnectionStatus.RespondedAwaitingApproval, "Awaiting approval"); SetStatus(NetConnectionStatus.RespondedAwaitingApproval, "Awaiting approval");
@@ -401,11 +401,11 @@ namespace Lidgren.Network
break; break;
case NetMessageType.Discovery: case NetMessageType.Discovery:
m_peer.HandleIncomingDiscoveryRequest(now, m_remoteEndpoint, ptr, payloadLength); m_peer.HandleIncomingDiscoveryRequest(now, m_remoteEndPoint, ptr, payloadLength);
return; return;
case NetMessageType.DiscoveryResponse: case NetMessageType.DiscoveryResponse:
m_peer.HandleIncomingDiscoveryResponse(now, m_remoteEndpoint, ptr, payloadLength); m_peer.HandleIncomingDiscoveryResponse(now, m_remoteEndPoint, ptr, payloadLength);
return; return;
case NetMessageType.Ping: case NetMessageType.Ping:

View File

@@ -71,7 +71,7 @@ namespace Lidgren.Network
int len = om.Encode(m_peer.m_sendBuffer, 0, 0); int len = om.Encode(m_peer.m_sendBuffer, 0, 0);
bool connectionReset; bool connectionReset;
m_peer.SendPacket(len, m_remoteEndpoint, 1, out connectionReset); m_peer.SendPacket(len, m_remoteEndPoint, 1, out connectionReset);
m_statistics.PacketSent(len, 1); m_statistics.PacketSent(len, 1);
} }
@@ -88,7 +88,7 @@ namespace Lidgren.Network
int len = om.Encode(m_peer.m_sendBuffer, 0, 0); int len = om.Encode(m_peer.m_sendBuffer, 0, 0);
bool connectionReset; bool connectionReset;
m_peer.SendPacket(len, m_remoteEndpoint, 1, out connectionReset); m_peer.SendPacket(len, m_remoteEndPoint, 1, out connectionReset);
m_statistics.PacketSent(len, 1); m_statistics.PacketSent(len, 1);
} }
@@ -138,7 +138,7 @@ namespace Lidgren.Network
{ {
NetIncomingMessage update = m_peer.CreateIncomingMessage(NetIncomingMessageType.ConnectionLatencyUpdated, 4); NetIncomingMessage update = m_peer.CreateIncomingMessage(NetIncomingMessageType.ConnectionLatencyUpdated, 4);
update.m_senderConnection = this; update.m_senderConnection = this;
update.m_senderEndpoint = this.m_remoteEndpoint; update.m_senderEndPoint = this.m_remoteEndPoint;
update.Write(rtt); update.Write(rtt);
m_peer.ReleaseMessage(update); m_peer.ReleaseMessage(update);
} }

View File

@@ -104,7 +104,7 @@ namespace Lidgren.Network
om.m_messageType = NetMessageType.ExpandMTURequest; om.m_messageType = NetMessageType.ExpandMTURequest;
int len = om.Encode(m_peer.m_sendBuffer, 0, 0); int len = om.Encode(m_peer.m_sendBuffer, 0, 0);
bool ok = m_peer.SendMTUPacket(len, m_remoteEndpoint); bool ok = m_peer.SendMTUPacket(len, m_remoteEndPoint);
if (ok == false) if (ok == false)
{ {
//m_peer.LogDebug("Send MTU failed for size " + size); //m_peer.LogDebug("Send MTU failed for size " + size);
@@ -148,7 +148,7 @@ namespace Lidgren.Network
om.m_messageType = NetMessageType.ExpandMTUSuccess; om.m_messageType = NetMessageType.ExpandMTUSuccess;
int len = om.Encode(m_peer.m_sendBuffer, 0, 0); int len = om.Encode(m_peer.m_sendBuffer, 0, 0);
bool connectionReset; bool connectionReset;
m_peer.SendPacket(len, m_remoteEndpoint, 1, out connectionReset); m_peer.SendPacket(len, m_remoteEndPoint, 1, out connectionReset);
// m_peer.LogDebug("Received MTU expand request for " + size + " bytes"); // m_peer.LogDebug("Received MTU expand request for " + size + " bytes");

View File

@@ -8,14 +8,14 @@ namespace Lidgren.Network
/// <summary> /// <summary>
/// Represents a connection to a remote peer /// Represents a connection to a remote peer
/// </summary> /// </summary>
[DebuggerDisplay("RemoteUniqueIdentifier={RemoteUniqueIdentifier} RemoteEndpoint={RemoteEndpoint}")] [DebuggerDisplay("RemoteUniqueIdentifier={RemoteUniqueIdentifier} RemoteEndPoint={remoteEndPoint}")]
public partial class NetConnection public partial class NetConnection
{ {
internal NetPeer m_peer; internal NetPeer m_peer;
internal NetPeerConfiguration m_peerConfiguration; internal NetPeerConfiguration m_peerConfiguration;
internal NetConnectionStatus m_status; internal NetConnectionStatus m_status;
internal NetConnectionStatus m_visibleStatus; internal NetConnectionStatus m_visibleStatus;
internal IPEndPoint m_remoteEndpoint; internal IPEndPoint m_remoteEndPoint;
internal NetSenderChannelBase[] m_sendChannels; internal NetSenderChannelBase[] m_sendChannels;
internal NetReceiverChannelBase[] m_receiveChannels; internal NetReceiverChannelBase[] m_receiveChannels;
internal NetOutgoingMessage m_localHailMessage; internal NetOutgoingMessage m_localHailMessage;
@@ -54,7 +54,7 @@ namespace Lidgren.Network
/// <summary> /// <summary>
/// Gets the remote endpoint for the connection /// Gets the remote endpoint for the connection
/// </summary> /// </summary>
public IPEndPoint RemoteEndpoint { get { return m_remoteEndpoint; } } public IPEndPoint RemoteEndPoint { get { return m_remoteEndPoint; } }
/// <summary> /// <summary>
/// Gets the unique identifier of the remote NetPeer for this connection /// Gets the unique identifier of the remote NetPeer for this connection
@@ -75,13 +75,13 @@ namespace Lidgren.Network
return 0.02f + (avgRtt * 2.0f); // 20 ms + double rtt return 0.02f + (avgRtt * 2.0f); // 20 ms + double rtt
} }
internal NetConnection(NetPeer peer, IPEndPoint remoteEndpoint) internal NetConnection(NetPeer peer, IPEndPoint remoteEndPoint)
{ {
m_peer = peer; m_peer = peer;
m_peerConfiguration = m_peer.Configuration; m_peerConfiguration = m_peer.Configuration;
m_status = NetConnectionStatus.None; m_status = NetConnectionStatus.None;
m_visibleStatus = NetConnectionStatus.None; m_visibleStatus = NetConnectionStatus.None;
m_remoteEndpoint = remoteEndpoint; m_remoteEndPoint = remoteEndPoint;
m_sendChannels = new NetSenderChannelBase[NetConstants.NumTotalChannels]; m_sendChannels = new NetSenderChannelBase[NetConstants.NumTotalChannels];
m_receiveChannels = new NetReceiverChannelBase[NetConstants.NumTotalChannels]; m_receiveChannels = new NetReceiverChannelBase[NetConstants.NumTotalChannels];
m_queuedOutgoingAcks = new NetQueue<NetTuple<NetMessageType, int>>(4); m_queuedOutgoingAcks = new NetQueue<NetTuple<NetMessageType, int>>(4);
@@ -94,10 +94,9 @@ namespace Lidgren.Network
/// <summary> /// <summary>
/// Change the internal endpoint to this new one. Used when, during handshake, a switch in port is detected (due to NAT) /// Change the internal endpoint to this new one. Used when, during handshake, a switch in port is detected (due to NAT)
/// </summary> /// </summary>
internal void MutateEndpoint(IPEndPoint endpoint) internal void MutateEndPoint(IPEndPoint endPoint)
{ {
m_remoteEndpoint = endpoint; m_remoteEndPoint = endPoint;
} }
internal void SetStatus(NetConnectionStatus status, string reason) internal void SetStatus(NetConnectionStatus status, string reason)
@@ -121,7 +120,7 @@ namespace Lidgren.Network
{ {
NetIncomingMessage info = m_peer.CreateIncomingMessage(NetIncomingMessageType.StatusChanged, 4 + reason.Length + (reason.Length > 126 ? 2 : 1)); NetIncomingMessage info = m_peer.CreateIncomingMessage(NetIncomingMessageType.StatusChanged, 4 + reason.Length + (reason.Length > 126 ? 2 : 1));
info.m_senderConnection = this; info.m_senderConnection = this;
info.m_senderEndpoint = m_remoteEndpoint; info.m_senderEndPoint = m_remoteEndPoint;
info.Write((byte)m_status); info.Write((byte)m_status);
info.Write(reason); info.Write(reason);
m_peer.ReleaseMessage(info); m_peer.ReleaseMessage(info);
@@ -216,7 +215,7 @@ namespace Lidgren.Network
{ {
// send packet and go for another round of acks // send packet and go for another round of acks
NetException.Assert(m_sendBufferWritePtr > 0 && m_sendBufferNumMessages > 0); NetException.Assert(m_sendBufferWritePtr > 0 && m_sendBufferNumMessages > 0);
m_peer.SendPacket(m_sendBufferWritePtr, m_remoteEndpoint, m_sendBufferNumMessages, out connectionReset); m_peer.SendPacket(m_sendBufferWritePtr, m_remoteEndPoint, m_sendBufferNumMessages, out connectionReset);
m_statistics.PacketSent(m_sendBufferWritePtr, 1); m_statistics.PacketSent(m_sendBufferWritePtr, 1);
m_sendBufferWritePtr = 0; m_sendBufferWritePtr = 0;
m_sendBufferNumMessages = 0; m_sendBufferNumMessages = 0;
@@ -259,7 +258,7 @@ namespace Lidgren.Network
{ {
m_peer.VerifyNetworkThread(); m_peer.VerifyNetworkThread();
NetException.Assert(m_sendBufferWritePtr > 0 && m_sendBufferNumMessages > 0); NetException.Assert(m_sendBufferWritePtr > 0 && m_sendBufferNumMessages > 0);
m_peer.SendPacket(m_sendBufferWritePtr, m_remoteEndpoint, m_sendBufferNumMessages, out connectionReset); m_peer.SendPacket(m_sendBufferWritePtr, m_remoteEndPoint, m_sendBufferNumMessages, out connectionReset);
m_statistics.PacketSent(m_sendBufferWritePtr, m_sendBufferNumMessages); m_statistics.PacketSent(m_sendBufferWritePtr, m_sendBufferNumMessages);
m_sendBufferWritePtr = 0; m_sendBufferWritePtr = 0;
m_sendBufferNumMessages = 0; m_sendBufferNumMessages = 0;
@@ -280,7 +279,7 @@ namespace Lidgren.Network
{ {
bool connReset; // TODO: handle connection reset bool connReset; // TODO: handle connection reset
NetException.Assert(m_sendBufferWritePtr > 0 && m_sendBufferNumMessages > 0); // or else the message should have been fragmented earlier NetException.Assert(m_sendBufferWritePtr > 0 && m_sendBufferNumMessages > 0); // or else the message should have been fragmented earlier
m_peer.SendPacket(m_sendBufferWritePtr, m_remoteEndpoint, m_sendBufferNumMessages, out connReset); m_peer.SendPacket(m_sendBufferWritePtr, m_remoteEndPoint, m_sendBufferNumMessages, out connReset);
m_statistics.PacketSent(m_sendBufferWritePtr, m_sendBufferNumMessages); m_statistics.PacketSent(m_sendBufferWritePtr, m_sendBufferNumMessages);
m_sendBufferWritePtr = 0; m_sendBufferWritePtr = 0;
m_sendBufferNumMessages = 0; m_sendBufferNumMessages = 0;
@@ -500,7 +499,7 @@ namespace Lidgren.Network
/// </summary> /// </summary>
public override string ToString() public override string ToString()
{ {
return "[NetConnection to " + m_remoteEndpoint + "]"; return "[NetConnection to " + m_remoteEndPoint + "]";
} }
} }
} }

View File

@@ -29,7 +29,7 @@ namespace Lidgren.Network
public sealed class NetIncomingMessage : NetBuffer public sealed class NetIncomingMessage : NetBuffer
{ {
internal NetIncomingMessageType m_incomingMessageType; internal NetIncomingMessageType m_incomingMessageType;
internal IPEndPoint m_senderEndpoint; internal IPEndPoint m_senderEndPoint;
internal NetConnection m_senderConnection; internal NetConnection m_senderConnection;
internal int m_sequenceNumber; internal int m_sequenceNumber;
internal NetMessageType m_receivedMessageType; internal NetMessageType m_receivedMessageType;
@@ -54,7 +54,7 @@ namespace Lidgren.Network
/// <summary> /// <summary>
/// IPEndPoint of sender, if any /// IPEndPoint of sender, if any
/// </summary> /// </summary>
public IPEndPoint SenderEndpoint { get { return m_senderEndpoint; } } public IPEndPoint SenderEndPoint { get { return m_senderEndPoint; } }
/// <summary> /// <summary>
/// NetConnection of sender, if any /// NetConnection of sender, if any

View File

@@ -48,8 +48,8 @@ namespace Lidgren.Network
NetIncomingMessage tmp = SetupReadHelperMessage(ptr, 1000); // never mind length NetIncomingMessage tmp = SetupReadHelperMessage(ptr, 1000); // never mind length
byte hostByte = tmp.ReadByte(); byte hostByte = tmp.ReadByte();
IPEndPoint remoteInternal = tmp.ReadIPEndpoint(); IPEndPoint remoteInternal = tmp.ReadIPEndPoint();
IPEndPoint remoteExternal = tmp.ReadIPEndpoint(); IPEndPoint remoteExternal = tmp.ReadIPEndPoint();
string token = tmp.ReadString(); string token = tmp.ReadString();
bool isHost = (hostByte != 0); bool isHost = (hostByte != 0);
@@ -78,7 +78,7 @@ namespace Lidgren.Network
/// <summary> /// <summary>
/// Called when receiving a NatPunchMessage from a remote endpoint /// Called when receiving a NatPunchMessage from a remote endpoint
/// </summary> /// </summary>
private void HandleNatPunch(int ptr, IPEndPoint senderEndpoint) private void HandleNatPunch(int ptr, IPEndPoint senderEndPoint)
{ {
NetIncomingMessage tmp = SetupReadHelperMessage(ptr, 1000); // never mind length NetIncomingMessage tmp = SetupReadHelperMessage(ptr, 1000); // never mind length
@@ -86,18 +86,18 @@ namespace Lidgren.Network
if (fromHostByte == 0) if (fromHostByte == 0)
{ {
// it's from client // it's from client
LogDebug("NAT punch received from " + senderEndpoint + " we're host, so we ignore this"); LogDebug("NAT punch received from " + senderEndPoint + " we're host, so we ignore this");
return; // don't alert hosts about nat punch successes; only clients return; // don't alert hosts about nat punch successes; only clients
} }
string token = tmp.ReadString(); string token = tmp.ReadString();
LogDebug("NAT punch received from " + senderEndpoint + " we're client, so we've succeeded - token is " + token); LogDebug("NAT punch received from " + senderEndPoint + " we're client, so we've succeeded - token is " + token);
// //
// Release punch success to client; enabling him to Connect() to msg.SenderIPEndPoint if token is ok // Release punch success to client; enabling him to Connect() to msg.SenderIPEndPoint if token is ok
// //
NetIncomingMessage punchSuccess = CreateIncomingMessage(NetIncomingMessageType.NatIntroductionSuccess, 10); NetIncomingMessage punchSuccess = CreateIncomingMessage(NetIncomingMessageType.NatIntroductionSuccess, 10);
punchSuccess.m_senderEndpoint = senderEndpoint; punchSuccess.m_senderEndPoint = senderEndPoint;
punchSuccess.Write(token); punchSuccess.Write(token);
ReleaseMessage(punchSuccess); ReleaseMessage(punchSuccess);
} }

View File

@@ -30,11 +30,11 @@ namespace Lidgren.Network
/// <summary> /// <summary>
/// Emit a discovery signal to a single known host /// Emit a discovery signal to a single known host
/// </summary> /// </summary>
public void DiscoverKnownPeer(IPEndPoint endpoint) public void DiscoverKnownPeer(IPEndPoint endPoint)
{ {
NetOutgoingMessage om = CreateMessage(0); NetOutgoingMessage om = CreateMessage(0);
om.m_messageType = NetMessageType.Discovery; om.m_messageType = NetMessageType.Discovery;
m_unsentUnconnectedMessages.Enqueue(new NetTuple<IPEndPoint, NetOutgoingMessage>(endpoint, om)); m_unsentUnconnectedMessages.Enqueue(new NetTuple<IPEndPoint, NetOutgoingMessage>(endPoint, om));
} }
/// <summary> /// <summary>

View File

@@ -291,10 +291,10 @@ namespace Lidgren.Network
{ {
#if DEBUG #if DEBUG
// sanity check // sanity check
if (conn.m_status == NetConnectionStatus.Disconnected && m_handshakes.ContainsKey(conn.RemoteEndpoint)) if (conn.m_status == NetConnectionStatus.Disconnected && m_handshakes.ContainsKey(conn.RemoteEndPoint))
{ {
LogWarning("Sanity fail! Handshakes list contained disconnected connection!"); LogWarning("Sanity fail! Handshakes list contained disconnected connection!");
m_handshakes.Remove(conn.RemoteEndpoint); m_handshakes.Remove(conn.RemoteEndPoint);
} }
#endif #endif
break; // collection has been modified break; // collection has been modified
@@ -322,7 +322,7 @@ namespace Lidgren.Network
// remove connection // remove connection
// //
m_connections.Remove(conn); m_connections.Remove(conn);
m_connectionLookup.Remove(conn.RemoteEndpoint); m_connectionLookup.Remove(conn.RemoteEndPoint);
break; // can't continue iteration here break; // can't continue iteration here
} }
} }
@@ -461,7 +461,7 @@ namespace Lidgren.Network
msg.m_sequenceNumber = sequenceNumber; msg.m_sequenceNumber = sequenceNumber;
msg.m_receivedMessageType = tp; msg.m_receivedMessageType = tp;
msg.m_senderConnection = sender; msg.m_senderConnection = sender;
msg.m_senderEndpoint = ipsender; msg.m_senderEndPoint = ipsender;
msg.m_bitLength = payloadBitLength; msg.m_bitLength = payloadBitLength;
Buffer.BlockCopy(m_receiveBuffer, ptr, msg.m_data, 0, payloadByteLength); Buffer.BlockCopy(m_receiveBuffer, ptr, msg.m_data, 0, payloadByteLength);
if (sender != null) if (sender != null)
@@ -509,7 +509,7 @@ namespace Lidgren.Network
m_executeFlushSendQueue = true; m_executeFlushSendQueue = true;
} }
internal void HandleIncomingDiscoveryRequest(double now, IPEndPoint senderEndpoint, int ptr, int payloadByteLength) internal void HandleIncomingDiscoveryRequest(double now, IPEndPoint senderEndPoint, int ptr, int payloadByteLength)
{ {
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryRequest)) if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryRequest))
{ {
@@ -518,12 +518,12 @@ namespace Lidgren.Network
Buffer.BlockCopy(m_receiveBuffer, ptr, dm.m_data, 0, payloadByteLength); Buffer.BlockCopy(m_receiveBuffer, ptr, dm.m_data, 0, payloadByteLength);
dm.m_receiveTime = now; dm.m_receiveTime = now;
dm.m_bitLength = payloadByteLength * 8; dm.m_bitLength = payloadByteLength * 8;
dm.m_senderEndpoint = senderEndpoint; dm.m_senderEndPoint = senderEndPoint;
ReleaseMessage(dm); ReleaseMessage(dm);
} }
} }
internal void HandleIncomingDiscoveryResponse(double now, IPEndPoint senderEndpoint, int ptr, int payloadByteLength) internal void HandleIncomingDiscoveryResponse(double now, IPEndPoint senderEndPoint, int ptr, int payloadByteLength)
{ {
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryResponse)) if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryResponse))
{ {
@@ -532,15 +532,15 @@ namespace Lidgren.Network
Buffer.BlockCopy(m_receiveBuffer, ptr, dr.m_data, 0, payloadByteLength); Buffer.BlockCopy(m_receiveBuffer, ptr, dr.m_data, 0, payloadByteLength);
dr.m_receiveTime = now; dr.m_receiveTime = now;
dr.m_bitLength = payloadByteLength * 8; dr.m_bitLength = payloadByteLength * 8;
dr.m_senderEndpoint = senderEndpoint; dr.m_senderEndPoint = senderEndPoint;
ReleaseMessage(dr); ReleaseMessage(dr);
} }
} }
private void ReceivedUnconnectedLibraryMessage(double now, IPEndPoint senderEndpoint, NetMessageType tp, int ptr, int payloadByteLength) private void ReceivedUnconnectedLibraryMessage(double now, IPEndPoint senderEndPoint, NetMessageType tp, int ptr, int payloadByteLength)
{ {
NetConnection shake; NetConnection shake;
if (m_handshakes.TryGetValue(senderEndpoint, out shake)) if (m_handshakes.TryGetValue(senderEndPoint, out shake))
{ {
shake.ReceivedHandshake(now, tp, ptr, payloadByteLength); shake.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return; return;
@@ -552,16 +552,16 @@ namespace Lidgren.Network
switch (tp) switch (tp)
{ {
case NetMessageType.Discovery: case NetMessageType.Discovery:
HandleIncomingDiscoveryRequest(now, senderEndpoint, ptr, payloadByteLength); HandleIncomingDiscoveryRequest(now, senderEndPoint, ptr, payloadByteLength);
return; return;
case NetMessageType.DiscoveryResponse: case NetMessageType.DiscoveryResponse:
HandleIncomingDiscoveryResponse(now, senderEndpoint, ptr, payloadByteLength); HandleIncomingDiscoveryResponse(now, senderEndPoint, ptr, payloadByteLength);
return; return;
case NetMessageType.NatIntroduction: case NetMessageType.NatIntroduction:
HandleNatIntroduction(ptr); HandleNatIntroduction(ptr);
return; return;
case NetMessageType.NatPunchMessage: case NetMessageType.NatPunchMessage:
HandleNatPunch(ptr, senderEndpoint); HandleNatPunch(ptr, senderEndPoint);
return; return;
case NetMessageType.ConnectResponse: case NetMessageType.ConnectResponse:
@@ -569,7 +569,7 @@ namespace Lidgren.Network
{ {
foreach (var hs in m_handshakes) foreach (var hs in m_handshakes)
{ {
if (hs.Key.Address.Equals(senderEndpoint.Address)) if (hs.Key.Address.Equals(senderEndPoint.Address))
{ {
if (hs.Value.m_connectionInitiator) if (hs.Value.m_connectionInitiator)
{ {
@@ -582,11 +582,11 @@ namespace Lidgren.Network
m_connectionLookup.Remove(hs.Key); m_connectionLookup.Remove(hs.Key);
m_handshakes.Remove(hs.Key); m_handshakes.Remove(hs.Key);
LogDebug("Detected host port change; rerouting connection to " + senderEndpoint); LogDebug("Detected host port change; rerouting connection to " + senderEndPoint);
hsconn.MutateEndpoint(senderEndpoint); hsconn.MutateEndPoint(senderEndPoint);
m_connectionLookup.Add(senderEndpoint, hsconn); m_connectionLookup.Add(senderEndPoint, hsconn);
m_handshakes.Add(senderEndpoint, hsconn); m_handshakes.Add(senderEndPoint, hsconn);
hsconn.ReceivedHandshake(now, tp, ptr, payloadByteLength); hsconn.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return; return;
@@ -595,17 +595,17 @@ namespace Lidgren.Network
} }
} }
LogWarning("Received unhandled library message " + tp + " from " + senderEndpoint); LogWarning("Received unhandled library message " + tp + " from " + senderEndPoint);
return; return;
case NetMessageType.Connect: case NetMessageType.Connect:
// proceed // proceed
break; break;
case NetMessageType.Disconnect: case NetMessageType.Disconnect:
// this is probably ok // this is probably ok
LogVerbose("Received Disconnect from unconnected source: " + senderEndpoint); LogVerbose("Received Disconnect from unconnected source: " + senderEndPoint);
return; return;
default: default:
LogWarning("Received unhandled library message " + tp + " from " + senderEndpoint); LogWarning("Received unhandled library message " + tp + " from " + senderEndPoint);
return; return;
} }
@@ -617,14 +617,14 @@ namespace Lidgren.Network
// server full // server full
NetOutgoingMessage full = CreateMessage("Server full"); NetOutgoingMessage full = CreateMessage("Server full");
full.m_messageType = NetMessageType.Disconnect; full.m_messageType = NetMessageType.Disconnect;
SendLibrary(full, senderEndpoint); SendLibrary(full, senderEndPoint);
return; return;
} }
// Ok, start handshake! // Ok, start handshake!
NetConnection conn = new NetConnection(this, senderEndpoint); NetConnection conn = new NetConnection(this, senderEndPoint);
conn.m_status = NetConnectionStatus.ReceivedInitiation; conn.m_status = NetConnectionStatus.ReceivedInitiation;
m_handshakes.Add(senderEndpoint, conn); m_handshakes.Add(senderEndPoint, conn);
conn.ReceivedHandshake(now, tp, ptr, payloadByteLength); conn.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return; return;
@@ -635,7 +635,7 @@ namespace Lidgren.Network
// LogDebug("Accepted connection " + conn); // LogDebug("Accepted connection " + conn);
conn.InitExpandMTU(NetTime.Now); conn.InitExpandMTU(NetTime.Now);
if (m_handshakes.Remove(conn.m_remoteEndpoint) == false) if (m_handshakes.Remove(conn.m_remoteEndPoint) == false)
LogWarning("AcceptConnection called but m_handshakes did not contain it!"); LogWarning("AcceptConnection called but m_handshakes did not contain it!");
lock (m_connections) lock (m_connections)
@@ -647,7 +647,7 @@ namespace Lidgren.Network
else else
{ {
m_connections.Add(conn); m_connections.Add(conn);
m_connectionLookup.Add(conn.m_remoteEndpoint, conn); m_connectionLookup.Add(conn.m_remoteEndPoint, conn);
} }
} }
} }

View File

@@ -217,7 +217,7 @@ namespace Lidgren.Network
om.m_isFragment = false; om.m_isFragment = false;
om.m_receiveTime = NetTime.Now; om.m_receiveTime = NetTime.Now;
om.m_senderConnection = null; om.m_senderConnection = null;
om.m_senderEndpoint = m_socket.LocalEndPoint as IPEndPoint; om.m_senderEndPoint = m_socket.LocalEndPoint as IPEndPoint;
om.m_bitLength = msg.LengthBits; om.m_bitLength = msg.LengthBits;
ReleaseMessage(om); ReleaseMessage(om);

View File

@@ -240,29 +240,29 @@ namespace Lidgren.Network
/// <summary> /// <summary>
/// Create a connection to a remote endpoint /// Create a connection to a remote endpoint
/// </summary> /// </summary>
public NetConnection Connect(IPEndPoint remoteEndpoint) public NetConnection Connect(IPEndPoint remoteEndPoint)
{ {
return Connect(remoteEndpoint, null); return Connect(remoteEndPoint, null);
} }
/// <summary> /// <summary>
/// Create a connection to a remote endpoint /// Create a connection to a remote endpoint
/// </summary> /// </summary>
public virtual NetConnection Connect(IPEndPoint remoteEndpoint, NetOutgoingMessage hailMessage) public virtual NetConnection Connect(IPEndPoint remoteEndPoint, NetOutgoingMessage hailMessage)
{ {
if (remoteEndpoint == null) if (remoteEndPoint == null)
throw new ArgumentNullException("remoteEndpoint"); throw new ArgumentNullException("remoteEndPoint");
lock (m_connections) lock (m_connections)
{ {
if (m_status == NetPeerStatus.NotRunning) if (m_status == NetPeerStatus.NotRunning)
throw new NetException("Must call Start() first"); throw new NetException("Must call Start() first");
if (m_connectionLookup.ContainsKey(remoteEndpoint)) if (m_connectionLookup.ContainsKey(remoteEndPoint))
throw new NetException("Already connected to that endpoint!"); throw new NetException("Already connected to that endpoint!");
NetConnection hs; NetConnection hs;
if (m_handshakes.TryGetValue(remoteEndpoint, out hs)) if (m_handshakes.TryGetValue(remoteEndPoint, out hs))
{ {
// already trying to connect to that endpoint; make another try // already trying to connect to that endpoint; make another try
switch (hs.m_status) switch (hs.m_status)
@@ -283,7 +283,7 @@ namespace Lidgren.Network
return hs; return hs;
} }
NetConnection conn = new NetConnection(this, remoteEndpoint); NetConnection conn = new NetConnection(this, remoteEndPoint);
conn.m_status = NetConnectionStatus.InitiatedConnect; conn.m_status = NetConnectionStatus.InitiatedConnect;
conn.m_localHailMessage = hailMessage; conn.m_localHailMessage = hailMessage;
@@ -291,7 +291,7 @@ namespace Lidgren.Network
conn.m_connectRequested = true; conn.m_connectRequested = true;
conn.m_connectionInitiator = true; conn.m_connectionInitiator = true;
m_handshakes.Add(remoteEndpoint, conn); m_handshakes.Add(remoteEndPoint, conn);
return conn; return conn;
} }

View File

@@ -34,7 +34,7 @@ namespace Lidgren.Network
/// </summary> /// </summary>
public static class NetUtility public static class NetUtility
{ {
public delegate void ResolveEndPointCallback(IPEndPoint endpoint); public delegate void ResolveEndPointCallback(IPEndPoint endPoint);
public delegate void ResolveAddressCallback(IPAddress adr); public delegate void ResolveAddressCallback(IPAddress adr);
/// <summary> /// <summary>
@@ -371,11 +371,11 @@ namespace Lidgren.Network
/// <summary> /// <summary>
/// Returns true if the IPEndPoint supplied is on the same subnet as this host /// Returns true if the IPEndPoint supplied is on the same subnet as this host
/// </summary> /// </summary>
public static bool IsLocal(IPEndPoint endpoint) public static bool IsLocal(IPEndPoint endPoint)
{ {
if (endpoint == null) if (endPoint == null)
return false; return false;
return IsLocal(endpoint.Address); return IsLocal(endPoint.Address);
} }
/// <summary> /// <summary>

View File

@@ -72,8 +72,8 @@
<Project>{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}</Project> <Project>{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}</Project>
<Name>Lidgren.Network</Name> <Name>Lidgren.Network</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\..\SamplesCommon\SamplesCommon\SamplesCommon.csproj"> <ProjectReference Include="..\..\..\SamplesCommon\SamplesCommon.csproj">
<Project>{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}</Project> <Project>{773069DA-B66E-4667-ADCB-0D215AD8CF3E}</Project>
<Name>SamplesCommon</Name> <Name>SamplesCommon</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>

View File

@@ -67,10 +67,10 @@ namespace DurableClient
Display("Received data?!"); Display("Received data?!");
break; break;
case NetIncomingMessageType.DiscoveryResponse: case NetIncomingMessageType.DiscoveryResponse:
Display("Got discovery response from " + msg.SenderEndpoint); Display("Got discovery response from " + msg.SenderEndPoint);
NetOutgoingMessage approval = Client.CreateMessage(); NetOutgoingMessage approval = Client.CreateMessage();
approval.Write("durableschmurable"); approval.Write("durableschmurable");
Client.Connect(msg.SenderEndpoint, approval); Client.Connect(msg.SenderEndPoint, approval);
break; break;
case NetIncomingMessageType.StatusChanged: case NetIncomingMessageType.StatusChanged:

View File

@@ -5,10 +5,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DurableClient", "DurableCli
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DurableServer", "DurableServer\DurableServer.csproj", "{5825BF6B-B344-4B00-8A25-95A42B89F7F9}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DurableServer", "DurableServer\DurableServer.csproj", "{5825BF6B-B344-4B00-8A25-95A42B89F7F9}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesCommon", "..\..\SamplesCommon\SamplesCommon\SamplesCommon.csproj", "{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "..\..\..\Lidgren.Network\Lidgren.Network.csproj", "{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "..\..\..\Lidgren.Network\Lidgren.Network.csproj", "{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesCommon", "..\..\SamplesCommon\SamplesCommon.csproj", "{773069DA-B66E-4667-ADCB-0D215AD8CF3E}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -39,16 +39,6 @@ Global
{5825BF6B-B344-4B00-8A25-95A42B89F7F9}.Release|Mixed Platforms.Build.0 = Release|x86 {5825BF6B-B344-4B00-8A25-95A42B89F7F9}.Release|Mixed Platforms.Build.0 = Release|x86
{5825BF6B-B344-4B00-8A25-95A42B89F7F9}.Release|x86.ActiveCfg = Release|x86 {5825BF6B-B344-4B00-8A25-95A42B89F7F9}.Release|x86.ActiveCfg = Release|x86
{5825BF6B-B344-4B00-8A25-95A42B89F7F9}.Release|x86.Build.0 = Release|x86 {5825BF6B-B344-4B00-8A25-95A42B89F7F9}.Release|x86.Build.0 = Release|x86
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|x86.ActiveCfg = Debug|Any CPU
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Any CPU.Build.0 = Release|Any CPU
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|x86.ActiveCfg = Release|Any CPU
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.Build.0 = Debug|Any CPU {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -59,6 +49,16 @@ Global
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Mixed Platforms.Build.0 = Release|Any CPU {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|x86.ActiveCfg = Release|Any CPU {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|x86.ActiveCfg = Release|Any CPU
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|x86.ActiveCfg = Debug|Any CPU
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Any CPU.Build.0 = Release|Any CPU
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -72,8 +72,8 @@
<Project>{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}</Project> <Project>{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}</Project>
<Name>Lidgren.Network</Name> <Name>Lidgren.Network</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\..\SamplesCommon\SamplesCommon\SamplesCommon.csproj"> <ProjectReference Include="..\..\..\SamplesCommon\SamplesCommon.csproj">
<Project>{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}</Project> <Project>{773069DA-B66E-4667-ADCB-0D215AD8CF3E}</Project>
<Name>SamplesCommon</Name> <Name>SamplesCommon</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>

View File

@@ -79,7 +79,7 @@ namespace DurableServer
break; break;
case NetIncomingMessageType.DiscoveryRequest: case NetIncomingMessageType.DiscoveryRequest:
// just send a no-info response // just send a no-info response
Server.SendDiscoveryResponse(null, msg.SenderEndpoint); Server.SendDiscoveryResponse(null, msg.SenderEndPoint);
break; break;
case NetIncomingMessageType.ConnectionApproval: case NetIncomingMessageType.ConnectionApproval:
string ok = msg.ReadString(); string ok = msg.ReadString();