Skip to main content

Module sack

Module sack 

Source
Available on crate feature std only.
Expand description

Selective-acknowledgement (SACK) range codec.

§Purpose

Replaces the legacy 4-byte single-sequence ACK payload inside the ENCRYPTED | ACK crate::transport::PhantomPacket control frame with a compact multi-range encoding that lets the sender retire many segments in a single ACK and detect gaps for fast-retransmit.

This is the AEAD plaintext of that control frame — it is NOT the outer frozen PhantomPacket container. Changing this format does NOT require a WIRE_VERSION or PROTOCOL_VERSION bump and does NOT invalidate core/tests/wire_vectors.

§Wire format

All integers are big-endian (network byte order), matching the rest of the Phantom Protocol codec (PacketHeader::to_wire, etc.).

off  0  largest_acked  : u32 be   — the highest sequence number ACKed
off  4  ack_delay_us   : u32 be   — sender-measured ACK delay in µs
off  8  range_count    : u16 be   — number of SACK ranges; ≥ 1, ≤ MAX_SACK_RANGES
off 10  first_len      : u32 be   — length-minus-one of the first (highest) range
off 14  [gap : u32 be, len : u32 be] × (range_count − 1)

§Range encoding

Ranges are stored descending (highest first). The first range is:

high = largest_acked
low  = largest_acked − first_len          (inclusive; first_len is length − 1)

Each subsequent (gap, len) pair descends below the previous range’s low:

high_i = low_{i-1} − 1 − gap             (skip `gap` unACKed sequences)
low_i  = high_i − len                    (len is length − 1)

The “length − 1” convention means len == 0 encodes a single-sequence range (one ACKed packet). gap = number of unACKed sequences between a range’s low and the next (lower) range’s high; gap is always ≥ 1 (adjacent ranges are coalesced by the sender and rejected as Malformed on decode).

§Minimum wire size

rangesbytes
114
222
N10 + 4 + 8×(N−1)

§Decode error conditions

ConditionError
Buffer shorter than declaredTruncated
range_count > MAX_SACK_RANGESTooManyRanges
range_count == 0Malformed
gap == 0 (adjacent ranges)Malformed
gap/len underflows below 0Malformed
resulting range overlaps / is adjacent to previousMalformed

Structs§

Sack
A selective acknowledgement over a per-stream u32 sequence space.

Enums§

SackError
Errors returned by Sack::from_wire.

Constants§

MAX_SACK_RANGES
Maximum number of SACK ranges accepted during decode — anti-DoS bound. A 32-range SACK fits in 262 bytes, well within any AEAD budget.