Beispiel #1
0
        public override void Decode(byte[] packet)
        {
            ByteArray array = new ByteArray(packet);
            byte      type  = array.ReadByte();
            // Size of the packet PacketNumber is determined by the last 2 bits of the Type.
            int pnSize = (type & 0x03) + 1;

            Version = array.ReadUInt32();

            DCID = array.ReadByte();
            if (DCID > 0)
            {
                DestinationConnectionId = array.ReadByte();
            }

            SCID = array.ReadByte();
            if (SCID > 0)
            {
                SourceConnectionId = array.ReadByte();
            }

            TokenLength = array.ReadVariableInteger();
            if (TokenLength != 0)
            {
                Token = array.ReadBytes((int)TokenLength.Value);
            }

            Length       = array.ReadVariableInteger();
            PacketNumber = array.ReadBytes(pnSize);

            Length = Length - PacketNumber.Size;

            this.DecodeFrames(array);
        }
Beispiel #2
0
        public PacketCreator(GranularInteger connectionId, GranularInteger peerConnectionId)
        {
            _ns = new NumberSpace();

            _connectionId     = connectionId;
            _peerConnectionId = peerConnectionId;
        }
Beispiel #3
0
        public InitialPacket(GranularInteger destinationConnectionId, GranularInteger sourceConnectionId)
        {
            DestinationConnectionIdLength = destinationConnectionId.Size;
            DestinationConnectionId       = destinationConnectionId;

            SourceConnectionIdLength = sourceConnectionId.Size;
            SourceConnectionId       = sourceConnectionId;
        }
Beispiel #4
0
        public LongHeaderPacket(PacketType packetType, GranularInteger destinationConnectionId, GranularInteger sourceConnectionId)
        {
            PacketType = packetType;
            DestinationConnectionIdLength = destinationConnectionId.Size;
            DestinationConnectionId       = destinationConnectionId;

            SourceConnectionIdLength = sourceConnectionId.Size;
            SourceConnectionId       = sourceConnectionId;
        }
Beispiel #5
0
        public void TestGranularIntegerMaxValue()
        {
            GranularInteger integer = new GranularInteger(GranularInteger.MaxValue);

            byte[] bin = integer;
            UInt64 num = integer;

            Assert.IsNotNull(bin);
            Assert.AreEqual(bin.Length, 8);
            Assert.AreEqual(num, GranularInteger.MaxValue);
        }
Beispiel #6
0
        public void Test255()
        {
            GranularInteger integer = new GranularInteger(255);

            byte[] bin = integer;
            UInt64 num = integer;

            Assert.IsNotNull(bin);
            Assert.AreEqual(bin.Length, 1);
            Assert.AreEqual(bin[0], (byte)255);
            Assert.AreEqual(num, (UInt64)255);
        }
Beispiel #7
0
        public override void Decode(byte[] packet)
        {
            ByteArray array = new ByteArray(packet);
            byte      type  = array.ReadByte();

            DestinationConnectionId = array.ReadByte();

            int pnSize = (type & 0x03) + 1;

            PacketNumber = array.ReadBytes(pnSize);

            DecodeFrames(array);
        }
        public InitialPacket CreateInitialPacket(GranularInteger sourceConnectionId, GranularInteger destinationConnectionId)
        {
            InitialPacket packet = new InitialPacket(destinationConnectionId, sourceConnectionId);

            packet.PacketNumber            = 0;
            packet.SourceConnectionId      = sourceConnectionId;
            packet.DestinationConnectionId = destinationConnectionId;
            packet.Version = QuicVersion.CurrentVersion;

            int length  = packet.Encode().Length;
            int padding = QuicSettings.PMTU - length;

            for (int i = 0; i < padding; i++)
            {
                packet.AttachFrame(new PaddingFrame());
            }

            return(packet);
        }
Beispiel #9
0
 public ConnectionData(PacketWireTransfer pwt, GranularInteger connectionId, GranularInteger peerConnnectionId)
 {
     PWT              = pwt;
     ConnectionId     = connectionId;
     PeerConnectionId = peerConnnectionId;
 }
Beispiel #10
0
        /// <summary>
        /// Create a new connection
        /// </summary>
        /// <param name="connectionId"></param>
        /// <param name="peerConnectionId"></param>
        private void EstablishConnection(GranularInteger connectionId, GranularInteger peerConnectionId)
        {
            ConnectionData connection = new ConnectionData(_pwt, connectionId, peerConnectionId);

            _connection = new QuicConnection(connection);
        }