How to use the aioquic.quic.connection.QuicConnection function in aioquic

To help you get started, we’ve selected a few aioquic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aiortc / aioquic / tests / test_connection.py View on Github external
def create_standalone_client(self, **client_options):
    client = QuicConnection(
        configuration=QuicConfiguration(
            is_client=True, quic_logger=QuicLogger(), **client_options
        )
    )
    client._ack_delay = 0

    # kick-off handshake
    client.connect(SERVER_ADDR, now=time.time())
    self.assertEqual(drop(client), 1)

    return client
github aiortc / aioquic / tests / test_connection.py View on Github external
def test_connect_with_loss_1(self):
        """
        Check connection is established even in the client's INITIAL is lost.
        """

        def datagram_sizes(items):
            return [len(x[0]) for x in items]

        client_configuration = QuicConfiguration(is_client=True)
        client_configuration.load_verify_locations(cafile=SERVER_CACERTFILE)

        client = QuicConnection(configuration=client_configuration)
        client._ack_delay = 0

        server_configuration = QuicConfiguration(is_client=False)
        server_configuration.load_cert_chain(SERVER_CERTFILE, SERVER_KEYFILE)

        server = QuicConnection(configuration=server_configuration)
        server._ack_delay = 0

        # client sends INITIAL
        now = 0.0
        client.connect(SERVER_ADDR, now=now)
        items = client.datagrams_to_send(now=now)
        self.assertEqual(datagram_sizes(items), [1280])
        self.assertEqual(client.get_timer(), 1.0)

        # INITIAL is lost
github aiortc / aioquic / tests / test_connection.py View on Github external
def test_connect_with_loss_2(self):
        def datagram_sizes(items):
            return [len(x[0]) for x in items]

        client_configuration = QuicConfiguration(is_client=True)
        client_configuration.load_verify_locations(cafile=SERVER_CACERTFILE)

        client = QuicConnection(configuration=client_configuration)
        client._ack_delay = 0

        server_configuration = QuicConfiguration(is_client=False)
        server_configuration.load_cert_chain(SERVER_CERTFILE, SERVER_KEYFILE)

        server = QuicConnection(configuration=server_configuration)
        server._ack_delay = 0

        # client sends INITIAL
        now = 0.0
        client.connect(SERVER_ADDR, now=now)
        items = client.datagrams_to_send(now=now)
        self.assertEqual(datagram_sizes(items), [1280])
        self.assertEqual(client.get_timer(), 1.0)

        # server receives INITIAL, sends INITIAL + HANDSHAKE but second datagram is lost
github aiortc / aioquic / tests / test_connection.py View on Github external
def test_connect_with_loss_2(self):
        def datagram_sizes(items):
            return [len(x[0]) for x in items]

        client_configuration = QuicConfiguration(is_client=True)
        client_configuration.load_verify_locations(cafile=SERVER_CACERTFILE)

        client = QuicConnection(configuration=client_configuration)
        client._ack_delay = 0

        server_configuration = QuicConfiguration(is_client=False)
        server_configuration.load_cert_chain(SERVER_CERTFILE, SERVER_KEYFILE)

        server = QuicConnection(configuration=server_configuration)
        server._ack_delay = 0

        # client sends INITIAL
        now = 0.0
        client.connect(SERVER_ADDR, now=now)
        items = client.datagrams_to_send(now=now)
        self.assertEqual(datagram_sizes(items), [1280])
        self.assertEqual(client.get_timer(), 1.0)

        # server receives INITIAL, sends INITIAL + HANDSHAKE but second datagram is lost
        now = 0.1
        server.receive_datagram(items[0][0], CLIENT_ADDR, now=now)
        items = server.datagrams_to_send(now=now)
        self.assertEqual(datagram_sizes(items), [1280, 1084])
        self.assertEqual(server.get_timer(), 1.1)
        self.assertEqual(len(server._loss.spaces[0].sent_packets), 1)
