MacBackend

Trait MacBackend 

Source
pub trait MacBackend: Clone {
    type SendError;
    type CapacityError;
    type RunError;

Show 21 methods // Required methods async fn next_event( &self, on_event: impl FnMut(LocalIdentityId, MacEventRef<'_>), ) -> Result<(), Self::RunError>; async fn add_peer( &self, key: PublicKey, ) -> Result<PeerId, MacBackendError<Self::SendError, Self::CapacityError>>; async fn add_private_channel( &self, key: ChannelKey, ) -> Result<(), MacBackendError<Self::SendError, Self::CapacityError>>; async fn add_named_channel( &self, name: &str, ) -> Result<(), MacBackendError<Self::SendError, Self::CapacityError>>; async fn send_broadcast( &self, from: LocalIdentityId, payload: &[u8], options: &SendOptions, ) -> Result<SendReceipt, MacBackendError<Self::SendError, Self::CapacityError>>; async fn send_multicast( &self, from: LocalIdentityId, channel: &ChannelId, payload: &[u8], options: &SendOptions, ) -> Result<SendReceipt, MacBackendError<Self::SendError, Self::CapacityError>>; async fn send_unicast( &self, from: LocalIdentityId, dst: &PublicKey, payload: &[u8], options: &SendOptions, ) -> Result<Option<SendReceipt>, MacBackendError<Self::SendError, Self::CapacityError>>; async fn send_blind_unicast( &self, from: LocalIdentityId, dst: &PublicKey, channel: &ChannelId, payload: &[u8], options: &SendOptions, ) -> Result<Option<SendReceipt>, MacBackendError<Self::SendError, Self::CapacityError>>; async fn fill_random(&self, dest: &mut [u8]); async fn now_ms(&self) -> u64; async fn register_ephemeral( &self, parent: LocalIdentityId, identity: SoftwareIdentity, ) -> Result<LocalIdentityId, MacBackendError<Self::SendError, Self::CapacityError>>; async fn remove_ephemeral(&self, id: LocalIdentityId) -> bool; // Provided methods async fn remove_peer(&self, key: &PublicKey) -> bool { ... } async fn ensure_transient_peer(&self, key: &PublicKey) -> bool { ... } async fn remove_channel(&self, key: &ChannelKey) -> bool { ... } async fn frame_counter(&self, from: LocalIdentityId) -> Option<u32> { ... } async fn persisted_frame_counter( &self, from: LocalIdentityId, ) -> Option<u32> { ... } async fn for_each_peer(&self, f: &mut dyn FnMut(PublicKey)) { ... } async fn for_each_peer_counter( &self, from: LocalIdentityId, f: &mut dyn FnMut(PublicKey, u32, u32), ) { ... } async fn peer_route(&self, peer: &PublicKey) -> Option<CachedRoute> { ... } async fn clear_peer_route(&self, peer: &PublicKey) -> bool { ... }
}
Expand description

Pluggable backend that the node layer delegates to for MAC operations.

MacHandle implements MacBackend, and test code can provide a lightweight fake. Making the node layer (Host, LocalNode, …) generic over this trait keeps the MAC’s eight fixed-capacity const generics confined to the MacHandle type rather than propagating through every node-layer type and free function.

Required Associated Types§

Source

type SendError

Error type returned by send-oriented operations.

Source

type CapacityError

Error type returned by fixed-capacity operations.

Source

type RunError

Error type returned by the event-loop driver, next_event.

Required Methods§

Source

