/// <summary> /// Receives a pong and updates connection timings. /// </summary> internal void OnReceivePong(long curTime, byte pongSeq, byte drop) { // Reject it if it's too old, including statistics for it long creationTime = this.outgoingPing.ConsumePong(pongSeq); if (creationTime < 0) { return; } long diff = curTime - creationTime; if (diff < 0) { return; } this.lastPacketRecvTime = curTime; this.lastPongRecvTime = curTime; this.pingWindow[this.pingWindowIndex] = (int)diff; this.pingWindowIndex = (this.pingWindowIndex + 1) % this.pingWindow.Length; // Recompute since it may be read on the main thread this.Ping = NetTraffic.PingAverage(this.pingWindow); this.RemoteDrop = drop / (float)NetTraffic.LOSS_BITS; }
internal NetPeer(IPEndPoint endPoint, string token, bool isClient, long creationTick) { // Probably no need to pool this class since users may want to hold on // to them after closing and they aren't created all that often anyway ClosedByUser = false; payloadSeqOut = 0; AckRequested = false; traffic = new NetTraffic(creationTick); outgoing = new Queue <NetEvent>(); this.endPoint = endPoint; this.isClient = isClient; this.token = token; notificationSeq = 1; if (isClient) // Client peers are created after a successful connection { status = NetPeerStatus.Connected; } else // Host peers are created in the process of to connecting to them { status = NetPeerStatus.Connecting; } }
internal NetPeer( IPEndPoint endPoint, string token, bool isClient, long creationTick) { // Probably no need to pool this class since users may want to hold on // to them after closing and they aren't created all that often anyway this.ClosedByUser = false; this.payloadSeqOut = 0; this.AckRequested = false; this.traffic = new NetTraffic(creationTick); this.outgoing = new Queue<NetEvent>(); this.endPoint = endPoint; this.isClient = isClient; this.token = token; this.notificationSeq = 1; if (isClient) // Client peers are created after a successful connection this.status = NetPeerStatus.Connected; else // Host peers are created in the process of to connecting to them this.status = NetPeerStatus.Connecting; }