Skip to content

Architecture

André Borchert edited this page Nov 13, 2026 · 5 revisions

Architecture

The repository holds two independent implementations of the same protocol, written from the same draft and sharing no source files. They are built, tested and released separately; the version number is the only thing tying them together.

Swift package C99 library
Target macOS 26+, Network.framework QUIC Portable C99 over POSIX/Winsock sockets and system OpenSSL
Manifest Package.swift (root), Swift/Package.swift (nested) C99/CMakeLists.txt
Transport Network.framework QUIC C99/src/runtime/udp.c
Crypto/TLS Apple Security and CryptoKit; TLS 1.3 state in WebTransportTLSCore OpenSSL primitives; TLS 1.3 handshake written in C99/src/tls/
Apps WebTransportClient, WebTransportServer wt-client-c99, wt-server-c99, wt-conformance-c99

Neither library is a wrapper around the other. A change in one does not compile or test the other.

Swift package layering

Layer Modules Responsibility
Application WebTransport Public async API: client, server, listening server, session, streams, datagrams, logger, error surface, version.
Entry points WebTransportClient, WebTransportServer Executable targets: conformance scenarios and a loopback client/server mode.
Conformance WebTransportCLIConformance Shared scenario catalog and the client/server scenario runners.
Runtime WebTransportNetworkRuntime Network.framework QUIC connections and listeners, trust policies, endpoints, server identity, admission policy, session lifecycle.
HTTP/3 WebTransportHTTP3Core HTTP/3 frames and settings, QPACK, extended CONNECT, WebTransport sessions, streams, datagrams, capsules, flow control.
QUIC WebTransportQUICCore Wire codecs and state primitives: varints, packets, frames, transport parameters, stream identifiers, protection helpers.
TLS WebTransportTLSCore TLS 1.3 messages, transcript and key schedule, handshake readiness, exporter state.
Apple platform WebTransportCryptoApple, WebTransportUDPApple CryptoKit/Security-backed packet helpers; Darwin loopback UDP.
Exception bridge WebTransportSecurityShim The repository's only non-Swift target: a narrow Objective-C frame that turns the NSException SecPKCS12Import raises into a status code, because Swift cannot catch Objective-C exceptions. Internal, not a product.
Test support WebTransportTestSupport, WebTransportLoopbackTestSupport Fixtures and loopback helpers used by the test targets.

Swift/Package.swift declares the same library products plus two smoke executables (LibrarySmokeClient, LibrarySmokeServer) and the nested-only test target. The repository-root manifest is the supported integration point.

Swift client flow

  1. WebTransportClient validates the configuration; transport must be .packet.
  2. WebTransportQUICClient applies the trust policy and opens a Network.framework QUIC connection.
  3. Both ends exchange HTTP/3 control streams and SETTINGS.
  4. The client sends an extended CONNECT with its subprotocol list and any optimistic capsules.
  5. Response headers, settings, subprotocol selection and session policy are validated.
  6. WebTransportNetworkSession exposes streams, datagrams, drain, close and exporter material as WebTransportSession.

Swift server flow

  1. WebTransportServer resolves the TLS identity (.developmentSelfSigned is refused on a non-loopback bind) and creates a configured listener.
  2. The runtime accepts a QUIC connection and exchanges HTTP/3 control streams.
  3. The extended CONNECT request is decoded; optimistic capsule bytes are retained.
  4. WebTransportServerSessionPolicy evaluates authority, path, optional origin, subprotocols and required settings.
  5. An accepted request is answered before optimistic capsules are processed; on a rejection the capsule bytes are discarded.
  6. The listener returns a WebTransportSession, or serves one echo exchange for the CLI's loopback mode.

C99 layering

Sources live in C99/src/; public headers in C99/include/webtransport/ keep the same directory names.

