Expand description
Window-based flow control for reliable data transmission. Window-based flow control for reliable data transmission.
This module implements a sliding window flow control mechanism that prevents overwhelming the receiver with too much data at once. The window size represents the maximum amount of unacknowledged data (in packets) that can be in flight at any given time.
§Flow Control Strategy
The flow control system uses a dynamic window that adapts to network conditions:
- Window Size: Measured in packets, controls how much data can be sent without acknowledgment
- In-Transit Tracking: Monitors bytes of reliable data waiting for ACK
- Dynamic Adjustment: Window grows during good conditions (low loss, low RTT) and shrinks during poor conditions (high loss, high RTT)
§Window Adjustment Algorithm
The window size adjusts based on:
- Packet loss rate (lower is better)
- Round-trip time (RTT) (lower is better)
Increase conditions: Loss rate < 1% and RTT < 200ms
- Window grows by ~3% (1/32) per adjustment
Decrease conditions: Loss rate > 5% or RTT > 500ms
- Window shrinks by ~6% (1/16) per adjustment
§Example
use bitfold_peer::flow_control::FlowControl;
use bitfold_core::config::Config;
let config = Config::default();
let mut flow_control = FlowControl::new(&config);
// Check if we can send data
if flow_control.can_send_reliable(&config, 0) {
// Send data and record it
flow_control.record_reliable_data_sent(1024);
}
// Later, when data is acknowledged
flow_control.record_reliable_data_acked(1024);
// Periodically adjust window based on network conditions
let loss_rate = 0.02; // 2% loss
let rtt_ms = 150;
flow_control.adjust_window_size(&config, loss_rate, rtt_ms);Structs§
- Flow
Control - Window-based flow control state for managing reliable data transmission.