pub struct FlowController { /* private fields */ }Expand description
Sliding window flow controller with AIMD congestion control and retransmission support.
Implementations§
Source§impl FlowController
impl FlowController
Sourcepub fn new(window_size: usize) -> Self
pub fn new(window_size: usize) -> Self
Create a new flow controller with the given maximum window size.
Sourcepub fn with_rto(window_size: usize, rto_ms: u64) -> Self
pub fn with_rto(window_size: usize, rto_ms: u64) -> Self
Create a flow controller with a custom retransmission timeout.
Sourcepub fn can_send(&self) -> bool
pub fn can_send(&self) -> bool
Returns true if the effective window has space to send another packet.
Sourcepub fn available_slots(&self) -> usize
pub fn available_slots(&self) -> usize
Returns how many more packets can be sent right now.
Sourcepub fn window_size(&self) -> usize
pub fn window_size(&self) -> usize
Returns the hard maximum window size.
Sourcepub fn effective_window(&self) -> usize
pub fn effective_window(&self) -> usize
Returns the effective window: min(cwnd as usize, window_size), at least 1.
Sourcepub fn in_slow_start(&self) -> bool
pub fn in_slow_start(&self) -> bool
Returns true if currently in slow start phase.
Sourcepub fn set_window_size(&mut self, size: usize)
pub fn set_window_size(&mut self, size: usize)
Dynamically adjust the hard maximum window size.
Sourcepub fn in_flight_count(&self) -> usize
pub fn in_flight_count(&self) -> usize
Returns the number of packets currently in flight.
Sourcepub fn oldest_unacked_sequence(&self) -> Option<u64>
pub fn oldest_unacked_sequence(&self) -> Option<u64>
Returns the sequence number of the oldest unacknowledged packet.
Sourcepub fn on_send(&mut self, sequence: u64, data: Vec<u8>) -> bool
pub fn on_send(&mut self, sequence: u64, data: Vec<u8>) -> bool
Register a packet as sent with its data payload (for retransmission).
Returns false if the effective window is full.
Sourcepub fn on_ack(&mut self, sequence: u64) -> bool
pub fn on_ack(&mut self, sequence: u64) -> bool
Register a packet as acknowledged.
Updates RTT estimate and advances congestion window via AIMD.
Returns true if the packet was found and removed.
Sourcepub fn timed_out_packets(&mut self) -> Vec<RetransmitRequest>
pub fn timed_out_packets(&mut self) -> Vec<RetransmitRequest>
Returns all in-flight packets that have exceeded the retransmission timeout.
Returns RetransmitRequests with data to resend.
Triggers AIMD multiplicative decrease on loss.
Sourcepub fn total_sent(&self) -> u64
pub fn total_sent(&self) -> u64
Returns total packets sent.
Sourcepub fn total_acked(&self) -> u64
pub fn total_acked(&self) -> u64
Returns total packets acknowledged.
Sourcepub fn total_lost(&self) -> u64
pub fn total_lost(&self) -> u64
Returns total packets detected as lost.
Sourcepub fn total_retransmits(&self) -> u64
pub fn total_retransmits(&self) -> u64
Returns total retransmissions performed.