Module
whiplash/quic
src/whiplash/quic.pookaQUIC, the transport under HTTP/3 (RFC 9000).
This module holds the wire: variable-length integers, packet numbers,
packet headers and frames. whiplash/quic/crypto holds the keys and the
packet protection of RFC 9001, whiplash/quic/tls the TLS 1.3 handshake
carried in CRYPTO frames, and whiplash/quic/connection a connection's
state: streams, flow control, loss recovery (RFC 9002), migration and key
updates.
Sans-IO, like the other protocol modules: the server owns the UDP socket.
API reference
- classQuicError
- functionencode_varint
- functionvarint_size
- functionframe_size
- functiondecode_varint
- functionpacket_number_length
- functiondecode_packet_number
- classHeader
- classLongHeader
- classShortHeader
- classVersionNegotiation
- enumLongKind
- classInvariant
- functionpeek
- classFrame
- classPadding
- classPingFrame
- classAck
- classAckEcn
- classResetStream
- classStopSending
- classCrypto
- classStreamFrame
- classMaxData
- classMaxStreamData
- classMaxStreams
- classNewConnectionId
- classConnectionClose
- classHandshakeDone
- classOtherFrame
- functiondecode_frames
- functionencode_frame
- classStreamKind
- functionstream_kind
class QuicError(code: Int, message: String)
Why bytes were refused, with the transport error code of RFC 9000 section 20.1.
code: Int
Intmessage: String
String
fn(Int, String) -> whiplash/quic.QuicErrorencode_varint(value: Int) -> BitArray
fn(Int) -> BitArrayA variable-length integer (section 16): 1, 2, 4 or 8 bytes, the two high bits giving the length.
varint_size(value: Int) -> Int
fn(Int) -> IntHow many bytes encode_varint uses for a value.
frame_size(frame: Frame) -> Int
fn(whiplash/quic.Frame) -> IntHow many bytes encode_frame writes for a frame, without encoding it:
worked out for STREAM and CRYPTO frames, which carry data, and measured
for the rest.
decode_varint(bytes: BitArray) -> Result(#(Int, BitArray), QuicError)
fn(BitArray) -> Result(#(Int, BitArray), whiplash/quic.QuicError)A variable-length integer and the bytes after it.
packet_number_length(full: Int, largest_acked: Option(Int)) -> Int
fn(Int, Option(Int)) -> IntHow many bytes a packet number needs, given the largest one the peer acknowledged (Appendix A.2).
decode_packet_number(largest: Int, truncated: Int, bits: Int) -> Int
fn(Int, Int, Int) -> IntA full packet number from its truncated form (Appendix A.3).
class Header
A packet's header, once header protection is removed.
class LongHeader(
kind: LongKind,
version: Int,
destination: BitArray,
source: BitArray,
token: BitArray,
length: Int,
packet_number: Int
) is Header
Initial, 0-RTT, Handshake and Retry packets (section 17.2).
kind: LongKind
whiplash/quic.LongKindversion: Int
Intdestination: BitArray
BitArraysource: BitArray
BitArraytoken: BitArray
BitArraylength: Int
Intpacket_number: Int
Int
fn(whiplash/quic.LongKind, Int, BitArray, BitArray, BitArray, Int, Int) -> whiplash/quic.LongHeaderclass ShortHeader(destination: BitArray, key_phase: Bool, packet_number: Int) is Header
1-RTT packets (section 17.3).
destination: BitArray
BitArraykey_phase: Bool
Boolpacket_number: Int
Int
fn(BitArray, Bool, Int) -> whiplash/quic.ShortHeaderclass VersionNegotiation(
destination: BitArray,
source: BitArray,
versions: List(Int)
) is Header
A Version Negotiation packet (section 17.2.1).
destination: BitArray
BitArraysource: BitArray
BitArrayversions: List(Int)
List(Int)
fn(BitArray, BitArray, List(Int)) -> whiplash/quic.VersionNegotiationenum LongKind
LongKind.Initial
LongKind.ZeroRtt
LongKind.Handshake
LongKind.Retry
class Invariant(
long: Bool,
version: Int,
destination: BitArray,
source: BitArray
)
The parts of a long header that are not protected: enough to find the connection and its keys (section 17.2). Short headers need the length of the connection IDs this end issued.
long: Bool
Boolversion: Int
Intdestination: BitArray
BitArraysource: BitArray
BitArray
fn(Bool, Int, BitArray, BitArray) -> whiplash/quic.Invariantpeek(datagram: BitArray, short_cid_length: Int) -> Result(Invariant, QuicError)
fn(BitArray, Int) -> Result(whiplash/quic.Invariant, whiplash/quic.QuicError)Read the parts of a header that header protection leaves alone.
class Frame
One frame (section 19). Only the frames HTTP/3 needs are listed; the
Other known frame layouts decode as OtherFrame; unknown types are errors
because QUIC has no generic length with which to skip them safely.
class Padding(length: Int) is Frame
length: Int
Int
fn(Int) -> whiplash/quic.Paddingclass PingFrame is Frame
class Ack(largest: Int, delay: Int, ranges: List(#(Int, Int))) is Frame
Inclusive ACK intervals, newest first: #(smallest, largest).
largest: Int
Intdelay: Int
Intranges: List(#(Int, Int))
List(#(Int, Int))
fn(Int, Int, List(#(Int, Int))) -> whiplash/quic.Ackclass AckEcn(
largest: Int,
delay: Int,
ranges: List(#(Int, Int)),
ect0: Int,
ect1: Int,
ce: Int
) is Frame
largest: Int
Intdelay: Int
Intranges: List(#(Int, Int))
List(#(Int, Int))ect0: Int
Intect1: Int
Intce: Int
Int
fn(Int, Int, List(#(Int, Int)), Int, Int, Int) -> whiplash/quic.AckEcnclass ResetStream(stream: Int, code: Int, final_size: Int) is Frame
stream: Int
Intcode: Int
Intfinal_size: Int
Int
fn(Int, Int, Int) -> whiplash/quic.ResetStreamclass StopSending(stream: Int, code: Int) is Frame
stream: Int
Intcode: Int
Int
fn(Int, Int) -> whiplash/quic.StopSendingclass Crypto(offset: Int, data: BitArray) is Frame
offset: Int
Intdata: BitArray
BitArray
fn(Int, BitArray) -> whiplash/quic.Cryptoclass StreamFrame(stream: Int, offset: Int, fin: Bool, data: BitArray) is Frame
stream: Int
Intoffset: Int
Intfin: Bool
Booldata: BitArray
BitArray
fn(Int, Int, Bool, BitArray) -> whiplash/quic.StreamFrameclass MaxData(maximum: Int) is Frame
maximum: Int
Int
fn(Int) -> whiplash/quic.MaxDataclass MaxStreamData(stream: Int, maximum: Int) is Frame
stream: Int
Intmaximum: Int
Int
fn(Int, Int) -> whiplash/quic.MaxStreamDataclass MaxStreams(bidirectional: Bool, maximum: Int) is Frame
bidirectional: Bool
Boolmaximum: Int
Int
fn(Bool, Int) -> whiplash/quic.MaxStreamsclass NewConnectionId(
sequence: Int,
retire_prior_to: Int,
id: BitArray,
reset_token: BitArray
) is Frame
sequence: Int
Intretire_prior_to: Int
Intid: BitArray
BitArrayreset_token: BitArray
BitArray
fn(Int, Int, BitArray, BitArray) -> whiplash/quic.NewConnectionIdclass ConnectionClose(
application: Bool,
code: Int,
frame_type: Int,
reason: String
) is Frame
application: Bool
Boolcode: Int
Intframe_type: Int
Intreason: String
String
fn(Bool, Int, Int, String) -> whiplash/quic.ConnectionCloseclass HandshakeDone is Frame
class OtherFrame(kind: Int, payload: BitArray) is Frame
kind: Int
Intpayload: BitArray
BitArray
fn(Int, BitArray) -> whiplash/quic.OtherFramedecode_frames(payload: BitArray) -> Result(List(Frame), QuicError)
fn(BitArray) -> Result(List(whiplash/quic.Frame), whiplash/quic.QuicError)Every frame in a packet's payload.
encode_frame(frame: Frame) -> BitArray
fn(whiplash/quic.Frame) -> BitArrayOne frame's bytes.
class StreamKind(client_initiated: Bool, bidirectional: Bool)
Which streams a stream ID names (section 2.1): who opened it, and whether data flows both ways.
client_initiated: Bool
Boolbidirectional: Bool
Bool
fn(Bool, Bool) -> whiplash/quic.StreamKindstream_kind(stream: Int) -> StreamKind
fn(Int) -> whiplash/quic.StreamKind