pub trait MacBackend: Clone {
type SendError;
type CapacityError;
type RunError;
Show 23 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 for_each_transmitter_observation(
&self,
f: &mut dyn FnMut(TransmitterObservation),
) { ... }
async fn peer_route(&self, peer: &PublicKey) -> Option<CachedRoute> { ... }
async fn clear_peer_route(&self, peer: &PublicKey) -> bool { ... }
async fn restore_peer_route(
&self,
peer: &PublicKey,
route: CachedRoute,
) -> 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§
Sourcetype CapacityError
type CapacityError
Error type returned by fixed-capacity operations.
Sourcetype RunError
type RunError
Error type returned by the event-loop driver, next_event.
Required Methods§
Sourceasync fn next_event(
&self,
on_event: impl FnMut(LocalIdentityId, MacEventRef<'_>),
) -> Result<(), Self::RunError>
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.
Sourceasync fn add_peer(
&self,
key: PublicKey,
) -> Result<PeerId, MacBackendError<Self::SendError, Self::CapacityError>>
async fn add_peer( &self, key: PublicKey, ) -> Result<PeerId, MacBackendError<Self::SendError, Self::CapacityError>>
Add or refresh a peer.
Sourceasync fn add_private_channel(
&self,
key: ChannelKey,
) -> Result<(), MacBackendError<Self::SendError, Self::CapacityError>>
async fn add_private_channel( &self, key: ChannelKey, ) -> Result<(), MacBackendError<Self::SendError, Self::CapacityError>>
Add or refresh a private channel.
Sourceasync fn add_named_channel(
&self,
name: &str,
) -> Result<(), MacBackendError<Self::SendError, Self::CapacityError>>
async fn add_named_channel( &self, name: &str, ) -> Result<(), MacBackendError<Self::SendError, Self::CapacityError>>
Add or refresh a named channel.
Sourceasync fn send_broadcast(
&self,
from: LocalIdentityId,
payload: &[u8],
options: &SendOptions,
) -> Result<SendReceipt, MacBackendError<Self::SendError, Self::CapacityError>>
async fn send_broadcast( &self, from: LocalIdentityId, payload: &[u8], options: &SendOptions, ) -> Result<SendReceipt, MacBackendError<Self::SendError, Self::CapacityError>>
Queue a broadcast frame.
Sourceasync fn send_multicast(
&self,
from: LocalIdentityId,
channel: &ChannelId,
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>>
Queue a multicast frame.
Sourceasync fn send_unicast(
&self,
from: LocalIdentityId,
dst: &PublicKey,
payload: &[u8],
options: &SendOptions,
) -> Result<Option<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>>
Queue a unicast frame.
Sourceasync 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 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.
Sourceasync fn fill_random(&self, dest: &mut [u8])
async fn fill_random(&self, dest: &mut [u8])
Fill dest with random bytes.
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§
Sourceasync fn remove_peer(&self, key: &PublicKey) -> bool
async fn remove_peer(&self, key: &PublicKey) -> bool
Remove a peer and its per-peer transport state, reporting whether it was registered.
Sourceasync fn ensure_transient_peer(&self, key: &PublicKey) -> bool
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.
Sourceasync fn remove_channel(&self, key: &ChannelKey) -> bool
async fn remove_channel(&self, key: &ChannelKey) -> bool
Remove a channel and its replay state, reporting whether it was registered.
Sourceasync fn frame_counter(&self, from: LocalIdentityId) -> Option<u32>
async fn frame_counter(&self, from: LocalIdentityId) -> Option<u32>
Return the live TX frame counter for from, if it identifies a registered identity.
Sourceasync fn persisted_frame_counter(&self, from: LocalIdentityId) -> Option<u32>
async fn persisted_frame_counter(&self, from: LocalIdentityId) -> Option<u32>
Return the persisted TX frame-counter boundary for from, if registered.
Sourceasync fn for_each_peer(&self, f: &mut dyn FnMut(PublicKey))
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.
Sourceasync fn for_each_peer_counter(
&self,
from: LocalIdentityId,
f: &mut dyn FnMut(PublicKey, u32, u32),
)
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).
Sourceasync fn for_each_transmitter_observation(
&self,
f: &mut dyn FnMut(TransmitterObservation),
)
async fn for_each_transmitter_observation( &self, f: &mut dyn FnMut(TransmitterObservation), )
Invoke f for each transmitter the radio has heard, with the most
recent measurements from it.
This is what a peer-repeater listing reports about the hops it names: a frame forwarded past this node or simply overheard proves a neighbor was on the air, and no peer-oriented view sees it.
Sourceasync fn peer_route(&self, peer: &PublicKey) -> Option<CachedRoute>
async fn peer_route(&self, peer: &PublicKey) -> Option<CachedRoute>
Return the route the MAC currently has cached for peer.
Sourceasync fn clear_peer_route(&self, peer: &PublicKey) -> bool
async fn clear_peer_route(&self, peer: &PublicKey) -> bool
Forget the route cached for peer, returning whether one was held.
Sourceasync fn restore_peer_route(&self, peer: &PublicKey, route: CachedRoute) -> bool
async fn restore_peer_route(&self, peer: &PublicKey, route: CachedRoute) -> bool
Install a route learned before this MAC existed, returning whether
peer was registered to receive it.
A backend that keeps no route cache accepts none, which is the
same answer it gives to Self::peer_route.
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.