async fn next_event( &self, on_event: impl FnMut(LocalIdentityId, MacEventRef<'_>), ) -> Result<(), Self::RunError>

Drive the MAC until one wake cycle completes, invoking on_event for each emitted event.

This is the single wake-driven step the node layer builds pump_once / run on top of; it waits for radio activity or a protocol deadline rather than busy-polling.

Source

async fn add_peer( &self, key: PublicKey, ) -> Result<PeerId, MacBackendError<Self::SendError, Self::CapacityError>>

Add or refresh a peer.

Source

async fn add_private_channel( &self, key: ChannelKey, ) -> Result<(), MacBackendError<Self::SendError, Self::CapacityError>>

Add or refresh a private channel.

Source

async fn add_named_channel( &self, name: &str, ) -> Result<(), MacBackendError<Self::SendError, Self::CapacityError>>

Add or refresh a named channel.

Source

async fn send_broadcast( &self, from: LocalIdentityId, payload: &[u8], options: &SendOptions, ) -> Result<SendReceipt, MacBackendError<Self::SendError, Self::CapacityError>>

Queue a broadcast frame.

Source

async fn send_multicast( &self, from: LocalIdentityId, channel: &ChannelId, payload: &[u8], options: &SendOptions, ) -> Result<SendReceipt, MacBackendError<Self::SendError, Self::CapacityError>>

Queue a multicast frame.

Source

async fn send_unicast( &self, from: LocalIdentityId, dst: &PublicKey, payload: &[u8], options: &SendOptions, ) -> Result<Option<SendReceipt>, MacBackendError<Self::SendError, Self::CapacityError>>

Queue a unicast frame.

Source

async fn send_blind_unicast( &self, from: LocalIdentityId, dst: &PublicKey, channel: &ChannelId, payload: &[u8], options: &SendOptions, ) -> Result<Option<SendReceipt>, MacBackendError<Self::SendError, Self::CapacityError>>

Queue a blind-unicast frame.

Source

async fn fill_random(&self, dest: &mut [u8])

Fill dest with random bytes.

Source

async fn now_ms(&self) -> u64

Return the current MAC clock time.

Source

async fn register_ephemeral( &self, parent: LocalIdentityId, identity: SoftwareIdentity, ) -> Result<LocalIdentityId, MacBackendError<Self::SendError, Self::CapacityError>>

Source

async fn remove_ephemeral(&self, id: LocalIdentityId) -> bool

Provided Methods§

Source

async fn remove_peer(&self, key: &PublicKey) -> bool

Remove a peer and its per-peer transport state, reporting whether it was registered.

Source

async fn ensure_transient_peer(&self, key: &PublicKey) -> bool

Ensure key holds at least a transient (unpinned, LRU-evictable) peer slot, so an explicit reply to a stranger can be sent. Reports whether a slot is held.

Source

async fn remove_channel(&self, key: &ChannelKey) -> bool

Remove a channel and its replay state, reporting whether it was registered.

Source

async fn frame_counter(&self, from: LocalIdentityId) -> Option<u32>

Return the live TX frame counter for from, if it identifies a registered identity.

Source

async fn persisted_frame_counter(&self, from: LocalIdentityId) -> Option<u32>

Return the persisted TX frame-counter boundary for from, if registered.

Source

async fn for_each_peer(&self, f: &mut dyn FnMut(PublicKey))

Invoke f for every peer registered in the MAC-layer peer registry.

Covers all known peers, not just those with an active crypto session.

Source

async fn for_each_peer_counter( &self, from: LocalIdentityId, f: &mut dyn FnMut(PublicKey, u32, u32), )

Invoke f for each peer with established crypto state for from. Arguments are (peer public key, last-accepted RX counter, persisted RX boundary).

Source

async fn peer_route(&self, peer: &PublicKey) -> Option<CachedRoute>

Return the route the MAC currently has cached for peer.

Source

async fn clear_peer_route(&self, peer: &PublicKey) -> bool

Forget the route cached for peer, returning whether one was held.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a, P: Platform, const IDENTITIES: usize, const PEERS: usize, const CHANNELS: usize, const ACKS: usize, const TX: usize, const FRAME: usize, const DUP: usize, const RN: usize, const HN: usize> MacBackend for MacHandle<'a, P, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP, RN, HN>

Source§

type SendError = SendError

Source§

type CapacityError = CapacityError

Source§

type RunError = MacError<<<P as Platform>::Radio as Radio>::Error>

Source§

async fn next_event( &self, on_event: impl FnMut(LocalIdentityId, MacEventRef<'_>), ) -> Result<(), Self::RunError>

Source§

async fn add_peer( &self, key: PublicKey, ) -> Result<PeerId, MacBackendError<Self::SendError, Self::CapacityError>>

Source§

async fn remove_peer(&self, key: &PublicKey) -> bool

Source§

async fn ensure_transient_peer(&self, key: &PublicKey) -> bool

Source§

async fn add_private_channel( &self, key: ChannelKey, ) -> Result<(), MacBackendError<Self::SendError, Self::CapacityError>>

Source§

async fn add_named_channel( &self, name: &str, ) -> Result<(), MacBackendError<Self::SendError, Self::CapacityError>>

Source§

async fn remove_channel(&self, key: &ChannelKey) -> bool

Source§

async fn send_broadcast( &self, from: LocalIdentityId, payload: &[u8], options: &SendOptions, ) -> Result<SendReceipt, MacBackendError<Self::SendError, Self::CapacityError>>

Source§

async fn send_multicast( &self, from: LocalIdentityId, channel: &ChannelId, payload: &[u8], options: &SendOptions, ) -> Result<SendReceipt, MacBackendError<Self::SendError, Self::CapacityError>>

Source§

async fn send_unicast( &self, from: LocalIdentityId, dst: &PublicKey, payload: &[u8], options: &SendOptions, ) -> Result<Option<SendReceipt>, MacBackendError<Self::SendError, Self::CapacityError>>

Source§

async fn send_blind_unicast( &self, from: LocalIdentityId, dst: &PublicKey, channel: &ChannelId, payload: &[u8], options: &SendOptions, ) -> Result<Option<SendReceipt>, MacBackendError<Self::SendError, Self::CapacityError>>

Source§

async fn fill_random(&self, dest: &mut [u8])

Source§

async fn now_ms(&self) -> u64

Source§

async fn register_ephemeral( &self, parent: LocalIdentityId, identity: SoftwareIdentity, ) -> Result<LocalIdentityId, MacBackendError<Self::SendError, Self::CapacityError>>

Source§

async fn remove_ephemeral(&self, id: LocalIdentityId) -> bool

Source§

async fn frame_counter(&self, from: LocalIdentityId) -> Option<u32>

Source§

async fn persisted_frame_counter(&self, from: LocalIdentityId) -> Option<u32>

Source§

async fn for_each_peer(&self, f: &mut dyn FnMut(PublicKey))

Source§

async fn for_each_peer_counter( &self, from: LocalIdentityId, f: &mut dyn FnMut(PublicKey, u32, u32), )

Source§

async fn peer_route(&self, peer: &PublicKey) -> Option<CachedRoute>

Source§

async fn clear_peer_route(&self, peer: &PublicKey) -> bool

Implementors§