Module

whiplash/quic/connection

src/whiplash/quic/connection.pooka

One QUIC connection, from the server's side (RFC 9000, RFC 9001).

Sans-IO: datagrams go in with accept and receive; datagrams to send come out of flush and on_timeout; the application reads stream data from events and writes with send. The UDP socket, timers and routing of datagrams to connections belong to the caller.

What it does: the three packet number spaces with their keys, and 0-RTT packets in the 1-RTT space when the handshake accepts them; CRYPTO reassembly driving the TLS handshake (whiplash/quic/tls), then a session ticket; acknowledgements; round-trip estimates, loss detection by packet and time thresholds, and probe timeouts (RFC 9002 sections 5 and 6); NewReno congestion control with persistent congestion, and pacing (section 7); ordered stream data; flow control both ways (the peer's MAX_DATA and MAX_STREAM_DATA are respected, ours are raised as data is delivered, and MAX_STREAMS as client streams end); STOP_SENDING and RESET_STREAM; key updates either way (RFC 9001 section 6); connection IDs issued and retired, path validation and migration to a new client address (RFC 9000 sections 5.1, 8.2 and 9); the transport parameters of a connection that began with a Retry (retry, accept_retried); HANDSHAKE_DONE; closing. Initial and Handshake packets share datagrams where they fit, a datagram with an ack-eliciting Initial is padded to 1,200 bytes, and until the client's address is proven the server sends at most three times what it received (section 8.1).

Bytes given to send wait in the connection until flow control, the congestion window and the pacer let them go; pending tells the caller how much waits, so a producer can be held back.

Not done: the server never asks to move to a preferred address, never sends NEW_TOKEN, and keeps to 1,200-byte datagrams (no path MTU discovery). A 1-RTT packet, having no length, ends its datagram.

API reference

class

Event

src/whiplash/quic/connection.pooka:55
class Event

What happened on a connection.

class

Connected

src/whiplash/quic/connection.pooka:58
class Connected is Event

The handshake completed: the client's Finished was verified.

class

Migrated

src/whiplash/quic/connection.pooka:62
class Migrated is Event

The peer moved to a new address (RFC 9000 section 9): send there from now on. The connection is validating the address.

class

Data

src/whiplash/quic/connection.pooka:65
class Data(stream: Int, data: BitArray, fin: Bool) is Event

Stream data, in order.

field

stream

src/whiplash/quic/connection.pooka:65
stream: Int
INFERREDInt
field

data

src/whiplash/quic/connection.pooka:65
data: BitArray
INFERREDBitArray
field

fin

src/whiplash/quic/connection.pooka:65
fin: Bool
INFERREDBool
constructor

new

src/whiplash/quic/connection.pooka:65
INFERREDfn(Int, BitArray, Bool) -> whiplash/quic/connection.Data
class

Closed

src/whiplash/quic/connection.pooka:68
class Closed(code: Int, reason: String) is Event

The connection is closed, by the peer or by this end.

field

code

src/whiplash/quic/connection.pooka:68
code: Int
INFERREDInt
field

reason

src/whiplash/quic/connection.pooka:68
reason: String
INFERREDString
constructor

new

src/whiplash/quic/connection.pooka:68
INFERREDfn(Int, String) -> whiplash/quic/connection.Closed
class

Reset

src/whiplash/quic/connection.pooka:71
class Reset(stream: Int, code: Int) is Event

The peer abandoned sending on a stream (RESET_STREAM).

field

stream

src/whiplash/quic/connection.pooka:71
stream: Int
INFERREDInt
field

code

src/whiplash/quic/connection.pooka:71
code: Int
INFERREDInt
constructor

new

src/whiplash/quic/connection.pooka:71
INFERREDfn(Int, Int) -> whiplash/quic/connection.Reset
class

Stopped

src/whiplash/quic/connection.pooka:76
class Stopped(stream: Int, code: Int) is Event

The peer asked this end to stop sending on a stream (STOP_SENDING). The connection has answered with RESET_STREAM; whatever is sent on the stream from now on is dropped, and a send with fin forgets it.

field

stream

src/whiplash/quic/connection.pooka:76
stream: Int
INFERREDInt
field

code

src/whiplash/quic/connection.pooka:76
code: Int
INFERREDInt
constructor

new

src/whiplash/quic/connection.pooka:76
INFERREDfn(Int, Int) -> whiplash/quic/connection.Stopped
class

Space

src/whiplash/quic/connection.pooka:81
class Space(
  rx: Option(crypto.Keys),
  tx: Option(crypto.Keys),
  next: Int,
  largest: Int,
  ranges: List(#(Int, Int)),
  ack_due: Bool,
  crypto_in: Int,
  crypto_held: Dict(Int, BitArray),
  crypto_data: BitArray,
  crypto_out: Int,
  queue: List(Frame),
  sent: Sent
)

One packet number space: its keys, what has been received and must be acknowledged, the CRYPTO stream in each direction, frames waiting to be sent, and frames sent but not yet acknowledged.

field

rx

src/whiplash/quic/connection.pooka:82
rx: Option(crypto.Keys)
field

tx

src/whiplash/quic/connection.pooka:83
tx: Option(crypto.Keys)
field

next

src/whiplash/quic/connection.pooka:84
next: Int
INFERREDInt
field

largest

src/whiplash/quic/connection.pooka:85
largest: Int
INFERREDInt
field

ranges

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

ack_due

src/whiplash/quic/connection.pooka:87
ack_due: Bool
INFERREDBool
field

crypto_in

src/whiplash/quic/connection.pooka:88
crypto_in: Int
INFERREDInt
field

crypto_held

src/whiplash/quic/connection.pooka:89
crypto_held: Dict(Int, BitArray)
INFERRED$package/pooka_stdlib/pooka/dict.Dict(Int, BitArray)
field

crypto_data

src/whiplash/quic/connection.pooka:90
crypto_data: BitArray
INFERREDBitArray
field

crypto_out

src/whiplash/quic/connection.pooka:91
crypto_out: Int
INFERREDInt
field

queue

src/whiplash/quic/connection.pooka:92
queue: List(Frame)
INFERREDList(whiplash/quic.Frame)
field

sent

src/whiplash/quic/connection.pooka:93
sent: Sent
constructor

new

src/whiplash/quic/connection.pooka:82
INFERREDfn(Option(whiplash/quic/crypto.Keys), Option(whiplash/quic/crypto.Keys), Int, Int, List(#(Int, Int)), Bool, Int, $package/pooka_stdlib/pooka/dict.Dict(Int, BitArray), BitArray, Int, List(whiplash/quic.Frame), whiplash/quic/connection.Sent) -> whiplash/quic/connection.Space
class

Incoming

src/whiplash/quic/connection.pooka:100
class Incoming(
  next: Int,
  held: Dict(Int, #(BitArray, Bool)),
  limit: Int,
  highest: Int,
  consumed: Int
)

One receiving stream: the next byte to deliver, the bytes held out of order, the limit granted to the peer, the highest byte received, and the bytes the application has consumed (-1 when delivery counts as consumption; see manual).

field

next

src/whiplash/quic/connection.pooka:101
next: Int
INFERREDInt
field

held

src/whiplash/quic/connection.pooka:102
held: Dict(Int, #(BitArray, Bool))
INFERRED$package/pooka_stdlib/pooka/dict.Dict(Int, #(BitArray, Bool))
field

limit

src/whiplash/quic/connection.pooka:103
limit: Int
INFERREDInt
field

highest

src/whiplash/quic/connection.pooka:104
highest: Int
INFERREDInt
field

consumed

src/whiplash/quic/connection.pooka:105
consumed: Int
INFERREDInt
constructor

new

src/whiplash/quic/connection.pooka:101
INFERREDfn(Int, $package/pooka_stdlib/pooka/dict.Dict(Int, #(BitArray, Bool)), Int, Int, Int) -> whiplash/quic/connection.Incoming
class

Outgoing

src/whiplash/quic/connection.pooka:111
class Outgoing(pending: BitArray, offset: Int, fin: Bool, limit: Int)

Bytes waiting to be sent on one stream, the offset they start at, whether the stream ends after them, and how far the peer lets the stream go. A limit of -1 marks a stream the peer stopped: its bytes are dropped.

field

pending

src/whiplash/quic/connection.pooka:111
pending: BitArray
INFERREDBitArray
field

offset

src/whiplash/quic/connection.pooka:111
offset: Int
INFERREDInt
field

fin

src/whiplash/quic/connection.pooka:111
fin: Bool
INFERREDBool
field

limit

src/whiplash/quic/connection.pooka:111
limit: Int
INFERREDInt
constructor

new

src/whiplash/quic/connection.pooka:111
INFERREDfn(BitArray, Int, Bool, Int) -> whiplash/quic/connection.Outgoing
class

Sending

src/whiplash/quic/connection.pooka:117
class Sending(
  outgoing: Dict(Int, Outgoing),
  order: List(Int),
  early: Dict(Int, Int),
  peer_data: Int,
  data_sent: Int,
  peer_bidi: Int,
  peer_uni: Int
)

The sending side of flow control: streams with bytes waiting (order is the round-robin), limits for streams not yet written to, the peer's connection limit and how much of it is used, and the peer's initial stream limits.

field

outgoing

src/whiplash/quic/connection.pooka:118
outgoing: Dict(Int, Outgoing)
INFERRED$package/pooka_stdlib/pooka/dict.Dict(Int, whiplash/quic/connection.Outgoing)
field

order

src/whiplash/quic/connection.pooka:119
order: List(Int)
INFERREDList(Int)
field

early

src/whiplash/quic/connection.pooka:120
early: Dict(Int, Int)
INFERRED$package/pooka_stdlib/pooka/dict.Dict(Int, Int)
field

peer_data

src/whiplash/quic/connection.pooka:121
peer_data: Int
INFERREDInt
field

data_sent

src/whiplash/quic/connection.pooka:122
data_sent: Int
INFERREDInt
field

peer_bidi

src/whiplash/quic/connection.pooka:123
peer_bidi: Int
INFERREDInt
field

peer_uni

src/whiplash/quic/connection.pooka:124
peer_uni: Int
INFERREDInt
constructor

new

src/whiplash/quic/connection.pooka:118
INFERREDfn($package/pooka_stdlib/pooka/dict.Dict(Int, whiplash/quic/connection.Outgoing), List(Int), $package/pooka_stdlib/pooka/dict.Dict(Int, Int), Int, Int, Int, Int) -> whiplash/quic/connection.Sending
class

Congestion

src/whiplash/quic/connection.pooka:130
class Congestion(in_flight: Int, window: Int, threshold: Int, recovery: Int)

NewReno: bytes in flight in 1-RTT packets, the congestion window, the slow-start threshold, and the first packet number sent after the last window reduction (losses below it do not reduce the window again).

field

in_flight

src/whiplash/quic/connection.pooka:130
in_flight: Int
INFERREDInt
field

window

src/whiplash/quic/connection.pooka:130
window: Int
INFERREDInt
field

threshold

src/whiplash/quic/connection.pooka:130
threshold: Int
INFERREDInt
field

recovery

src/whiplash/quic/connection.pooka:130
recovery: Int
INFERREDInt
constructor

new

src/whiplash/quic/connection.pooka:130
INFERREDfn(Int, Int, Int, Int) -> whiplash/quic/connection.Congestion
class

Receiving

src/whiplash/quic/connection.pooka:136
class Receiving(
  data_max: Int,
  data_received: Int,
  bidi_max: Int,
  uni_max: Int,
  finished: Dict(Int, Nil),
  bidi_floor: Int,
  uni_floor: Int,
  opened_bidi: Int
)

The receiving side: this end's connection limit and the bytes counted against it, the client stream counts allowed, streams whose receiving side has ended (below the floors, or in finished), and the highest bidirectional stream count the client has opened.

field

data_max

src/whiplash/quic/connection.pooka:137
data_max: Int
INFERREDInt
field

data_received

src/whiplash/quic/connection.pooka:138
data_received: Int
INFERREDInt
field

bidi_max

src/whiplash/quic/connection.pooka:139
bidi_max: Int
INFERREDInt
field

uni_max

src/whiplash/quic/connection.pooka:140
uni_max: Int
INFERREDInt
field

finished

src/whiplash/quic/connection.pooka:141
finished: Dict(Int, Nil)
INFERRED$package/pooka_stdlib/pooka/dict.Dict(Int, Nil)
field

bidi_floor

src/whiplash/quic/connection.pooka:142
bidi_floor: Int
INFERREDInt
field

uni_floor

src/whiplash/quic/connection.pooka:143
uni_floor: Int
INFERREDInt
field

opened_bidi

src/whiplash/quic/connection.pooka:144
opened_bidi: Int
INFERREDInt
constructor

new

src/whiplash/quic/connection.pooka:137
INFERREDfn(Int, Int, Int, Int, $package/pooka_stdlib/pooka/dict.Dict(Int, Nil), Int, Int, Int) -> whiplash/quic/connection.Receiving
class

Flow

src/whiplash/quic/connection.pooka:147
class Flow(sending: Sending, congestion: Congestion, receiving: Receiving)
field

sending

src/whiplash/quic/connection.pooka:147
sending: Sending
field

congestion

src/whiplash/quic/connection.pooka:147
congestion: Congestion
field

receiving

src/whiplash/quic/connection.pooka:147
receiving: Receiving
constructor

new

src/whiplash/quic/connection.pooka:147
class

Connection

src/whiplash/quic/connection.pooka:149
class Connection(
  original: BitArray,
  local: BitArray,
  peer: BitArray,
  initial: Space,
  handshake: Space,
  application: Space,
  identity: tls.Identity,
  flight: Option(tls.Flight),
  connected: Bool,
  closed: Bool,
  streams: Dict(Int, Incoming),
  flow: Flow,
  received: Int,
  sent_bytes: Int,
  keys: Phases,
  recovery: Recovery,
  path: Path
)
field

original

src/whiplash/quic/connection.pooka:150
original: BitArray
INFERREDBitArray
field

local

src/whiplash/quic/connection.pooka:151
local: BitArray
INFERREDBitArray
field

peer

src/whiplash/quic/connection.pooka:152
peer: BitArray
INFERREDBitArray
field

initial

src/whiplash/quic/connection.pooka:153
initial: Space
field

handshake

src/whiplash/quic/connection.pooka:154
handshake: Space
field

application

src/whiplash/quic/connection.pooka:155
application: Space
field

identity

src/whiplash/quic/connection.pooka:156
identity: tls.Identity
field

flight

src/whiplash/quic/connection.pooka:157
flight: Option(tls.Flight)
INFERREDOption(whiplash/quic/tls.Flight)
field

connected

src/whiplash/quic/connection.pooka:158
connected: Bool
INFERREDBool
field

closed

src/whiplash/quic/connection.pooka:159
closed: Bool
INFERREDBool
field

streams

src/whiplash/quic/connection.pooka:160
streams: Dict(Int, Incoming)
INFERRED$package/pooka_stdlib/pooka/dict.Dict(Int, whiplash/quic/connection.Incoming)
field

flow

src/whiplash/quic/connection.pooka:161
flow: Flow
field

received

src/whiplash/quic/connection.pooka:162
received: Int
INFERREDInt
field

sent_bytes

src/whiplash/quic/connection.pooka:163
sent_bytes: Int
INFERREDInt
field

keys

src/whiplash/quic/connection.pooka:164
keys: Phases
field

recovery

src/whiplash/quic/connection.pooka:165
recovery: Recovery
field

path

src/whiplash/quic/connection.pooka:166
path: Path
constructor

new

src/whiplash/quic/connection.pooka:150
class

Sent

src/whiplash/quic/connection.pooka:175
class Sent(
  packets: Dict(Int, #(Int, Int, List(Frame))),
  oldest: Int,
  acked: Int,
  last: Int,
  loss_at: Int
)

Packets sent in one space and not yet acknowledged or declared lost, by packet number: when each was sent, its size, and its frames. Numbers below oldest are all settled, so acknowledgement and loss detection walk only what is still in flight. Also the largest number the peer acknowledged (-1 before any), when the last ack-eliciting packet went (-1 before any), and when the next packet would be declared lost by time (-1 for none).

field

packets

src/whiplash/quic/connection.pooka:176
packets: Dict(Int, #(Int, Int, List(Frame)))
INFERRED$package/pooka_stdlib/pooka/dict.Dict(Int, #(Int, Int, List(whiplash/quic.Frame)))
field

oldest

src/whiplash/quic/connection.pooka:177
oldest: Int
INFERREDInt
field

acked

src/whiplash/quic/connection.pooka:178
acked: Int
INFERREDInt
field

last

src/whiplash/quic/connection.pooka:179
last: Int
INFERREDInt
field

loss_at

src/whiplash/quic/connection.pooka:180
loss_at: Int
INFERREDInt
constructor

new

src/whiplash/quic/connection.pooka:176
INFERREDfn($package/pooka_stdlib/pooka/dict.Dict(Int, #(Int, Int, List(whiplash/quic.Frame))), Int, Int, Int, Int) -> whiplash/quic/connection.Sent
class

Phases

src/whiplash/quic/connection.pooka:190
class Phases(
  phase: Int,
  rx_secret: BitArray,
  tx_secret: BitArray,
  next_rx: Option(crypto.Keys),
  previous_rx: Option(crypto.Keys),
  rx_since: Int,
  tx_since: Int,
  confirmed: Bool,
  early: Option(crypto.Keys)
)

Key update for 1-RTT packets (RFC 9001 section 6): the current key phase bit, the secrets of the current phase, the peer's keys for the next phase (ready before it updates) and for the previous one (for late packets), the first packet number received in this phase (-1 until one arrives), the first packet number sent in it, whether one of those was acknowledged, without which this end may not update again, and the keys of the client's 0-RTT packets while they are accepted.

field

phase

src/whiplash/quic/connection.pooka:191
phase: Int
INFERREDInt
field

rx_secret

src/whiplash/quic/connection.pooka:192
rx_secret: BitArray
INFERREDBitArray
field

tx_secret

src/whiplash/quic/connection.pooka:193
tx_secret: BitArray
INFERREDBitArray
field

next_rx

src/whiplash/quic/connection.pooka:194
next_rx: Option(crypto.Keys)
field

previous_rx

src/whiplash/quic/connection.pooka:195
previous_rx: Option(crypto.Keys)
field

rx_since

src/whiplash/quic/connection.pooka:196
rx_since: Int
INFERREDInt
field

tx_since

src/whiplash/quic/connection.pooka:197
tx_since: Int
INFERREDInt
field

confirmed

src/whiplash/quic/connection.pooka:198
confirmed: Bool
INFERREDBool
field

early

src/whiplash/quic/connection.pooka:199
early: Option(crypto.Keys)
constructor

new

src/whiplash/quic/connection.pooka:191
INFERREDfn(Int, BitArray, BitArray, Option(whiplash/quic/crypto.Keys), Option(whiplash/quic/crypto.Keys), Int, Int, Bool, Option(whiplash/quic/crypto.Keys)) -> whiplash/quic/connection.Phases
class

Recovery

src/whiplash/quic/connection.pooka:208
class Recovery(
  latest: Int,
  smoothed: Int,
  variance: Int,
  minimum: Int,
  sampled: Bool,
  pto_count: Int,
  max_ack_delay: Int,
  ack_exponent: Int,
  probes: Int,
  tokens: Int,
  refilled: Int
)

Round-trip estimates and probe timeouts (RFC 9002 sections 5 and 6), in milliseconds: the latest sample, the smoothed estimate, its variation, the minimum seen, and whether any sample was taken; how many probe timeouts passed without an acknowledgement; the peer's max_ack_delay and ack_delay_exponent; probe packets owed that may exceed the congestion window; and the pacer's bytes in hand and when it last refilled.

field

latest

src/whiplash/quic/connection.pooka:209
latest: Int
INFERREDInt
field

smoothed

src/whiplash/quic/connection.pooka:210
smoothed: Int
INFERREDInt
field

variance

src/whiplash/quic/connection.pooka:211
variance: Int
INFERREDInt
field

minimum

src/whiplash/quic/connection.pooka:212
minimum: Int
INFERREDInt
field

sampled

src/whiplash/quic/connection.pooka:213
sampled: Bool
INFERREDBool
field

pto_count

src/whiplash/quic/connection.pooka:214
pto_count: Int
INFERREDInt
field

max_ack_delay

src/whiplash/quic/connection.pooka:215
max_ack_delay: Int
INFERREDInt
field

ack_exponent

src/whiplash/quic/connection.pooka:216
ack_exponent: Int
INFERREDInt
field

probes

src/whiplash/quic/connection.pooka:217
probes: Int
INFERREDInt
field

tokens

src/whiplash/quic/connection.pooka:218
tokens: Int
INFERREDInt
field

refilled

src/whiplash/quic/connection.pooka:219
refilled: Int
INFERREDInt
constructor

new

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

Path

src/whiplash/quic/connection.pooka:232
class Path(
  validated: Bool,
  challenge: Option(BitArray),
  ids: Dict(Int, BitArray),
  issued: Int,
  peer_ids: Dict(Int, BitArray),
  peer_sequence: Int,
  peer_limit: Int,
  retried: Option(BitArray),
  newest: Bool,
  mtu: Int,
  probe: Int,
  probing: Int
)

The network path and connection IDs (RFC 9000 sections 5.1, 8 and 9): whether the peer's address is validated, the PATH_CHALLENGE data awaiting a response, this end's connection IDs by sequence number and the next sequence to issue, the peer's IDs by sequence and the sequence of the one in use, how many IDs the peer accepts, the original destination ID when the client came back after a Retry, and whether the datagram being read carried the peer's newest packet that is not only probing. Then path MTU discovery (RFC 9000 section 14.3): the largest datagram known to get through, the packet number of a probe in flight (-1 for none), and the size to probe next (0 when done).

field

validated

src/whiplash/quic/connection.pooka:233
validated: Bool
INFERREDBool
field

challenge

src/whiplash/quic/connection.pooka:234
challenge: Option(BitArray)
INFERREDOption(BitArray)
field

ids

src/whiplash/quic/connection.pooka:235
ids: Dict(Int, BitArray)
INFERRED$package/pooka_stdlib/pooka/dict.Dict(Int, BitArray)
field

issued

src/whiplash/quic/connection.pooka:236
issued: Int
INFERREDInt
field

peer_ids

src/whiplash/quic/connection.pooka:237
peer_ids: Dict(Int, BitArray)
INFERRED$package/pooka_stdlib/pooka/dict.Dict(Int, BitArray)
field

peer_sequence

src/whiplash/quic/connection.pooka:238
peer_sequence: Int
INFERREDInt
field

peer_limit

src/whiplash/quic/connection.pooka:239
peer_limit: Int
INFERREDInt
field

retried

src/whiplash/quic/connection.pooka:240
retried: Option(BitArray)
INFERREDOption(BitArray)
field

newest

src/whiplash/quic/connection.pooka:241
newest: Bool
INFERREDBool
field

mtu

src/whiplash/quic/connection.pooka:242
mtu: Int
INFERREDInt
field

probe

src/whiplash/quic/connection.pooka:243
probe: Int
INFERREDInt
field

probing

src/whiplash/quic/connection.pooka:244
probing: Int
INFERREDInt
constructor

new

src/whiplash/quic/connection.pooka:233
INFERREDfn(Bool, Option(BitArray), $package/pooka_stdlib/pooka/dict.Dict(Int, BitArray), Int, $package/pooka_stdlib/pooka/dict.Dict(Int, BitArray), Int, Int, Option(BitArray), Bool, Int, Int, Int) -> whiplash/quic/connection.Path
function

accept

src/whiplash/quic/connection.pooka:298
accept(datagram: BitArray, identity: tls.Identity, now: Int) -> Result(
  #(Connection, List(Event), List(BitArray)),
  quic.QuicError
)

A connection for a client's first Initial datagram, and what it leads to.

function

accept_validated

src/whiplash/quic/connection.pooka:308
accept_validated(datagram: BitArray, identity: tls.Identity, now: Int) -> Result(
  #(Connection, List(Event), List(BitArray)),
  quic.QuicError
)

accept for a client whose Initial carried a token this server gave it with NEW_TOKEN on an earlier connection: its address is already proven, so nothing limits what the server sends it, and no Retry is needed.

function

send_token

src/whiplash/quic/connection.pooka:317
send_token(connection: Connection, token: BitArray) -> Connection

Give the client a token for its next connection (NEW_TOKEN, RFC 9000 section 8.1.3), sent in 1-RTT packets.

function

accept_retried

src/whiplash/quic/connection.pooka:332
accept_retried(
  datagram: BitArray,
  identity: tls.Identity,
  original: BitArray,
  now: Int
) -> Result(#(Connection, List(Event), List(BitArray)), quic.QuicError)
INFERREDfn(BitArray, whiplash/quic/tls.Identity, BitArray, Int) -> Result(#(whiplash/quic/connection.Connection, List(whiplash/quic/connection.Event), List(BitArray)), whiplash/quic.QuicError)

accept for a client that came back with the token of a Retry: original is the destination ID of its very first Initial, which the token carries. Its address is proven, so nothing limits what the server sends it.

function

refuse

src/whiplash/quic/connection.pooka:406
refuse(
  datagram: BitArray,
  identity: tls.Identity,
  code: Int,
  reason: String,
  now: Int
) -> Result(List(BitArray), Nil)
INFERREDfn(BitArray, whiplash/quic/tls.Identity, Int, String, Int) -> Result(List(BitArray), Nil)

Refuse a client's Initial with CONNECTION_CLOSE in an Initial packet, as for a Retry token that does not check out (INVALID_TOKEN, 0x0b). Returns the datagrams to send; an error when the datagram is no Initial.

function

initial_token

src/whiplash/quic/connection.pooka:460
initial_token(datagram: BitArray) -> Result(BitArray, Nil)
INFERREDfn(BitArray) -> Result(BitArray, Nil)

The token of a client's Initial packet (RFC 9000 section 17.2.2); empty when it has none. An error when the datagram is no Initial.

function

retry

src/whiplash/quic/connection.pooka:485
retry(datagram: BitArray, source: BitArray, token: BitArray) -> Result(
  BitArray,
  Nil
)
INFERREDfn(BitArray, BitArray, BitArray) -> Result(BitArray, Nil)

A Retry packet answering a client's Initial (RFC 9000 section 17.2.5), from the new connection ID source and carrying token, with its integrity tag. The client sends its Initial again, to source, with the token; an error when the datagram is no Initial.

Pooka
let assert Ok(packet) = connection.retry(datagram, id, token)
function

local_id

src/whiplash/quic/connection.pooka:503
local_id(connection: Connection) -> BitArray
INFERREDfn(whiplash/quic/connection.Connection) -> BitArray

This end's connection ID: route datagrams carrying it here.

function

ids

src/whiplash/quic/connection.pooka:510
ids(connection: Connection) -> List(BitArray)
INFERREDfn(whiplash/quic/connection.Connection) -> List(BitArray)

Every connection ID that routes to this connection: the client's original destination ID and each ID this end has issued and the peer not retired. It changes as the peer retires IDs and new ones replace them.

function

original_id

src/whiplash/quic/connection.pooka:515
original_id(connection: Connection) -> BitArray
INFERREDfn(whiplash/quic/connection.Connection) -> BitArray

The client's original destination ID, which routes its first packets.

function

is_closed

src/whiplash/quic/connection.pooka:519
is_closed(connection: Connection) -> Bool
function

receive

src/whiplash/quic/connection.pooka:525
receive(connection: Connection, datagram: BitArray, now: Int) -> Result(
  #(Connection, List(Event), List(BitArray)),
  quic.QuicError
)

Read a datagram: every packet in it, every frame in each packet. Returns the events and the datagrams to send now.

function

receive_from

src/whiplash/quic/connection.pooka:544
receive_from(
  connection: Connection,
  datagram: BitArray,
  moved: Bool,
  now: Int
) -> Result(#(Connection, List(Event), List(BitArray)), quic.QuicError)

receive, saying whether the datagram came from an address other than the one this end sends to. The datagrams returned belong to the address it came from; a PATH_RESPONSE must go back where its challenge came from. When it carries the peer's newest packet that is not only probing, the peer has moved (RFC 9000 section 9): the events include Migrated, everything goes to the new address from then on, and the connection validates it, sending at most three times what arrives from it until it answers.

Pooka
let moved = from != address
let assert Ok(#(c, events, out)) = connection.receive_from(c, datagram, moved, now)
function

transport_parameters

src/whiplash/quic/connection.pooka:1710
transport_parameters(connection: Connection) -> BitArray
INFERREDfn(whiplash/quic/connection.Connection) -> BitArray

The transport parameters this server sends (RFC 9000 section 18.2).

function

send

src/whiplash/quic/connection.pooka:2025
send(connection: Connection, stream: Int, data: BitArray, fin: Bool) -> Connection

Give bytes to a stream; fin ends it. They are sent, in 1-RTT packets, as flow control and the congestion window allow.

function

pending

src/whiplash/quic/connection.pooka:2092
pending(connection: Connection, stream: Int) -> Int
INFERREDfn(whiplash/quic/connection.Connection, Int) -> Int

Bytes given to send on a stream and not yet put in packets.

function

flush

src/whiplash/quic/connection.pooka:2347
flush(connection: Connection, now: Int) -> #(List(BitArray), Connection)

Every datagram ready to send now: acknowledgements and queued frames, space by space. Initial and Handshake packets share datagrams where they fit (RFC 9000 section 12.2); 1-RTT packets go as the congestion window and the pacer allow (RFC 9002 section 7.7).

function

max_datagram

src/whiplash/quic/connection.pooka:2664
max_datagram(connection: Connection) -> Int

The largest datagram this connection sends: 1,200 bytes until path MTU discovery finds more room.

function

probe_timeout

src/whiplash/quic/connection.pooka:3398
probe_timeout(connection: Connection, space: Int) -> Int
INFERREDfn(whiplash/quic/connection.Connection, Int) -> Int

The probe timeout of a packet number space, in milliseconds (RFC 9002 section 6.2.1): the smoothed round trip, four times its variation, and for 1-RTT the peer's max_ack_delay; it doubles with each timeout that passes without an acknowledgement.

function

on_timeout

src/whiplash/quic/connection.pooka:3415
on_timeout(connection: Connection, now: Int) -> #(List(BitArray), Connection)

Run the timers that are due: declare lost what the loss timer waited for, or after a probe timeout send probes (RFC 9002 section 6.2.4): the frames of the oldest packets in flight again, in up to two packets that may exceed the congestion window. Then send whatever the pacer now allows.

function

next_timeout

src/whiplash/quic/connection.pooka:3536
next_timeout(connection: Connection) -> Option(Int)
INFERREDfn(whiplash/quic/connection.Connection) -> Option(Int)

When on_timeout should next run: a loss timer, a probe timeout, or the pacer letting the next packet go. None when nothing waits.

function

close

src/whiplash/quic/connection.pooka:3561
close(connection: Connection, code: Int, reason: String, now: Int) -> #(
  List(BitArray),
  Connection
)
INFERREDfn(whiplash/quic/connection.Connection, Int, String, Int) -> #(List(BitArray), whiplash/quic/connection.Connection)

Close with a transport error code, telling the peer.

function

fail

src/whiplash/quic/connection.pooka:3596
fail(connection: Connection, code: Int, reason: String) -> Connection

Close because of an error the application found, such as an HTTP/3 error: CONNECTION_CLOSE of the application kind, sent by the next flush.

function

handshake_flight

src/whiplash/quic/connection.pooka:3764
handshake_flight(connection: Connection) -> Option(tls.Flight)

The handshake's flight and secrets, once the ClientHello has been answered. For diagnostics and key logging.

function

reset

src/whiplash/quic/connection.pooka:3771
reset(connection: Connection, stream: Int, code: Int) -> Connection

Abandon sending on a stream (RESET_STREAM with code): what waits is dropped, and so is whatever is sent on it later; a send with fin forgets the stream.

function

stop

src/whiplash/quic/connection.pooka:3777
stop(connection: Connection, stream: Int, code: Int) -> Connection

Ask the peer to stop sending on a stream (STOP_SENDING with code); what it sends meanwhile is still counted, and dropped by the caller.

function

manual

src/whiplash/quic/connection.pooka:3784
manual(connection: Connection, stream: Int) -> Connection

From now on, a stream's window grows only as the application reports bytes consumed with consume, not as they are delivered: a slow reader holds the peer back. Bytes delivered so far count as consumed.

function

consume

src/whiplash/quic/connection.pooka:3799
consume(connection: Connection, stream: Int, size: Int) -> Connection

The application consumed size delivered bytes of a manual stream; the peer may send more once half the window is used.

function

key_phase

src/whiplash/quic/connection.pooka:3903
key_phase(connection: Connection) -> Int

The key phase 1-RTT packets are protected with, 0 or 1. It flips with every key update, whichever end starts it.

function

update_keys

src/whiplash/quic/connection.pooka:3916
update_keys(connection: Connection) -> Result(Connection, Nil)

Start a key update (RFC 9001 section 6.1): new 1-RTT keys in both directions from the next packet on. An error before the handshake is confirmed, or while no packet sent with the current keys has been acknowledged. The connection also updates by itself before its keys have protected a million packets, well inside AES-GCM's limits.

Pooka
let assert Ok(c) = connection.update_keys(c)