pub struct Sack {
pub largest_acked: u32,
pub ack_delay_us: u32,
/* private fields */
}Expand description
A selective acknowledgement over a per-stream u32 sequence space.
ranges are inclusive (low, high) runs of acknowledged sequences,
sorted descending (highest first), non-overlapping and non-adjacent.
ranges[0].1 == largest_acked. An empty ranges slice is invalid — a
Sack always ACKs at least one sequence.
Fields§
§largest_acked: u32The highest sequence number covered by this ACK.
ack_delay_us: u32Sender-measured delay between receiving the data packet and generating this ACK, in microseconds. Used by the BBR / RTT estimator.
Implementations§
Source§impl Sack
impl Sack
Sourcepub fn from_received(received: &[u32], ack_delay_us: u32) -> Option<Sack>
pub fn from_received(received: &[u32], ack_delay_us: u32) -> Option<Sack>
Build a Sack from an unordered slice of received sequence numbers.
Coalesces adjacent or overlapping sequences into the minimal set of
inclusive (low, high) ranges sorted descending (highest first).
Returns None if received is empty (there is nothing to ACK).
Sourcepub fn from_inclusive_ranges(
ranges: Vec<(u32, u32)>,
ack_delay_us: u32,
) -> Option<Sack>
pub fn from_inclusive_ranges( ranges: Vec<(u32, u32)>, ack_delay_us: u32, ) -> Option<Sack>
Build a Sack from explicit inclusive (low, high) ranges in any order
(each must have low <= high). Ranges are sorted ascending, coalesced
(adjacent/overlapping merged), reversed to descending, and capped to the
highest MAX_SACK_RANGES so the encoded SACK always decodes at the peer
(from_wire rejects range_count > MAX_SACK_RANGES). Dropping the lowest
ranges is safe: those sequences are recovered by cumulative re-ACK as holes
fill, or by RTO. Returns None if ranges is empty.
Sourcepub fn ranges(&self) -> &[(u32, u32)]
pub fn ranges(&self) -> &[(u32, u32)]
Returns the inclusive (low, high) ranges, sorted descending (highest
first), non-overlapping and non-adjacent. Always non-empty.
Sourcepub fn to_wire(&self) -> Vec<u8> ⓘ
pub fn to_wire(&self) -> Vec<u8> ⓘ
Serialise to wire bytes.
Panics are structurally impossible: ranges is always non-empty (the
invariant is enforced by the private field — only from_received and
from_wire can construct a Sack, both of which guarantee at least one
range), and the arithmetic cannot overflow because all fields fit in
u32.