Skip to main content

Encoder

Struct Encoder 

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

Sender side: groups items into FEC-protected blocks and answers ARQ retransmit requests.

Implementations§

Source§

impl Encoder

Source

pub fn new(k: usize, r: usize, max_item: usize) -> Self

Create an encoder. k data shards per block, initial r parity shards (clamped to r_min..=r_max), max_item largest item byte length.

Source

pub fn coding_counts(&self) -> (u64, u64)

Blocks sealed at zero parity (Passthrough) so far, and blocks sealed with parity. A nonzero first value proves FEC actually switched off on the wire; the ratio shows how much of the stream rode unprotected.

Source

pub fn enable_tower(&mut self, d: usize, r_outer: usize)

Enable the tower outer code: every d data blocks ship with r_outer fire-and-forget outer-parity blocks that recover whole lost data blocks without a retransmit. (0, _) or (_, 0) disables it.

Source

pub fn with_flow_window(self, blocks: u32) -> Self

Set the in-flight flow window (blocks sent but not yet acked). Match this to the receiver’s Decoder::with_window.

Source

pub fn set_flow_window(&mut self, blocks: u32)

Adjust the in-flight flow window at runtime - the bufferbloat pacer shrinks it toward the BDP to drain a self-induced queue, and restores it when the queue clears. The receiver’s window is the hard ceiling, so the pacer only ever clamps DOWN from the configured maximum.

Source

pub fn flow_window(&self) -> u32

Current in-flight flow window (blocks).

Source

pub fn in_flight(&self) -> u32

Blocks sent but not yet acked by the receiver.

Source

pub fn flow_blocked(&self) -> bool

true when the producer should pause sending new blocks until an ack frees window space (keeps the receiver’s bounded window from dropping far-ahead blocks).

Source

pub fn max_item(&self) -> usize

Largest item this encoder accepts.

Source

pub fn parity(&self) -> usize

Current parity count.

Source

pub fn next_block_id(&self) -> u32

The id the NEXT sealed block will take; the block just sealed by a non-empty push / flush is this minus one. Lets the sender record a per-block send time for RTT sampling.

Source

pub fn push(&mut self, item: &[u8]) -> Vec<Vec<u8>>

Stage item for transmission. Returns the datagrams to send when the staged set reaches k items (a full block); otherwise an empty vec. Call flush to force a short final block.

Source

pub fn flush(&mut self) -> Vec<Vec<u8>>

Force the staged items (fewer than k) into a final padded block. Returns its datagrams, or empty if nothing is staged.

Source

pub fn set_parity(&mut self, r: usize)

Set the parity shards per new block, clamped to the encoder’s [r_min, r_max]. The fusion controller drives this from the control table; the encoder no longer self-adapts parity.

Source

pub fn set_parity_covering(&mut self, floor: usize, loss: f32)

Set parity to at least floor (the fusion controller’s burst / feed-forward signal) AND enough to FEC-recover a loss fraction of THIS block: to recover a fraction p of the k + r shards, r / (k + r) >= p, i.e. r >= p * k / (1 - p). A 20% margin covers a spike above the mean. Capped at r_max (the bitmap ceiling). Without this, parity tracked only the controller’s modest floor and a high-loss block fell to ARQ round trips instead of recovering in-FEC; this lets block-RS provision to the loss the way the sliding-window RLC rate law already does.

Source

pub fn on_feedback(&mut self, fb: &Feedback) -> Vec<Vec<u8>>

Apply receiver feedback: free acked blocks and return any ARQ retransmit datagrams. Parity adaptation is the controller’s job (see set_parity), not this method’s.

Source

pub fn pending_len(&self) -> usize

Number of unacked blocks held for ARQ.

Source

pub fn oldest_pending(&self) -> Option<u32>

The oldest unacked block id - the one the receiver’s in-order frontier is waiting on - or None if everything is acked.

Source

pub fn probe_block(&self, block_id: u32) -> Vec<Vec<u8>>

Retransmit datagrams (flagged RETRANSMIT) for the k DATA shards of one pending block - a liveness probe that also pre-positions the block the receiver’s frontier is stalled on. Empty if the block is already acked.

Source

pub fn retransmit_all_data(&self) -> Vec<Vec<u8>>

Retransmit datagrams (flagged RETRANSMIT) for the k DATA shards of EVERY pending block, oldest-first - the proactive burst on link recovery that resends the whole unacked window WITHOUT waiting for the receiver’s NAKs (the sender already holds the exact unacked set, so no estimation is needed). The receiver dedups any datagram it already has via its D-SACK / false-recovery path, so over-resending is safe. k data shards per block suffice to decode a fully-lost block; any shard still missing after the burst is recovered by the normal reactive NAK.

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