Skip to main content

FlowControl

Struct FlowControl 

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

Window-based flow control state for managing reliable data transmission.

This struct encapsulates the state needed for sliding window flow control, including the current window size and tracking of in-transit reliable data.

Implementations§

Source§

impl FlowControl

Source

pub fn new(config: &Config) -> Self

Creates a new flow control instance with configuration defaults.

§Arguments
  • config - Configuration containing initial window size and limits
§Example
use bitfold_peer::flow_control::FlowControl;
use bitfold_core::config::Config;

let config = Config::default();
let flow_control = FlowControl::new(&config);
Source

pub fn window_size(&self) -> u32

Returns the current window size (in packets).

The window size represents the maximum number of packets that can be in flight (unacknowledged) at any given time.

Source

pub fn reliable_data_in_transit(&self) -> u32

Returns the amount of reliable data currently in transit (in bytes).

This tracks the total bytes of reliable data that have been sent but not yet acknowledged by the receiver.

Source

pub fn set_window_size(&mut self, config: &Config, window_size: u32)

Sets the window size (for negotiation during handshake).

The provided window size will be clamped to the configured min/max bounds.

§Arguments
  • config - Configuration containing min and max window size limits
  • window_size - Desired window size (will be clamped to min/max)
Source

pub fn record_reliable_data_sent(&mut self, data_size: u32)

Records reliable data being sent (adds to in-transit counter).

Call this method whenever reliable data is transmitted to track how much data is waiting for acknowledgment.

§Arguments
  • data_size - Size of the data being sent, in bytes
Source

pub fn record_reliable_data_acked(&mut self, data_size: u32)

Records reliable data being acknowledged (removes from in-transit counter).

Call this method when an acknowledgment is received to reduce the amount of tracked in-transit data.

§Arguments
  • data_size - Size of the data being acknowledged, in bytes
Source

pub fn can_send_reliable(&self, config: &Config, packets_in_flight: u16) -> bool

Checks if we can send more data based on window-based flow control.

Returns true if we have room in the window, false if the window is full. When window flow control is disabled, this falls back to checking a simple packet count limit.

§Arguments
  • config - Configuration containing window control settings
  • packets_in_flight - Current number of unacknowledged packets (used when window flow control is disabled)
§Returns

true if more reliable data can be sent, false if the window is full

Source

pub fn adjust_window_size( &mut self, config: &Config, loss_rate: f32, rtt_ms: u32, )

Dynamically adjusts the window size based on network conditions.

This should be called periodically to adapt the window size to changing network conditions. The window grows during good conditions and shrinks during poor conditions.

§Adjustment Logic
  • Increase: When loss rate < 1% and RTT < 200ms, grow window by ~3% (1/32)
  • Decrease: When loss rate > 5% or RTT > 500ms, shrink window by ~6% (1/16)
  • No change: Otherwise maintain current window size

The window size is always clamped to the configured min/max bounds.

§Arguments
  • config - Configuration containing window control settings and limits
  • loss_rate - Current packet loss rate (0.0 to 1.0)
  • rtt_ms - Current round-trip time in milliseconds

Trait Implementations§

Source§

impl Clone for FlowControl

Source§

fn clone(&self) -> FlowControl

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FlowControl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FlowControl

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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