Ejemplo n.º 1
0
        private bool AcceptIncomingPacket(SeqNo seq)
        {
            if (_isFirstIncomingPacketAck)
            {
                _incomingPacketAck = seq - 1;
                _incomingPacketAckBuffer.ClearAll();
                _isFirstIncomingPacketAck = false;
            }

            var diff = seq.CompareTo(_incomingPacketAck);

            if (diff == 0)
            {
                // Already received packet
                return(false);
            }
            else if (diff > 0)
            {
                _incomingPacketAck = seq;

                if (diff < _incomingPacketAckBuffer.Capacity)
                {
                    // New packet
                    _incomingPacketAckBuffer.LeftShift(diff);
                }
                else
                {
                    // Early packet but still ok
                    _incomingPacketAckBuffer.ClearAll();
                }

                _incomingPacketAckBuffer.Set(0);

                return(true);
            }
            else
            {
                diff *= -1;
                if (diff < _incomingPacketAckBuffer.Capacity)
                {
                    if (_incomingPacketAckBuffer[diff])
                    {
                        // Already received packet
                        return(false);
                    }
                    else
                    {
                        // New packet
                        _incomingPacketAckBuffer.Set(diff);
                        return(true);
                    }
                }
                else
                {
                    // Late packet
                    return(false);
                }
            }
        }