Пример #1
0
        public ReceivedPacket Receive(byte[] packet)
        {
            int offset     = 0;
            var packetType = (PacketType)ByteUtils.ReadByte(packet, ref offset);

            // todo replace assert with log
            Assert.AreEqual(packetType, PacketType.Notify);

            ushort sequence         = ByteUtils.ReadUShort(packet, ref offset);
            ushort receivedSequence = ByteUtils.ReadUShort(packet, ref offset);
            uint   receivedMask     = ByteUtils.ReadUInt(packet, ref offset);

            // todo replace assert with log
            Assert.AreEqual(offset, HEADER_SIZE);

            if (SetReievedNumbers(sequence))
            {
                return(new ReceivedPacket
                {
                    isValid = true,
                    receivedSequence = receivedSequence,
                    receivedMask = receivedMask,
                });
            }
            else
            {
                return(ReceivedPacket.Invalid());
            }
        }
Пример #2
0
        public void Receive(byte[] packet)
        {
            ReceivedPacket received = ackSystem.Receive(packet);

            if (!received.isValid)
            {
                return;
            }

            NotifySent(received);
        }
Пример #3
0
        private void NotifySent(ReceivedPacket received)
        {
            while (sent.Count > 0)
            {
                NotifyToken token = sent.Peek();

                int distance = (int)ackSystem.sequencer.Distance(received.receivedSequence, token.Sequence);

                // negative distance means next is sent after last ack, so nothing to ack yet
                if (distance < 0)
                {
                    return;
                }

                // positive distance means it should have been acked, or mark it as lost
                sent.Dequeue();

                // if distance above size then it is outside of mask, so set as lost
                bool lost = OutsideOfMask(distance) || NotInMask(distance, received.receivedMask);

                token.Notify(!lost);
            }
        }
Пример #4
0
        internal void ReceiveAck(byte[] array)
        {
            ReceivedPacket received = ackSystem.ReceiveAck(array);

            NotifySent(received);
        }