/// <summary> /// request retransmission of lost sequences /// </summary> /// <param name="rcvdSeq">the sequence of the packet that was just received.</param> private void DoRequestForRetransmission(uint rcvdSeq) { var desiredSeq = lastReceivedPacketSequence + 1; List <uint> needSeq = new List <uint>(); needSeq.Add(desiredSeq); uint bottom = desiredSeq + 1; for (uint a = bottom; a < rcvdSeq; a++) { if (!outOfOrderPackets.ContainsKey(a)) { needSeq.Add(a); } } ServerPacket reqPacket = new ServerPacket(); byte[] reqData = new byte[4 + (needSeq.Count * 4)]; MemoryStream msReqData = new MemoryStream(reqData); msReqData.Write(BitConverter.GetBytes((uint)needSeq.Count), 0, 4); needSeq.ForEach(k => msReqData.Write(BitConverter.GetBytes(k), 0, 4)); reqPacket.Data = msReqData; reqPacket.Header.Flags = PacketHeaderFlags.RequestRetransmit; EnqueueSend(reqPacket); LastRequestForRetransmitTime = DateTime.Now; packetLog.DebugFormat("[{0}] Requested retransmit of {1}", session.LoggingIdentifier, needSeq.Select(k => k.ToString()).Aggregate((a, b) => a + ", " + b)); NetworkStatistics.S2C_RequestsForRetransmit_Aggregate_Increment(); }
const uint MaxNumNakSeqIds = 115; //464 + header = 484; (464 - 4) / 4 /// <summary> /// request retransmission of lost sequences /// </summary> /// <param name="rcvdSeq">the sequence of the packet that was just received.</param> private void DoRequestForRetransmission(uint rcvdSeq) { var desiredSeq = lastReceivedPacketSequence + 1; List <uint> needSeq = new List <uint>(); needSeq.Add(desiredSeq); uint bottom = desiredSeq + 1; if (rcvdSeq < bottom || rcvdSeq - bottom > CryptoSystem.MaximumEffortLevel) { session.Terminate(SessionTerminationReason.AbnormalSequenceReceived); return; } uint seqIdCount = 1; for (uint a = bottom; a < rcvdSeq; a++) { if (!outOfOrderPackets.ContainsKey(a)) { needSeq.Add(a); seqIdCount++; if (seqIdCount >= MaxNumNakSeqIds) { break; } } } ServerPacket reqPacket = new ServerPacket(); byte[] reqData = new byte[4 + (needSeq.Count * 4)]; MemoryStream msReqData = new MemoryStream(reqData, 0, reqData.Length, true, true); msReqData.Write(BitConverter.GetBytes((uint)needSeq.Count), 0, 4); needSeq.ForEach(k => msReqData.Write(BitConverter.GetBytes(k), 0, 4)); reqPacket.Data = msReqData; reqPacket.Header.Flags = PacketHeaderFlags.RequestRetransmit; EnqueueSend(reqPacket); LastRequestForRetransmitTime = DateTime.UtcNow; packetLog.DebugFormat("[{0}] Requested retransmit of {1}", session.LoggingIdentifier, needSeq.Select(k => k.ToString()).Aggregate((a, b) => a + ", " + b)); NetworkStatistics.S2C_RequestsForRetransmit_Aggregate_Increment(); }