Struct LocalLink

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

Bounded datagram storage; no global/shared transport state or implicit I/O. See the module recipe and FPS local_session example for driver composition.

Implementations§

Source

pub fn new( link_id: u64, peers: &[u64], limits: Limits, impairment: Impairment, ) -> Result<LocalLink, LinkError>

Reserve the complete configured storage. Peer IDs may be zero but must be distinct; link_id must be nonzero and lifetime-unique in the host.

Source

pub fn limits(&self) -> Limits

Source

pub fn impairment(&self) -> Impairment

Source

pub fn queued_packets(&self) -> usize

Source

pub fn queued_bytes(&self) -> usize

Source

pub fn endpoint(&self, peer_id: u64) -> Result<Endpoint, LinkError>

Source

pub fn send( &mut self, from: Endpoint, to: Endpoint, bytes: &[u8], now: Duration, ) -> Result<(), LinkError>

Admit one complete opaque datagram. Bytes need not be a valid protocol packet: codecs/drivers retain that responsibility. Errors never consume an impairment ordinal, capacity or time. Same-peer sends reject.

Source

pub fn receive( &mut self, to: Endpoint, now: Duration, output: &mut [u8], ) -> Result<Option<Delivery>, LinkError>

Remove at most one due packet for this destination. Short output rejects without removing even a loss record; empty/lost output stays unchanged. Work scans <=4096 slots and moves at most one slot (swap removal). A loss still consumes its admitted packet/byte capacity until removed.

Source

pub fn reset_endpoint( &mut self, peer: Endpoint, now: Duration, ) -> Result<Endpoint, LinkError>

Invalidate one endpoint and cancel both directions, preserving time and the global impairment ordinal. The returned handle is the only fresh one.

use ferravex_net::local_link::{LocalLink, Limits, Impairment};
use std::time::Duration;
let mut link = LocalLink::new(77, &[1, 2], Limits::default(), Impairment::default())?;
let old = link.endpoint(1)?;
let fresh = link.reset_endpoint(old, Duration::ZERO)?;
assert_ne!(old, fresh);
link.dispose(fresh, Duration::ZERO)?;
assert!(link.endpoint(1).is_err());
Source

pub fn dispose( &mut self, peer: Endpoint, now: Duration, ) -> Result<(), LinkError>

Permanently remove a peer and all its traffic. Repeated disposal rejects.

Source

pub fn reset(&mut self, now: Duration) -> Result<(), LinkError>

Clear traffic and reset impairment ordinal, invalidating all live handles. Disposed peers stay disposed; time cannot be rewound or re-originated.

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.