MacHandle

Struct MacHandle 

Source
pub struct MacHandle<'a, P: Platform, const IDENTITIES: usize = DEFAULT_IDENTITIES, const PEERS: usize = DEFAULT_PEERS, const CHANNELS: usize = DEFAULT_CHANNELS, const ACKS: usize = DEFAULT_ACKS, const TX: usize = DEFAULT_TX, const FRAME: usize = DEFAULT_FRAME, const DUP: usize = DEFAULT_DUP> { /* private fields */ }
Expand description

Lightweight, cloneable handle for queuing MAC operations against shared state.

The handle borrows a RefCell that owns the underlying coordinator, which keeps queuing and configuration operations lightweight while the main MAC run loop continues to own radio receive/transmit progression.

Implementations§

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> MacHandle<'a, P, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP>

Source

pub fn new( mac: &'a RefCell<Mac<P, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP>>, ) -> Self

Creates a cloneable handle backed by shared coordinator state.

Source

pub fn add_identity( &self, identity: P::Identity, ) -> Result<LocalIdentityId, MacHandleError<CapacityError>>

Registers a local identity with the shared coordinator.

Source

pub async fn load_persisted_counter( &self, id: LocalIdentityId, ) -> Result<u32, MacHandleError<CounterPersistenceError<<P::CounterStore as CounterStore>::Error>>>

Load the persisted frame-counter boundary for one identity.

Source

pub async fn service_counter_persistence( &self, ) -> Result<usize, MacHandleError<<P::CounterStore as CounterStore>::Error>>

Persist all currently scheduled frame-counter reservations.

Source

pub fn add_peer( &self, key: PublicKey, ) -> Result<PeerId, MacHandleError<CapacityError>>

Registers or refreshes a remote peer in the shared registry.

Source

pub fn add_channel( &self, key: ChannelKey, ) -> Result<(), MacHandleError<CapacityError>>

Adds or updates a shared channel and derives its multicast keys.

Source

pub fn add_named_channel( &self, name: &str, ) -> Result<(), MacHandleError<CapacityError>>

Adds or updates a named channel using the coordinator’s channel-key derivation.

Source

pub fn auto_register_full_key_peers( &self, ) -> Result<bool, MacHandleError<Infallible>>

Return whether inbound secure packets carrying a full source key may auto-register peers.

Source

pub fn set_auto_register_full_key_peers( &self, enabled: bool, ) -> Result<(), MacHandleError<Infallible>>

Enable or disable inbound full-key peer auto-registration.

Source

pub fn install_pairwise_keys_advanced( &self, identity_id: LocalIdentityId, peer_id: PeerId, pairwise_keys: PairwiseKeys, ) -> Result<Option<PeerCryptoState>, MacHandleError<SendError>>

Installs pairwise transport keys for one local identity and remote peer.

§Safety (logical)

Installing wrong keys will silently corrupt the session. This method is deliberately gated behind the unsafe-advanced feature. Prefer going through the node-layer PFS session manager instead.

Source

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

Enqueues a broadcast frame for transmission.

Returns a SendReceipt for tracking transmission progress.

Source

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

Enqueues a multicast frame for transmission.

Returns a SendReceipt for tracking transmission progress.

Source

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

Enqueues a unicast frame for transmission.

Returns a SendReceipt when options.ack_requested is enabled.

Source

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

Enqueues a blind-unicast frame for transmission.

Returns a SendReceipt when options.ack_requested is enabled.

Source

pub async fn next_event( &self, on_event: impl FnMut(LocalIdentityId, MacEventRef<'_>), ) -> Result<(), MacHandleError<MacError<<P::Radio as Radio>::Error>>>

Drive the shared MAC until one wake cycle completes and invoke on_event for emitted events.

Source

pub async fn run( &self, on_event: impl FnMut(LocalIdentityId, MacEventRef<'_>), ) -> Result<(), MacHandleError<MacError<<P::Radio as Radio>::Error>>>

Drive the shared MAC forever, invoking on_event for delivered events.

This is the preferred long-lived driver API for standalone MAC-backed tasks. It keeps the wait policy inside the coordinator instead of requiring callers to hand-roll poll_cycle loops with arbitrary sleeps.

Source

pub async fn run_quiet( &self, ) -> Result<(), MacHandleError<MacError<<P::Radio as Radio>::Error>>>

Drive the shared MAC forever while ignoring emitted events.

Source

pub fn fill_random( &self, dest: &mut [u8], ) -> Result<(), MacHandleError<Infallible>>

Fills a caller-provided buffer with random bytes from the shared coordinator RNG.

Source

pub fn now_ms(&self) -> Result<u64, MacHandleError<Infallible>>

Returns the current coordinator clock time in milliseconds.

Source

pub fn register_ephemeral( &self, parent: LocalIdentityId, identity: SoftwareIdentity, ) -> Result<LocalIdentityId, MacHandleError<CapacityError>>

Registers an ephemeral software identity with the shared coordinator.

This is primarily used by the node layer when a PFS session becomes active.

Source

pub fn remove_ephemeral( &self, id: LocalIdentityId, ) -> Result<bool, MacHandleError<Infallible>>

Removes a previously registered ephemeral identity.

Source

pub fn cancel_pending_ack( &self, identity_id: LocalIdentityId, receipt: SendReceipt, ) -> bool

Cancel a pending ACK-requested send, stopping retransmissions.

Returns true if the pending ACK was found and removed. Returns false if the send was not found or the coordinator was busy.

Trait Implementations§

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> Clone for MacHandle<'a, P, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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> Copy for MacHandle<'a, P, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP>

Auto Trait Implementations§

§

impl<'a, P, const IDENTITIES: usize, const PEERS: usize, const CHANNELS: usize, const ACKS: usize, const TX: usize, const FRAME: usize, const DUP: usize> Freeze for MacHandle<'a, P, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP>

§

impl<'a, P, const IDENTITIES: usize = DEFAULT_IDENTITIES, const PEERS: usize = DEFAULT_PEERS, const CHANNELS: usize = DEFAULT_CHANNELS, const ACKS: usize = DEFAULT_ACKS, const TX: usize = DEFAULT_TX, const FRAME: usize = DEFAULT_FRAME, const DUP: usize = DEFAULT_DUP> !RefUnwindSafe for MacHandle<'a, P, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP>

§

impl<'a, P, const IDENTITIES: usize = DEFAULT_IDENTITIES, const PEERS: usize = DEFAULT_PEERS, const CHANNELS: usize = DEFAULT_CHANNELS, const ACKS: usize = DEFAULT_ACKS, const TX: usize = DEFAULT_TX, const FRAME: usize = DEFAULT_FRAME, const DUP: usize = DEFAULT_DUP> !Send for MacHandle<'a, P, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP>

§

impl<'a, P, const IDENTITIES: usize = DEFAULT_IDENTITIES, const PEERS: usize = DEFAULT_PEERS, const CHANNELS: usize = DEFAULT_CHANNELS, const ACKS: usize = DEFAULT_ACKS, const TX: usize = DEFAULT_TX, const FRAME: usize = DEFAULT_FRAME, const DUP: usize = DEFAULT_DUP> !Sync for MacHandle<'a, P, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP>

§

impl<'a, P, const IDENTITIES: usize, const PEERS: usize, const CHANNELS: usize, const ACKS: usize, const TX: usize, const FRAME: usize, const DUP: usize> Unpin for MacHandle<'a, P, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP>

§

impl<'a, P, const IDENTITIES: usize = DEFAULT_IDENTITIES, const PEERS: usize = DEFAULT_PEERS, const CHANNELS: usize = DEFAULT_CHANNELS, const ACKS: usize = DEFAULT_ACKS, const TX: usize = DEFAULT_TX, const FRAME: usize = DEFAULT_FRAME, const DUP: usize = DEFAULT_DUP> !UnwindSafe for MacHandle<'a, P, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

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> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.