1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! SRT ARQ (Automatic Repeat reQuest) reliability engine —
//! `draft-sharabayko-srt-01` §4.8 (Acknowledgement and Lost Packet
//! Handling), §4.8.1 (Packet Acknowledgement — ACKs, ACKACKs), §4.8.2
//! (Packet Retransmission — NAKs), §4.10 (Round-Trip Time Estimation).
//! Curated behavioural rules: `private/specs-verified/rules/srt-arq.md`. The wire field
//! layouts this module drives (ACK/NAK/ACKACK) are the existing
//! [`crate::packet`] codecs — this module never re-encodes them, it only
//! decides *when* to build one and *what* to do with one received.
//!
//! Sans-IO, like the rest of this crate: [`Sender`] and [`Receiver`] never
//! read a wall clock. All timing is driven by a caller-supplied
//! `now: broadcast_common::stage::Timestamp` (monotonic time since a fixed
//! epoch the caller owns) passed to `tick`/`feed_data`/`on_data`/`on_ack`/`on_ackack`.
//!
//! # Module map
//! - [`seq`] — wrap-safe 31-bit sequence-number arithmetic (not itself a
//! `srt-arq.md` rule — the draft does not specify a comparison algorithm;
//! see the module doc there for the resolution).
//! - [`rtt::RttEstimator`] — the rule 29-31 RTT/RTTVar EWMA, shared by both
//! roles (rule 34: a socket's RTT state is really one estimator usable by
//! both a sender and a receiver path).
//! - [`Sender`] — send buffer, NAK-driven retransmit queue, ACK/ACKACK
//! handling (rules 1, 3, 5, 7-10, 15-18, 23-24, 33).
//! - [`Receiver`] — loss detection, Full/Light ACK generation, periodic NAK,
//! ACKACK-driven RTT measurement (rules 4, 8, 11-14, 21-22, 26-30, 32).
//!
//! # Non-goals (explicit follow-ups, not curated as ARQ rules here)
//! - Deciding *when* to apply the TLPKTDROP fake-ACK skip (rule 13) is
//! `srt-tsbpd.md` scope: the receiver can skip a range, the integration layer
//! (the tokio adapter) decides when, and only if TLPKTDROP was negotiated.
//! - RTO-based periodic retransmission without a NAK / congestion control
//! (§5, FileCC) — srt-arq.md is explicit that the RTO formula is
//! congestion-control scope, not curated there.
//! - Send-queue overflow / unsent-packet drop sizing (rules 19-20) — the
//! latency-window math is §4.4/§4.5 scope.
pub use ;
pub use RttEstimator;
pub use Sender;
use crateSrtTimestamp;
use Timestamp;
use Duration;
/// Full ACK timer period — 10 milliseconds (`private/specs-verified/rules/srt-arq.md` rule
/// 11, quoting `draft-sharabayko-srt-01` L2874-2876: "the ACK period or
/// synchronization time interval SYN").
pub const FULL_ACK_PERIOD: Duration = from_millis;
/// Light-ACK packet-count threshold — 64 packets (`private/specs-verified/rules/srt-arq.md`
/// rule 12, L2877-2883): if this many packets have been sent/received
/// within the Full ACK period, the receiver sends a Light ACK early.
pub const LIGHT_ACK_THRESHOLD: u32 = 64;
/// `NAKInterval` floor — 20 milliseconds (`private/specs-verified/rules/srt-arq.md` rule 22,
/// L2953-2960 / L3276): `NAKInterval = max((RTT + 4*RTTVar) / 2, 20ms)`.
pub const NAK_INTERVAL_FLOOR: Duration = from_millis;
/// Convert a [`Duration`] to the wire `Timestamp` field's microsecond
/// `u32` (`draft-sharabayko-srt-01` §3: "microseconds elapsed since the SRT
/// connection was established"), **wrapping** modulo `2^32` once `d` exceeds
/// `u32::MAX` microseconds (about 71.58 minutes) since the caller's epoch —
/// not clamping to `u32::MAX`.
///
/// A clamp (this function's pre-#1063 behavior) makes every packet sent
/// after that point carry the *same* fixed timestamp forever, instead of one
/// that keeps counting up (mod 2^32) the way the field is defined. A real
/// peer's `PktTsbpdTime` formula (`TsbpdTimeBase + PKT_TIMESTAMP + ...`,
/// `private/specs-verified/rules/srt-tsbpd.md` rule 9) would then compute the same constant
/// play time for every such packet — which the peer's receiver clock keeps
/// advancing past, so every packet after the clamp point looks
/// arbitrarily-far too late and gets Too-Late-Packet-Dropped. The receiving
/// side of the same problem — correctly *un*wrapping a peer's wrapped
/// timestamp back into an always-increasing value for `PktTsbpdTime`
/// purposes — is `crate::tsbpd::TsbpdScheduler`'s `unwrap_timestamp`, not
/// this function (this one only ever produces an in-range wire value; it
/// does not need to remember any wrap-count itself, so plain truncation of
/// the microsecond count into 32 bits is exactly "mod 2^32").
pub
/// Convert a [`Timestamp`] to the wire `Timestamp` field's microsecond `u32`
/// (`draft-sharabayko-srt-01` §3), wrapping modulo `2^32` once the
/// microsecond count exceeds `u32::MAX` (about 71.58 minutes) since the
/// caller's epoch — not clamping to `u32::MAX`. See
/// [`duration_to_wire_us`] for why a clamp (instead of a wrap) stalls a real
/// peer's Too-Late-Packet-Drop.
pub
/// `NAKInterval = max((RTT + 4 * RTTVar) / 2, 20 ms)` (`private/specs-verified/rules/srt-arq.md`
/// rule 22, verbatim from `draft-sharabayko-srt-01` L2953-2960, unit
/// resolution cross-referenced from §5.2's L3276 restatement).
pub