Design

aioquic aims to be an implementation of QUIC and HTTP/3 which is easy to read and to audit. Its protocol logic is written in plain, idiomatic Python, and it relies on well-established libraries for the parts best left to specialists, such as cryptographic primitives and QPACK header compression.

Sans-IO APIs

Both the QUIC and the HTTP/3 APIs follow the sans I/O pattern, leaving actual I/O operations to the API user. This approach has a number of advantages including making the code testable and allowing integration with different concurrency models.

Time

The protocol code goes a step further than the sans I/O pattern: it does not read the clock for its timing. Methods of the QUIC API which depend on time, such as receive_datagram() and datagrams_to_send(), take the current time as a now argument, and get_timer() tells the API user when to call handle_timer(). Loss detection, congestion control and idle timeouts all run on the time the API user provides. HTTP/3 has no timers of its own, and TLS reads the system clock only where the calendar date is needed: certificate validity and session ticket lifetimes.

This lets tests step through timers and packet loss in simulated time, without waiting, and lets the API user choose the clock.

Errors

aioquic keeps errors caused by the peer apart from errors in the use of its API.

Input from the peer must not raise exceptions to the API user. Depending on the RFC, malformed input either drops the packet or closes the connection with an error code, which the API user sees as a ConnectionTerminated event.

Misuse of the API raises an exception straight away, such as sending on a stream which was already ended. QUIC exceptions derive from QuicError, and HTTP/3 exceptions from H3Error.

TLS and encryption

aioquic implements TLS 1.3 itself, in Python, like QUIC and HTTP/3. This keeps the handshake as easy to read and audit as the QUIC code which drives it. It also gives QUIC what it needs and Python’s ssl module does not offer: TLS handshake messages without the record layer, and the traffic secrets from which packet protection keys are derived.

For cryptographic operations, aioquic relies on cryptography, which provides well-reviewed primitives, wrapped in a memory-safe fashion and accessible from Python. Working closely with the cryptography project has shaped both libraries: aioquic’s needs have led to new APIs and to faster per-packet encryption.