pub struct ResendSender { /* private fields */ }Expand description
Go-Back-N sliding-window sender state machine.
Encapsulates sequence allocation, in-flight frame buffering, sliding-window bounds checks, cumulative ACK processing, round-trip time measurement, and timeout retransmission gathering.
Implementations§
Source§impl ResendSender
impl ResendSender
Sourcepub fn new(window_size: u8, max_retransmission_attempts: usize) -> Self
pub fn new(window_size: u8, max_retransmission_attempts: usize) -> Self
Creates a new sender state machine with the specified window size and retransmission limit.
§Panics
Panics if window_size == 0 or window_size > 128, or if max_retransmission_attempts == 0.
Sourcepub fn base(&self) -> u8
pub fn base(&self) -> u8
Returns the current base sequence number (oldest unacknowledged frame).
Sourcepub fn can_send(&self) -> bool
pub fn can_send(&self) -> bool
Returns true if another frame can be transmitted within the sliding window.
Sourcepub fn retransmission_attempts(&self) -> usize
pub fn retransmission_attempts(&self) -> usize
Returns the number of consecutive retransmission attempts made for the current window.
Sourcepub fn enqueue_frame(
&mut self,
session_id: u32,
channel_id: u16,
frame_type: FrameType,
payload: &[u8],
) -> Result<(u8, Vec<u8>), FrameError>
pub fn enqueue_frame( &mut self, session_id: u32, channel_id: u16, frame_type: FrameType, payload: &[u8], ) -> Result<(u8, Vec<u8>), FrameError>
Enqueues and encodes a new frame to be transmitted.
§Note
This method is intended exclusively for sequenced outbound frames (such as
FrameType::Data). Pure cumulative acknowledgments (FrameType::Ack) must
not be enqueued into the sliding window; emit them directly using encode_frame
or coordinate them via [AckTracker].
§Errors
Returns FrameError::WindowFull if in_flight() >= window_size.
Returns FrameError::PayloadTooLarge if payload.len() > MAX_PAYLOAD_SIZE.
Sourcepub fn handle_ack(&mut self, ack_seq: u8) -> AckOutcome
pub fn handle_ack(&mut self, ack_seq: u8) -> AckOutcome
Processes an incoming cumulative acknowledgment.
If ack_seq is within [base, next_seq), all frames from base through
ack_seq are removed from the buffer, base is advanced to ack_seq + 1,
retransmission attempts are reset to 0, and the elapsed RTT for ack_seq
is returned in AckOutcome::Advanced.
Sourcepub fn handle_timeout(
&mut self,
) -> Result<Vec<Vec<u8>>, RetransmissionLimitExceeded>
pub fn handle_timeout( &mut self, ) -> Result<Vec<Vec<u8>>, RetransmissionLimitExceeded>
Handles a retransmission timer timeout.
Increments retransmission_attempts. If the limit is reached, returns
Err(RetransmissionLimitExceeded). Otherwise, gathers and returns clones of all
unacknowledged frames from base to next_seq and updates their transmission
timestamps.
§Errors
Returns RetransmissionLimitExceeded if retransmission_attempts >= max_retransmission_attempts.
Callers should call reset() before reusing the sender after exceeding the limit.