Skip to main content

ResendSender

Struct ResendSender 

Source
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

Source

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.

Source

pub fn base(&self) -> u8

Returns the current base sequence number (oldest unacknowledged frame).

Source

pub fn next_seq(&self) -> u8

Returns the next sequence number to be assigned.

Source

pub fn in_flight(&self) -> u8

Returns the number of frames currently in flight.

Source

pub fn can_send(&self) -> bool

Returns true if another frame can be transmitted within the sliding window.

Source

pub fn is_idle(&self) -> bool

Returns true if there are no in-flight unacknowledged frames.

Source

pub fn retransmission_attempts(&self) -> usize

Returns the number of consecutive retransmission attempts made for the current window.

Source

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.

Source

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.

Source

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.

Source

pub fn reset(&mut self)

Resets the sender to an empty initial state.

Trait Implementations§

Source§

impl Debug for ResendSender

Source§

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

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

impl Default for ResendSender

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, 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, 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.