Exemplo n.º 1
0
        private void HandleInitialFrames(Packet packet)
        {
            List <Frame> frames = packet.GetFrames();

            for (int i = frames.Count - 1; i > 0; i--)
            {
                Frame frame = frames[i];
                if (frame is ConnectionCloseFrame)
                {
                    ConnectionCloseFrame ccf = (ConnectionCloseFrame)frame;

                    throw new QuicConnectivityException(ccf.ReasonPhrase);
                }

                if (frame is MaxStreamsFrame)
                {
                    MaxStreamsFrame msf = (MaxStreamsFrame)frame;
                    _maximumStreams = msf.MaximumStreams.Value;
                }

                // Break out if the first Padding Frame has been reached
                if (frame is PaddingFrame)
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
        private void OnConnectionCloseFrame(Frame frame)
        {
            ConnectionCloseFrame ccf = (ConnectionCloseFrame)frame;

            _state     = ConnectionState.Draining;
            _lastError = ccf.ReasonPhrase;
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            byte[]          bytes    = new VariableInteger(12345);
            VariableInteger integer  = bytes;
            UInt64          uinteger = integer;
            int             size     = VariableInteger.Size(bytes[0]);

            InitialPacket packet = new InitialPacket()
            {
                Version                 = 16,
                SourceConnectionId      = 124,
                DestinationConnectionId = 0,
                PacketNumber            = 777521,
                TokenLength             = 0
            };

            packet = new PacketCreator().CreateInitialPacket(124, 0);

            ConnectionCloseFrame frame     = new ConnectionCloseFrame(ErrorCode.SERVER_BUSY, "The server is too busy to process your request.");
            MaxStreamIdFrame     msidframe = new MaxStreamIdFrame(144123, StreamType.ClientUnidirectional);

            //packet.AttachFrame(frame);
            packet.AttachFrame(msidframe);

            byte[] data = packet.Encode();
            string b64  = ToBase64(data);

            byte[] shpdata1 = new byte[] { 1, 1, 2, 3, 5, 8 };
            byte[] shpdata2 = new byte[] { 13, 21, 34, 55, 89, 144 };

            ShortHeaderPacket shp = new ShortHeaderPacket();

            shp.DestinationConnectionId = 124;
            shp.PacketNumber            = 2;

            shp.AttachFrame(new StreamFrame()
            {
                StreamId = 1, Length = new VariableInteger((UInt64)shpdata2.Length), StreamData = shpdata2, Offset = 6, EndOfStream = true
            });
            shp.AttachFrame(new StreamFrame()
            {
                StreamId = 1, Length = new VariableInteger((UInt64)shpdata1.Length), StreamData = shpdata1, Offset = 0
            });

            string shpb64 = ToBase64(shp.Encode());

            packet.Decode(data);

            byte[] ccfData = frame.Encode();
            frame.Decode(new ByteArray(ccfData));

            byte[]   streamIdData = new StreamId(123, StreamType.ClientUnidirectional);
            StreamId streamId     = streamIdData;

            QuicListener listener = new QuicListener(11000);

            listener.OnClientConnected += Listener_OnClientConnected;
            listener.Start();
        }
Exemplo n.º 4
0
        public void ConnectionCloseFrameTest()
        {
            var ccf = new ConnectionCloseFrame(ErrorCode.PROTOCOL_VIOLATION, 0x00, ErrorConstants.PMTUNotReached);

            byte[] data = ccf.Encode();

            var nccf = new ConnectionCloseFrame();

            nccf.Decode(new ByteArray(data));

            Assert.AreEqual(ccf.ActualType, nccf.ActualType);
            Assert.AreEqual(ccf.FrameType.Value, nccf.FrameType.Value);
            Assert.AreEqual(ccf.ReasonPhraseLength.Value, nccf.ReasonPhraseLength.Value);
            Assert.AreEqual(ccf.ReasonPhrase, nccf.ReasonPhrase);
        }
Exemplo n.º 5
0
        public Frame GetFrame()
        {
            Frame result;
            byte  frameType = _array.PeekByte();

            switch (frameType)
            {
            case 0x00: result = new PaddingFrame(); break;

            case 0x01: result = new RSTStreamFrame(); break;

            case 0x02: result = new ConnectionCloseFrame(); break;

            case 0x06: result = new MaxStreamIdFrame(); break;

            case 0x10: result = new StreamFrame(); break;

            case 0x11: result = new StreamFrame(); break;

            case 0x12: result = new StreamFrame(); break;

            case 0x13: result = new StreamFrame(); break;

            case 0x14: result = new StreamFrame(); break;

            case 0x15: result = new StreamFrame(); break;

            case 0x16: result = new StreamFrame(); break;

            case 0x17: result = new StreamFrame(); break;

            default: result = null; break;
            }

            if (result != null)
            {
                result.Decode(_array);
            }

            return(result);
        }
Exemplo n.º 6
0
        public Frame GetFrame()
        {
            Frame result;
            var   frameType = _array.PeekByte();

            switch (frameType)
            {
            case 0x00:
                result = new PaddingFrame();
                break;

            case 0x01:
                result = new PingFrame();
                break;

            case 0x02:
                result = new AckFrame();
                break;

            case 0x03:
                result = new AckFrame();
                break;

            case 0x04:
                result = new ResetStreamFrame();
                break;

            case 0x05:
                result = new StopSendingFrame();
                break;

            case 0x06:
                result = new CryptoFrame();
                break;

            case 0x07:
                result = new NewTokenFrame();
                break;

            case 0x08:
                result = new StreamFrame();
                break;

            case 0x09:
                result = new StreamFrame();
                break;

            case 0x0a:
                result = new StreamFrame();
                break;

            case 0x0b:
                result = new StreamFrame();
                break;

            case 0x0c:
                result = new StreamFrame();
                break;

            case 0x0d:
                result = new StreamFrame();
                break;

            case 0x0e:
                result = new StreamFrame();
                break;

            case 0x0f:
                result = new StreamFrame();
                break;

            case 0x10:
                result = new MaxDataFrame();
                break;

            case 0x11:
                result = new MaxStreamDataFrame();
                break;

            case 0x12:
                result = new MaxStreamsFrame();
                break;

            case 0x13:
                result = new MaxStreamsFrame();
                break;

            case 0x14:
                result = new DataBlockedFrame();
                break;

            case 0x15:
                result = new StreamDataBlockedFrame();
                break;

            case 0x16:
                result = new StreamsBlockedFrame();
                break;

            case 0x17:
                result = new StreamsBlockedFrame();
                break;

            case 0x18:
                result = new NewConnectionIdFrame();
                break;

            case 0x19:
                result = new RetireConnectionIdFrame();
                break;

            case 0x1a:
                result = new PathChallengeFrame();
                break;

            case 0x1b:
                result = new PathResponseFrame();
                break;

            case 0x1c:
                result = new ConnectionCloseFrame();
                break;

            case 0x1d:
                result = new ConnectionCloseFrame();
                break;

            default:
                result = null;
                break;
            }

            if (result != null)
            {
                result.Decode(_array);
            }

            return(result);
        }