Module

whiplash/quic

src/whiplash/quic.pooka

QUIC, 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

class

QuicError

src/whiplash/quic.pooka:23
class QuicError(code: Int, message: String)

Why bytes were refused, with the transport error code of RFC 9000 section 20.1.

field

code

src/whiplash/quic.pooka:23
code: Int
INFERREDInt
field

message

src/whiplash/quic.pooka:23
message: String
INFERREDString
constructor

new

src/whiplash/quic.pooka:23
INFERREDfn(Int, String) -> whiplash/quic.QuicError
function

encode_varint

src/whiplash/quic.pooka:27
encode_varint(value: Int) -> BitArray
INFERREDfn(Int) -> BitArray

A variable-length integer (section 16): 1, 2, 4 or 8 bytes, the two high bits giving the length.

function

varint_size

src/whiplash/quic.pooka:38
varint_size(value: Int) -> Int
INFERREDfn(Int) -> Int

How many bytes encode_varint uses for a value.

function

frame_size

src/whiplash/quic.pooka:50
frame_size(frame: Frame) -> Int
INFERREDfn(whiplash/quic.Frame) -> Int

How 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.

function

decode_varint

src/whiplash/quic.pooka:69
decode_varint(bytes: BitArray) -> Result(#(Int, BitArray), QuicError)
INFERREDfn(BitArray) -> Result(#(Int, BitArray), whiplash/quic.QuicError)

A variable-length integer and the bytes after it.

function

packet_number_length

src/whiplash/quic.pooka:81
packet_number_length(full: Int, largest_acked: Option(Int)) -> Int
INFERREDfn(Int, Option(Int)) -> Int

How many bytes a packet number needs, given the largest one the peer acknowledged (Appendix A.2).

function

decode_packet_number

src/whiplash/quic.pooka:98
decode_packet_number(largest: Int, truncated: Int, bits: Int) -> Int
INFERREDfn(Int, Int, Int) -> Int

A full packet number from its truncated form (Appendix A.3).

class

Header

src/whiplash/quic.pooka:120
class Header

A packet's header, once header protection is removed.

class

LongHeader

src/whiplash/quic.pooka:123
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).

field

kind

src/whiplash/quic.pooka:124
kind: LongKind
field

version

src/whiplash/quic.pooka:125
version: Int
INFERREDInt
field

destination

src/whiplash/quic.pooka:126
destination: BitArray
INFERREDBitArray
field

source

src/whiplash/quic.pooka:127
source: BitArray
INFERREDBitArray
field

token

src/whiplash/quic.pooka:128
token: BitArray
INFERREDBitArray
field

length

src/whiplash/quic.pooka:129
length: Int
INFERREDInt
field

packet_number

src/whiplash/quic.pooka:130
packet_number: Int
INFERREDInt
constructor

new

src/whiplash/quic.pooka:124
INFERREDfn(whiplash/quic.LongKind, Int, BitArray, BitArray, BitArray, Int, Int) -> whiplash/quic.LongHeader
class

ShortHeader

src/whiplash/quic.pooka:134
class ShortHeader(destination: BitArray, key_phase: Bool, packet_number: Int) is Header

1-RTT packets (section 17.3).

field

destination

src/whiplash/quic.pooka:134
destination: BitArray
INFERREDBitArray
field

key_phase

src/whiplash/quic.pooka:134
key_phase: Bool
INFERREDBool
field

packet_number

src/whiplash/quic.pooka:134
packet_number: Int
INFERREDInt
constructor

new

src/whiplash/quic.pooka:134
INFERREDfn(BitArray, Bool, Int) -> whiplash/quic.ShortHeader
class

VersionNegotiation

src/whiplash/quic.pooka:137
class VersionNegotiation(
  destination: BitArray,
  source: BitArray,
  versions: List(Int)
) is Header

A Version Negotiation packet (section 17.2.1).

field

destination

src/whiplash/quic.pooka:138
destination: BitArray
INFERREDBitArray
field

source

src/whiplash/quic.pooka:139
source: BitArray
INFERREDBitArray
field

versions

src/whiplash/quic.pooka:140
versions: List(Int)
INFERREDList(Int)
constructor

new

src/whiplash/quic.pooka:138
INFERREDfn(BitArray, BitArray, List(Int)) -> whiplash/quic.VersionNegotiation
enum

LongKind

src/whiplash/quic.pooka:143
enum LongKind
variant

Initial

src/whiplash/quic.pooka:144
LongKind.Initial
variant

ZeroRtt

src/whiplash/quic.pooka:145
LongKind.ZeroRtt
variant

Handshake

src/whiplash/quic.pooka:146
LongKind.Handshake
variant

Retry

src/whiplash/quic.pooka:147
LongKind.Retry
class

Invariant

src/whiplash/quic.pooka:153
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.

field

long

src/whiplash/quic.pooka:154
long: Bool
INFERREDBool
field

version

src/whiplash/quic.pooka:155
version: Int
INFERREDInt
field

destination

src/whiplash/quic.pooka:156
destination: BitArray
INFERREDBitArray
field

source

src/whiplash/quic.pooka:157
source: BitArray
INFERREDBitArray
constructor

new

src/whiplash/quic.pooka:154
INFERREDfn(Bool, Int, BitArray, BitArray) -> whiplash/quic.Invariant
function

peek

src/whiplash/quic.pooka:161
peek(datagram: BitArray, short_cid_length: Int) -> Result(Invariant, QuicError)
INFERREDfn(BitArray, Int) -> Result(whiplash/quic.Invariant, whiplash/quic.QuicError)

Read the parts of a header that header protection leaves alone.

class

Frame

src/whiplash/quic.pooka:189
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

src/whiplash/quic.pooka:191
class Padding(length: Int) is Frame
field

length

src/whiplash/quic.pooka:191
length: Int
INFERREDInt
constructor

new

src/whiplash/quic.pooka:191
INFERREDfn(Int) -> whiplash/quic.Padding
class

PingFrame

src/whiplash/quic.pooka:193
class PingFrame is Frame
class

Ack

src/whiplash/quic.pooka:196
class Ack(largest: Int, delay: Int, ranges: List(#(Int, Int))) is Frame

Inclusive ACK intervals, newest first: #(smallest, largest).

field

largest

src/whiplash/quic.pooka:196
largest: Int
INFERREDInt
field

delay

src/whiplash/quic.pooka:196
delay: Int
INFERREDInt
field

ranges

src/whiplash/quic.pooka:196
ranges: List(#(Int, Int))
INFERREDList(#(Int, Int))
constructor

new

src/whiplash/quic.pooka:196
INFERREDfn(Int, Int, List(#(Int, Int))) -> whiplash/quic.Ack
class

AckEcn

src/whiplash/quic.pooka:198
class AckEcn(
  largest: Int,
  delay: Int,
  ranges: List(#(Int, Int)),
  ect0: Int,
  ect1: Int,
  ce: Int
) is Frame
field

largest

src/whiplash/quic.pooka:199
largest: Int
INFERREDInt
field

delay

src/whiplash/quic.pooka:200
delay: Int
INFERREDInt
field

ranges

src/whiplash/quic.pooka:201
ranges: List(#(Int, Int))
INFERREDList(#(Int, Int))
field

ect0

src/whiplash/quic.pooka:202
ect0: Int
INFERREDInt
field

ect1

src/whiplash/quic.pooka:203
ect1: Int
INFERREDInt
field

ce

src/whiplash/quic.pooka:204
ce: Int
INFERREDInt
constructor

new

src/whiplash/quic.pooka:199
INFERREDfn(Int, Int, List(#(Int, Int)), Int, Int, Int) -> whiplash/quic.AckEcn
class

ResetStream

src/whiplash/quic.pooka:207
class ResetStream(stream: Int, code: Int, final_size: Int) is Frame
field

stream

src/whiplash/quic.pooka:207
stream: Int
INFERREDInt
field

code

src/whiplash/quic.pooka:207
code: Int
INFERREDInt
field

final_size

src/whiplash/quic.pooka:207
final_size: Int
INFERREDInt
constructor

new

src/whiplash/quic.pooka:207
INFERREDfn(Int, Int, Int) -> whiplash/quic.ResetStream
class

StopSending

src/whiplash/quic.pooka:209
class StopSending(stream: Int, code: Int) is Frame
field

stream

src/whiplash/quic.pooka:209
stream: Int
INFERREDInt
field

code

src/whiplash/quic.pooka:209
code: Int
INFERREDInt
constructor

new

src/whiplash/quic.pooka:209
INFERREDfn(Int, Int) -> whiplash/quic.StopSending
class

Crypto

src/whiplash/quic.pooka:211
class Crypto(offset: Int, data: BitArray) is Frame
field

offset

src/whiplash/quic.pooka:211
offset: Int
INFERREDInt
field

data

src/whiplash/quic.pooka:211
data: BitArray
INFERREDBitArray
constructor

new

src/whiplash/quic.pooka:211
INFERREDfn(Int, BitArray) -> whiplash/quic.Crypto
class

StreamFrame

src/whiplash/quic.pooka:213
class StreamFrame(stream: Int, offset: Int, fin: Bool, data: BitArray) is Frame
field

stream

src/whiplash/quic.pooka:213
stream: Int
INFERREDInt
field

offset

src/whiplash/quic.pooka:213
offset: Int
INFERREDInt
field

fin

src/whiplash/quic.pooka:213
fin: Bool
INFERREDBool
field

data

src/whiplash/quic.pooka:213
data: BitArray
INFERREDBitArray
constructor

new

src/whiplash/quic.pooka:213
INFERREDfn(Int, Int, Bool, BitArray) -> whiplash/quic.StreamFrame
class

MaxData

src/whiplash/quic.pooka:215
class MaxData(maximum: Int) is Frame
field

maximum

src/whiplash/quic.pooka:215
maximum: Int
INFERREDInt
constructor

new

src/whiplash/quic.pooka:215
INFERREDfn(Int) -> whiplash/quic.MaxData
class

MaxStreamData

src/whiplash/quic.pooka:217
class MaxStreamData(stream: Int, maximum: Int) is Frame
field

stream

src/whiplash/quic.pooka:217
stream: Int
INFERREDInt
field

maximum

src/whiplash/quic.pooka:217
maximum: Int
INFERREDInt
constructor

new

src/whiplash/quic.pooka:217
INFERREDfn(Int, Int) -> whiplash/quic.MaxStreamData
class

MaxStreams

src/whiplash/quic.pooka:219
class MaxStreams(bidirectional: Bool, maximum: Int) is Frame
field

bidirectional

src/whiplash/quic.pooka:219
bidirectional: Bool
INFERREDBool
field

maximum

src/whiplash/quic.pooka:219
maximum: Int
INFERREDInt
constructor

new

src/whiplash/quic.pooka:219
INFERREDfn(Bool, Int) -> whiplash/quic.MaxStreams
class

NewConnectionId

src/whiplash/quic.pooka:221
class NewConnectionId(
  sequence: Int,
  retire_prior_to: Int,
  id: BitArray,
  reset_token: BitArray
) is Frame
field

sequence

src/whiplash/quic.pooka:222
sequence: Int
INFERREDInt
field

retire_prior_to

src/whiplash/quic.pooka:223
retire_prior_to: Int
INFERREDInt
field

id

src/whiplash/quic.pooka:224
id: BitArray
INFERREDBitArray
field

reset_token

src/whiplash/quic.pooka:225
reset_token: BitArray
INFERREDBitArray
constructor

new

src/whiplash/quic.pooka:222
INFERREDfn(Int, Int, BitArray, BitArray) -> whiplash/quic.NewConnectionId
class

ConnectionClose

src/whiplash/quic.pooka:228
class ConnectionClose(
  application: Bool,
  code: Int,
  frame_type: Int,
  reason: String
) is Frame
field

application

src/whiplash/quic.pooka:229
application: Bool
INFERREDBool
field

code

src/whiplash/quic.pooka:230
code: Int
INFERREDInt
field

frame_type

src/whiplash/quic.pooka:231
frame_type: Int
INFERREDInt
field

reason

src/whiplash/quic.pooka:232
reason: String
INFERREDString
constructor

new

src/whiplash/quic.pooka:229
INFERREDfn(Bool, Int, Int, String) -> whiplash/quic.ConnectionClose
class

HandshakeDone

src/whiplash/quic.pooka:235
class HandshakeDone is Frame
class

OtherFrame

src/whiplash/quic.pooka:237
class OtherFrame(kind: Int, payload: BitArray) is Frame
field

kind

src/whiplash/quic.pooka:237
kind: Int
INFERREDInt
field

payload

src/whiplash/quic.pooka:237
payload: BitArray
INFERREDBitArray
constructor

new

src/whiplash/quic.pooka:237
INFERREDfn(Int, BitArray) -> whiplash/quic.OtherFrame
function

decode_frames

src/whiplash/quic.pooka:240
decode_frames(payload: BitArray) -> Result(List(Frame), QuicError)
INFERREDfn(BitArray) -> Result(List(whiplash/quic.Frame), whiplash/quic.QuicError)

Every frame in a packet's payload.

function

encode_frame

src/whiplash/quic.pooka:245
encode_frame(frame: Frame) -> BitArray
INFERREDfn(whiplash/quic.Frame) -> BitArray

One frame's bytes.

class

StreamKind

src/whiplash/quic.pooka:328
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.

field

client_initiated

src/whiplash/quic.pooka:328
client_initiated: Bool
INFERREDBool
field

bidirectional

src/whiplash/quic.pooka:328
bidirectional: Bool
INFERREDBool
constructor

new

src/whiplash/quic.pooka:328
INFERREDfn(Bool, Bool) -> whiplash/quic.StreamKind
function

stream_kind

src/whiplash/quic.pooka:330
stream_kind(stream: Int) -> StreamKind
INFERREDfn(Int) -> whiplash/quic.StreamKind