github aiortc / aioquic / tests / test_connection.py View on Github external
client_options={},
    client_patch=lambda x: None,
    handshake=True,
    server_kwargs={},
    server_certfile=SERVER_CERTFILE,
    server_keyfile=SERVER_KEYFILE,
    server_options={},
    server_patch=lambda x: None,
    transport_options={},
):
    client_configuration = QuicConfiguration(
        is_client=True, quic_logger=QuicLogger(), **client_options
    )
    client_configuration.load_verify_locations(cafile=SERVER_CACERTFILE)

    client = QuicConnection(configuration=client_configuration, **client_kwargs)
    client._ack_delay = 0
    client_patch(client)

    server_configuration = QuicConfiguration(
        is_client=False, quic_logger=QuicLogger(), **server_options
    )
    server_configuration.load_cert_chain(server_certfile, server_keyfile)

    server = QuicConnection(configuration=server_configuration, **server_kwargs)
    server._ack_delay = 0
    server_patch(server)

    # perform handshake
    if handshake:
        client.connect(SERVER_ADDR, now=time.time())
        for i in range(3):
github aiortc / aioquic / tests / test_connection.py View on Github external
Check connection is established even in the client's INITIAL is lost.
        """

        def datagram_sizes(items):
            return [len(x[0]) for x in items]

        client_configuration = QuicConfiguration(is_client=True)
        client_configuration.load_verify_locations(cafile=SERVER_CACERTFILE)

        client = QuicConnection(configuration=client_configuration)
        client._ack_delay = 0

        server_configuration = QuicConfiguration(is_client=False)
        server_configuration.load_cert_chain(SERVER_CERTFILE, SERVER_KEYFILE)

        server = QuicConnection(configuration=server_configuration)
        server._ack_delay = 0

        # client sends INITIAL
        now = 0.0
        client.connect(SERVER_ADDR, now=now)
        items = client.datagrams_to_send(now=now)
        self.assertEqual(datagram_sizes(items), [1280])
        self.assertEqual(client.get_timer(), 1.0)

        # INITIAL is lost
        now = 1.0
        client.handle_timer(now=now)
        items = client.datagrams_to_send(now=now)
        self.assertEqual(datagram_sizes(items), [1280])
        self.assertEqual(client.get_timer(), 3.0)
github aiortc / aioquic / tests / test_connection.py View on Github external
):
    client_configuration = QuicConfiguration(
        is_client=True, quic_logger=QuicLogger(), **client_options
    )
    client_configuration.load_verify_locations(cafile=SERVER_CACERTFILE)

    client = QuicConnection(configuration=client_configuration, **client_kwargs)
    client._ack_delay = 0
    client_patch(client)

    server_configuration = QuicConfiguration(
        is_client=False, quic_logger=QuicLogger(), **server_options
    )
    server_configuration.load_cert_chain(server_certfile, server_keyfile)

    server = QuicConnection(configuration=server_configuration, **server_kwargs)
    server._ack_delay = 0
    server_patch(server)

    # perform handshake
    if handshake:
        client.connect(SERVER_ADDR, now=time.time())
        for i in range(3):
            roundtrip(client, server)

    yield client, server

    # close
    client.close()
    server.close()
github pgjones / hypercorn / hypercorn / protocol / quic.py View on Github external
def __init__(
        self,
        config: Config,
        server: Optional[Tuple[str, int]],
        spawn_app: Callable[[dict, Callable], Awaitable[Callable]],
        send: Callable[[Event], Awaitable[None]],
        call_at: Callable[[float, Callable], None],
        now: Callable[[], float],
    ) -> None:
        self.call_at = call_at
        self.config = config
        self.connections: Dict[bytes, QuicConnection] = {}
        self.http_connections: Dict[QuicConnection, H3Protocol] = {}
        self.now = now
        self.send = send
        self.server = server
        self.spawn_app = spawn_app

        self.quic_config = QuicConfiguration(alpn_protocols=["h3-23"], is_client=False)
        self.quic_config.load_cert_chain(certfile=config.certfile, keyfile=config.keyfile)
github pgjones / hypercorn / hypercorn / protocol / quic.py View on Github external
):
                data = encode_quic_version_negotiation(
                    source_cid=header.destination_cid,
                    destination_cid=header.source_cid,
                    supported_versions=self.quic_config.supported_versions,
                )
                await self.send(RawData(data=data, address=event.address))
                return

            connection = self.connections.get(header.destination_cid)
            if (
                connection is None
                and len(event.data) >= 1200
                and header.packet_type == PACKET_TYPE_INITIAL
            ):
                connection = QuicConnection(
                    configuration=self.quic_config, original_connection_id=None
                )
                self.connections[header.destination_cid] = connection
                self.connections[connection.host_cid] = connection

            if connection is not None:
                connection.receive_datagram(event.data, event.address, now=self.now())
                await self._handle_events(connection, event.address)
        elif isinstance(event, Closed):
            pass