Esempio n. 1
0
    def datagram_received(self, datagram, addr):
        buf = Buffer(data=datagram)
        header = pull_quic_header(buf, host_cid_length=8)

        # version negotiation
        if (header.version is not None
                and header.version not in QuicConnection.supported_versions):
            self._transport.sendto(
                encode_quic_version_negotiation(
                    source_cid=header.destination_cid,
                    destination_cid=header.source_cid,
                    supported_versions=QuicConnection.supported_versions,
                ),
                addr,
            )
            return

        connection = self._connections.get(header.destination_cid, None)
        if connection is None and header.packet_type == PACKET_TYPE_INITIAL:
            # create new connection
            connection = QuicConnection(is_client=False, **self._kwargs)
            connection.connection_made(QuicConnectionTransport(self, addr))
            connection.stream_created_cb = self.stream_created
            self._connections[connection.host_cid] = connection
            logger.info("%s New connection from %s" %
                        (connection_id(connection), addr))

        if connection is not None:
            connection.datagram_received(datagram, addr)
Esempio n. 2
0
    def test_datagram_received_wrong_destination_cid(self):
        client = QuicConnection(is_client=True)
        client_transport = FakeTransport()
        client.connection_made(client_transport)
        self.assertEqual(client_transport.sent, 1)

        client.datagram_received(load("retry.bin"), None)
        self.assertEqual(client_transport.sent, 1)
Esempio n. 3
0
    def test_datagram_received_retry(self):
        client = QuicConnection(is_client=True)
        client.host_cid = binascii.unhexlify("c98343fe8f5f0ff4")
        client.peer_cid = binascii.unhexlify("85abb547bf28be97")

        client_transport = FakeTransport()
        client.connection_made(client_transport)
        self.assertEqual(client_transport.sent, 1)

        client.datagram_received(load("retry.bin"), None)
        self.assertEqual(client_transport.sent, 2)
Esempio n. 4
0
    def test_version_negotiation_ok(self):
        client = QuicConnection(is_client=True)

        client_transport = FakeTransport()
        client.connection_made(client_transport)
        self.assertEqual(client_transport.sent, 1)

        # found a common version, retry
        client.datagram_received(
            encode_quic_version_negotiation(
                source_cid=client.peer_cid,
                destination_cid=client.host_cid,
                supported_versions=[QuicProtocolVersion.DRAFT_19],
            ),
            None,
        )
        self.assertEqual(client_transport.sent, 2)
Esempio n. 5
0
    def test_version_negotiation_fail(self):
        client = QuicConnection(is_client=True)

        client_transport = FakeTransport()
        client.connection_made(client_transport)
        self.assertEqual(client_transport.sent, 1)

        # no common version, no retry
        client.datagram_received(
            encode_quic_version_negotiation(
                source_cid=client.peer_cid,
                destination_cid=client.host_cid,
                supported_versions=[0xFF000011],  # DRAFT_16
            ),
            None,
        )
        self.assertEqual(client_transport.sent, 1)
Esempio n. 6
0
    def test_datagram_received_wrong_version(self):
        client = QuicConnection(is_client=True)
        client_transport = FakeTransport()
        client.connection_made(client_transport)
        self.assertEqual(client_transport.sent, 1)

        buf = Buffer(capacity=1300)
        push_quic_header(
            buf,
            QuicHeader(
                version=0xFF000011,  # DRAFT_16
                packet_type=PACKET_TYPE_INITIAL |
                (PACKET_NUMBER_SEND_SIZE - 1),
                destination_cid=client.host_cid,
                source_cid=client.peer_cid,
            ),
        )
        buf.seek(1300)
        client.datagram_received(buf.data, None)
        self.assertEqual(client_transport.sent, 1)