Directory Responsibility Start with
core/ One file each for the primitives every layer uses: status model, checked arithmetic, big-endian I/O, bounds-checked read cursor, two-pass writer, bounded buffer, allocator interface, logging surface, monotonic clock, version. core/status.c, core/cursor.c, core/writer.c
crypto/ The one crypto backend, OpenSSL: SHA-256, HMAC, HKDF, AES-128-GCM, ChaCha20-Poly1305, constant-time compare, secure zero. crypto/crypto_openssl.c
quic/ QUIC wire and state: varints, packet numbers, all RFC 9000 frames plus the RFC 9221 DATAGRAM pair, long/short/Retry headers, transport parameters, connection IDs, packet protection, loss detection, NewReno, streams, the connection runtime, the CRYPTO stream, DATAGRAM, close paths, Retry tokens. quic/frame.c, quic/connection.c, quic/stream.c, quic/protection.c
tls/ TLS 1.3: key schedule and transcript, message and extension codecs, X25519, certificate messages, trust and CertificateVerify, the client and server handshake state machines, the in-memory self-signed identity. tls/keyschedule.c, tls/handshake.c, tls/trust.c
http3/ HTTP/3 and QPACK: frames, SETTINGS, control and request streams, field-section codec, static and dynamic QPACK tables, Huffman, GOAWAY, the request lifecycle, the endpoint's own streams, and the driver that classifies inbound streams and routes frames. http3/frame.c, http3/qpack.c, http3/endpoint.c, http3/driver.c
runtime/ The only place where the socket, the QUIC connection and the TLS handshake meet: the UDP layer behind udp_platform.h, the session driver and its pump, and server Retry. runtime/udp.c, runtime/session.c
webtransport/ The draft-17 layer, with the §7.1 version selection that keeps draft-16 and legacy-era peers working: capsule codec, stream and datagram framing with the session prefix, error mapping, subprotocol negotiation, the session state machine, the request validator, and the buffer for streams and datagrams that arrive before their session. webtransport/capsule.c, webtransport/framing.c, webtransport/session.c
api/ The consumer surface: the opaque session handle, the event-loop seam, session flow control, endpoint and trust configuration. api/session.c, api/events.c, api/flow.c
cli/ The one options parser and one JSON report the three tools share, plus the local socket endpoint helper. cli/options.c, cli/report.c

C99 wire flow

A packet enters at runtime/udp.c. wt_runtime_session_pump (runtime/session.c) reads what is there, drives the QUIC connection and the TLS handshake over CRYPTO frames, and flushes what is owed; it never blocks, so a tool can honour its own timeout. Frame handlers are chained rather than replaced: the TLS handshake installs its own handler, and the HTTP/3 layer is installed behind it. http3/driver.c turns a stream's opening bytes into a classified stream — control, QPACK, request, or a WebTransport stream carrying the draft's 0x41 prefix and the session ID — and routes frames; http3/endpoint.c owns this endpoint's control and QPACK streams and the request lifecycle. webtransport/session.c is the session state machine, whose control channel is the capsules on the CONNECT stream. api/session.c wraps that in the handle a consumer uses.

Where to look for X

I want to… Swift C99
Establish a session (CONNECT, response) WebTransportNetworkRuntime http3/driver.c, webtransport/session_request.c
Parse or build an HTTP/3 frame WebTransportHTTP3Core http3/frame.c
Parse or build a QUIC frame WebTransportQUICCore quic/frame.c
Encode or decode a varint WebTransportQUICCore quic/varint.c
Protect or unprotect a packet WebTransportCryptoApple, WebTransportQUICCore quic/protection.c, crypto/crypto_openssl.c
Walk the TLS 1.3 key schedule WebTransportTLSCore tls/keyschedule.c
Run the TLS handshake Network.framework (production), WebTransportTLSCore (state) tls/handshake.c, quic/handshake.c
Validate a certificate WebTransportNetworkRuntime trust policy tls/trust.c
Handle a WebTransport capsule WebTransportHTTP3Core webtransport/capsule.c
Frame a stream or datagram with its session prefix WebTransportHTTP3Core webtransport/framing.c
Enforce flow control WebTransportHTTP3Core webtransport/session.c, api/flow.c
Reassemble CRYPTO data for the handshake Network.framework (production) quic/crypto_stream.c
Count what a peer can make us buffer WebTransportAdmissionPolicy, WebTransportTransportLimits webtransport/buffered.c, the fixed tables in http3/
Drive a real socket WebTransportNetworkRuntime runtime/session.c, runtime/udp.c
Add or change a CLI flag WebTransportCLIConformance (scenarios), */main.swift (network mode) cli/options.c
Add a conformance scenario Swift/Sources/WebTransportCLIConformance/ apps/wt-conformance-c99/

State, ownership and trust

  • Swift: WebTransportListeningServer owns acceptance, its bound endpoint, the certificate fingerprint and shutdown. WebTransportSession owns the application view of one session. Runtime actors serialize mutable state; protocol-core types are value-oriented where practical so parsers can be tested deterministically.
  • C99: every table in HTTP/3, the driver and the session layer is fixed, because a table that grows with a peer is a heap exhaustion path. A bound is this endpoint's, and a refusal carries no peer-facing error code when the limit is local.
  • Trust boundaries and the secrets policy are in Security and Trust.

Clone this wiki locally