Skip to main content

FlowController

Struct FlowController 

Source
pub struct FlowController { /* private fields */ }
Expand description

Sliding window flow controller with AIMD congestion control and retransmission support.

Implementations§

Source§

impl FlowController

Source

pub fn new(window_size: usize) -> Self

Create a new flow controller with the given maximum window size.

Source

pub fn with_rto(window_size: usize, rto_ms: u64) -> Self

Create a flow controller with a custom retransmission timeout.

Source

pub fn can_send(&self) -> bool

Returns true if the effective window has space to send another packet.

Source

pub fn available_slots(&self) -> usize

Returns how many more packets can be sent right now.

Source

pub fn window_size(&self) -> usize

Returns the hard maximum window size.

Source

pub fn cwnd(&self) -> f64

Returns the current congestion window size.

Source

pub fn effective_window(&self) -> usize

Returns the effective window: min(cwnd as usize, window_size), at least 1.

Source

pub fn in_slow_start(&self) -> bool

Returns true if currently in slow start phase.

Source

pub fn set_window_size(&mut self, size: usize)

Dynamically adjust the hard maximum window size.

Source

pub fn in_flight_count(&self) -> usize

Returns the number of packets currently in flight.

Source

pub fn oldest_unacked_sequence(&self) -> Option<u64>

Returns the sequence number of the oldest unacknowledged packet.

Source

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.

Source

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.

Source

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.

Source

pub fn srtt(&self) -> Option<Duration>

Returns the current smoothed RTT estimate.

Source

pub fn rttvar(&self) -> Option<Duration>

Returns the current RTT variance estimate.

Source

pub fn rto(&self) -> Duration

Returns the current retransmission timeout.

Source

pub fn total_sent(&self) -> u64

Returns total packets sent.

Source

pub fn total_acked(&self) -> u64

Returns total packets acknowledged.

Source

pub fn total_lost(&self) -> u64

Returns total packets detected as lost.

Source

pub fn total_retransmits(&self) -> u64

Returns total retransmissions performed.

Source

pub fn loss_rate(&self) -> f64

Returns the packet loss rate: lost / sent.

Source

pub fn is_acked(&self, sequence: u64) -> bool

Returns true if a sequence number has been acknowledged.

Source

pub fn reset(&mut self)

Reset all state.

Trait Implementations§

Source§

impl Default for FlowController

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more