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§impl LocalLink
impl LocalLink
Sourcepub fn new(
link_id: u64,
peers: &[u64],
limits: Limits,
impairment: Impairment,
) -> Result<LocalLink, LinkError>
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.
pub fn limits(&self) -> Limits
pub fn impairment(&self) -> Impairment
pub fn queued_packets(&self) -> usize
pub fn queued_bytes(&self) -> usize
pub fn endpoint(&self, peer_id: u64) -> Result<Endpoint, LinkError>
Sourcepub fn send(
&mut self,
from: Endpoint,
to: Endpoint,
bytes: &[u8],
now: Duration,
) -> Result<(), LinkError>
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.
Sourcepub fn receive(
&mut self,
to: Endpoint,
now: Duration,
output: &mut [u8],
) -> Result<Option<Delivery>, LinkError>
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.
Sourcepub fn reset_endpoint(
&mut self,
peer: Endpoint,
now: Duration,
) -> Result<Endpoint, LinkError>
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());