private SetStatus ( NetConnectionStatus status, string reason ) : void | ||
status | NetConnectionStatus | |
reason | string | |
Результат | void |
/// <summary> /// Create a connection to a remote endpoint /// </summary> public virtual NetConnection Connect(NetEndPoint remoteEndPoint, NetOutgoingMessage hailMessage) { if (remoteEndPoint == null) { throw new ArgumentNullException("remoteEndPoint"); } if (m_configuration.DualStack) { remoteEndPoint = NetUtility.MapToIPv6(remoteEndPoint); } lock (m_connections) { if (m_status == NetPeerStatus.NotRunning) { throw new NetException("Must call Start() first"); } if (m_connectionLookup.ContainsKey(remoteEndPoint)) { throw new NetException("Already connected to that endpoint!"); } NetConnection hs; if (m_handshakes.TryGetValue(remoteEndPoint, out hs)) { // already trying to connect to that endpoint; make another try switch (hs.m_status) { case NetConnectionStatus.InitiatedConnect: // send another connect hs.m_connectRequested = true; break; case NetConnectionStatus.RespondedConnect: // send another response hs.SendConnectResponse(NetTime.Now, false); break; default: // weird LogWarning("Weird situation; Connect() already in progress to remote endpoint; but hs status is " + hs.m_status); break; } return(hs); } NetConnection conn = new NetConnection(this, remoteEndPoint); conn.SetStatus(NetConnectionStatus.InitiatedConnect, "user called connect"); conn.m_localHailMessage = hailMessage; // handle on network thread conn.m_connectRequested = true; conn.m_connectionInitiator = true; m_handshakes.Add(remoteEndPoint, conn); return(conn); } }
internal void AddConnection(double now, NetConnection conn) { conn.SetStatus(NetConnectionStatus.Connecting, "Connecting"); lock (m_connections) { if (m_connections.Contains(conn)) { // already added conn.m_approved = true; // just to be sure return; } } LogWrite("Adding connection " + conn); // send response; even if connected OutgoingNetMessage response = CreateSystemMessage(NetSystemType.ConnectResponse); if (conn.LocalHailData != null) { response.m_data.Write(conn.LocalHailData); } conn.m_unsentMessages.Enqueue(response); conn.m_handshakeInitiated = now; conn.m_approved = true; lock (m_connections) m_connections.Add(conn); m_connectionLookup[conn.m_remoteEndPoint] = conn; }
internal void AddConnection(double now, NetConnection conn) { conn.SetStatus(NetConnectionStatus.Connecting, "Connecting"); if (m_connections.Contains(conn)) { // already added conn.m_approved = true; // just to be sure // TODO: is this really needed? return; } LogWrite("Adding connection " + conn); // send response; even if connected var responseBuffer = GetTempBuffer(); responseBuffer.Write(m_localRndSignature); responseBuffer.Write(conn.m_localRndSeqNr); responseBuffer.Write(conn.m_remoteRndSignature); responseBuffer.Write(conn.m_remoteRndSeqNr); double localTimeSent = conn.m_connectLocalSentTime; responseBuffer.Write(localTimeSent); double remoteTimeRecv = conn.m_connectRemoteRecvTime; responseBuffer.Write(remoteTimeRecv); double remoteTimeSent = NetTime.Now + m_localTimeOffset; responseBuffer.Write(remoteTimeSent); if (conn.LocalHailData != null) { responseBuffer.Write(conn.LocalHailData); } conn.m_handshakeInitiated = remoteTimeSent; conn.SendSingleUnreliableSystemMessage(NetSystemType.ConnectResponse, responseBuffer); conn.m_approved = true; m_connections.Add(conn); m_connectionLookup.Add(conn.m_remoteEndPoint, conn); m_pendingLookup.Remove(conn.m_remoteEndPoint); }
internal void AddConnection(double now, NetConnection conn) { conn.SetStatus(NetConnectionStatus.Connecting, "Connecting"); LogWrite("Adding connection " + conn); // send response; even if connected OutgoingNetMessage response = CreateSystemMessage(NetSystemType.ConnectResponse); if (conn.LocalHailData != null) response.m_data.Write(conn.LocalHailData); conn.m_unsentMessages.Enqueue(response); conn.m_handshakeInitiated = now; conn.m_approved = true; lock (m_connections) m_connections.Add(conn); m_connectionLookup.Add(conn.m_remoteEndPoint, conn); }