pub struct FileCc { /* private fields */ }Expand description
SRT File Transfer Congestion Control — sender-side window + pacing state
(draft-sharabayko-srt-01 §5.2). See the module doc for the full formula
mapping, the sans-IO contract, and the two flagged spec gaps.
Implementations§
Source§impl FileCc
impl FileCc
Sourcepub fn new(initial_seqno: u32) -> Self
pub fn new(initial_seqno: u32) -> Self
A fresh FileCC engine in Slow Start (rule 4: “runs exactly once at the beginning of a connection”).
initial_seqno seeds LAST_ACK_SEQNO (see the field doc) — pass the
connection’s initial sequence number (ISN) minus one, or the ISN
itself if no data has been sent yet; either way the first ACK’s
CWND_SIZE growth (Step 3) reflects exactly the packets actually
acknowledged since then.
Sourcepub fn pkt_snd_period_us(&self) -> f64
pub fn pkt_snd_period_us(&self) -> f64
The current PKT_SND_PERIOD, in microseconds (as an f64 — the
Congestion Avoidance formulas are inherently fractional).
Sourcepub fn pkt_snd_period(&self) -> Duration
pub fn pkt_snd_period(&self) -> Duration
The current PKT_SND_PERIOD as a Duration, for a sender to
consult before transmitting the next packet (same role as
crate::livecc::LiveCC::on_ack_received’s return value).
Truncates the microsecond value toward zero (consistent with this
crate’s existing integer-truncation convention, e.g. LiveCC’s
PKT_SND_PERIOD).
Sourcepub fn max_cwnd_size(&self) -> f64
pub fn max_cwnd_size(&self) -> f64
The current MAX_CWND_SIZE (rule 8), in packets.
Sourcepub fn set_max_cwnd_size(&mut self, packets: f64)
pub fn set_max_cwnd_size(&mut self, packets: f64)
Reconfigure MAX_CWND_SIZE — rule 8 calls the 12 MB-derived default
a settable/recommended value, not a hardwired constant.
Sourcepub fn max_bw_bytes_per_sec(&self) -> Option<u64>
pub fn max_bw_bytes_per_sec(&self) -> Option<u64>
The current MAX_BW clamp, in bytes/sec (None = unbounded).
Sourcepub fn set_max_bw_bytes_per_sec(&mut self, max_bw: Option<u64>)
pub fn set_max_bw_bytes_per_sec(&mut self, max_bw: Option<u64>)
Reconfigure MAX_BW (rule 15: MAXBW_SET mode only applies to file
transfer; there is no default, None is unbounded).
Sourcepub fn receiving_rate_pps(&self) -> u64
pub fn receiving_rate_pps(&self) -> u64
The last RECEIVING_RATE fed via FileCc::on_ack, packets/sec.
Sourcepub fn est_link_capacity_pps(&self) -> u64
pub fn est_link_capacity_pps(&self) -> u64
The last EST_LINK_CAPACITY fed via FileCc::on_ack, packets/sec.
Sourcepub fn rtt(&self) -> Duration
pub fn rtt(&self) -> Duration
The last RTT fed via FileCc::on_ack (or the initial 100 ms
default before the first ACK).
Sourcepub fn b_loss(&self) -> bool
pub fn b_loss(&self) -> bool
bLoss — true if a loss has been reported since the last rate
increase (rule 11-12).
Sourcepub fn avg_nak_num(&self) -> f64
pub fn avg_nak_num(&self) -> f64
AvgNAKNum — the average number of NAKs per congestion period
(rule 20’s EWMA).
Sourcepub fn nak_count(&self) -> u32
pub fn nak_count(&self) -> u32
NAKCount — NAKs received so far in the current congestion period.
Sourcepub fn dec_count(&self) -> u32
pub fn dec_count(&self) -> u32
DecCount — rate decreases applied so far in the current congestion
period.
Sourcepub fn last_dec_seq(&self) -> Option<u32>
pub fn last_dec_seq(&self) -> Option<u32>
LastDecSeq — the largest sent sequence number at the last rate
decrease / congestion-period boundary, or None if no
Congestion-Avoidance-phase loss has occurred yet.
Sourcepub fn last_dec_period_us(&self) -> f64
pub fn last_dec_period_us(&self) -> f64
LastDecPeriod, in microseconds (item under Step 5; initial value 1
microsecond).
Sourcepub fn on_ack(
&mut self,
now: Duration,
ack_seqno: u32,
receiving_rate_pps: u64,
est_link_capacity_pps: u64,
rtt: Duration,
)
pub fn on_ack( &mut self, now: Duration, ack_seqno: u32, receiving_rate_pps: u64, est_link_capacity_pps: u64, rtt: Duration, )
On full-ACK packet reception (specs/rules/srt-congestion.md,
§5.2.1.1 “(1) On ACK packet reception” / §5.2.1.2 “(1) On ACK packet
reception”). Only full ACKs trigger a rate increase (rule 3,
L3313-3314) — a light ACK must not be passed to this method.
now — the current time (Step 1’s currTime).
ack_seqno — the ACK’s acknowledged sequence number (ACK_SEQNO).
receiving_rate_pps / est_link_capacity_pps — the ACK-carried,
receiver-reported rate estimates (§5.2.1.3); see the module doc’s
gap-1 resolution for why these are stored verbatim, not smoothed
here.
rtt — the current (already-smoothed elsewhere) RTT estimate.
Sourcepub fn on_loss(
&mut self,
lost_seqno: u32,
largest_sent_seqno: u32,
loss_ratio: f64,
)
pub fn on_loss( &mut self, lost_seqno: u32, largest_sent_seqno: u32, loss_ratio: f64, )
On a loss report (NAK) packet reception.
- During Slow Start (rule 9): ends slow start;
PKT_SND_PERIODis set exactly as in the ACK Step 5 formula.lost_seqno,largest_sent_seqno, andloss_ratioare not consulted by this phase’s handling (the draft’s rule 9 gives no further formula). - During Congestion Avoidance (§5.2.1.2 “(2)”, L3568-3658): runs the full bLoss/loss-ratio-tolerance/congestion-period/repeat-decrease state machine.
lost_seqno — the sequence number reported lost by this NAK.
largest_sent_seqno — the largest sequence number sent so far
(recorded as the new LastDecSeq on a decrease, rules 22/29).
loss_ratio — the sender’s current estimated loss ratio (rule 16’s
“less than 2%” tolerance check), e.g. lost/sent over a recent window.
Sourcepub fn on_timeout(&mut self)
pub fn on_timeout(&mut self)
On a retransmission timeout (RTO) event.
During Slow Start (rule 10): ends slow start, PKT_SND_PERIOD set
exactly as in the ACK Step 5 formula (same as FileCc::on_loss’s
slow-start handling). Once in Congestion Avoidance, this section does
not describe an RTO-specific FileCC reaction (RTO-driven
retransmission itself is the ARQ engine’s concern, srt-arq.md) —
calling this while already in Congestion Avoidance is a no-op.
Sourcepub fn tick(&mut self, _now: Duration)
pub fn tick(&mut self, _now: Duration)
Time-driven tick — currently a no-op (mirrors
crate::livecc::LiveCC::tick). Provided for forward compatibility:
this section’s algorithm is driven entirely by the three named
events (send / ACK / timeout, rule 5); there is no additional
periodic-only state transition to run here.