Asyncio API¶
Use the top-level imports shown below.
connect¶
connect
async
¶
connect(host, port, *, configuration=None, create_protocol=QuicConnectionProtocol, session_ticket_handler=None, stream_handler=None, wait_connected=True, local_port=0)
Connect to a QUIC server at the given host and port.
:meth:connect() returns an awaitable. Awaiting it yields a
:class:~qh3.asyncio.QuicConnectionProtocol which can be used to
create streams.
:func:connect also accepts the following optional arguments:
configurationis a :class:~qh3.quic.configuration.QuicConfigurationconfiguration object.create_protocolallows customizing the :class:~asyncio.Protocolthat manages the connection. It should be a callable or class accepting the same arguments as :class:~qh3.asyncio.QuicConnectionProtocoland returning an instance of :class:~qh3.asyncio.QuicConnectionProtocolor a subclass.session_ticket_handleris a callback which is invoked by the TLS engine when a new session ticket is received.stream_handleris a callback which is invoked whenever a stream is created. It must accept two arguments: a :class:asyncio.StreamReaderand a :class:asyncio.StreamWriter.local_portis the UDP port number that this client wants to bind.
serve¶
serve
async
¶
serve(host, port, *, configuration, create_protocol=QuicConnectionProtocol, session_ticket_fetcher=None, session_ticket_handler=None, retry=False, stream_handler=None)
Start a QUIC server at the given host and port.
:func:serve requires a :class:~qh3.quic.configuration.QuicConfiguration
containing TLS certificate and private key as the configuration argument.
:func:serve also accepts the following optional arguments:
create_protocolallows customizing the :class:~asyncio.Protocolthat manages the connection. It should be a callable or class accepting the same arguments as :class:~qh3.asyncio.QuicConnectionProtocoland returning an instance of :class:~qh3.asyncio.QuicConnectionProtocolor a subclass.session_ticket_fetcheris a callback which is invoked by the TLS engine when a session ticket is presented by the peer. It should return the session ticket with the specified ID orNoneif it is not found.session_ticket_handleris a callback which is invoked by the TLS engine when a new session ticket is issued. It should store the session ticket for future lookup.retryspecifies whether client addresses should be validated prior to the cryptographic handshake using a retry packet.stream_handleris a callback which is invoked whenever a stream is created. It must accept two arguments: a :class:asyncio.StreamReaderand a :class:asyncio.StreamWriter.
The returned server handle supports close(). Its concrete implementation is
not a public construction or subclassing API.
QuicConnectionProtocol¶
QuicConnectionProtocol
¶
Bases: DatagramProtocol
change_connection_id
¶
Change the connection ID used to communicate with the peer.
The previous connection ID will be retired.
connect
¶
Initiate the TLS handshake.
This method can only be called for clients and a single time.
create_stream
async
¶
Create a QUIC stream and return a pair of (reader, writer) objects.
The returned reader and writer objects are instances of
:class:asyncio.StreamReader and :class:asyncio.StreamWriter classes.
quic_event_received
¶
Called when a QUIC event is received.
Reimplement this in your subclass to handle the events.