pub struct MacCounters {
pub tx_frames: u32,
pub tx_abandoned: u32,
pub rx_frames: u32,
pub rx_accepted: u32,
pub forwarded: u32,
pub forward_cancelled: u32,
}Expand description
Central MAC coordinator that owns and drives the full UMSH radio-facing state machine.
Mac is the top-level entry point for UMSH protocol operation. It combines a radio driver,
cryptographic engine, clock, RNG, counter store, and all protocol state into a single
fully-typed, allocation-free structure. All const-generic capacity parameters are enforced
at compile time via heapless collections — there are no heap allocations inside Mac.
§Generic parameters
P: Platform— a trait bundle supplying the concrete driver types forRadio,Aes/Sha(crypto),Clock,Rng, andCounterStore. ImplementPlatformonce per deployment target to swap in real hardware drivers, software stubs, or test doubles.IDENTITIES— maximum simultaneously active local identities (defaultDEFAULT_IDENTITIES).PEERS— maximum known remote peers and their per-identity pairwise key entries (defaultDEFAULT_PEERS).CHANNELS— maximum registered multicast channel keys (defaultDEFAULT_CHANNELS).ACKS— maximum simultaneously in-flight ACK-requested sends per identity (defaultDEFAULT_ACKS).TX— depth of the transmit queue (defaultDEFAULT_TX). Must be large enough to absorb a burst of control frames (MAC ACKs + forwarded frames) alongside any backlogged application sends.FRAME— maximum byte length of a stored frame buffer for retransmission (default [MAX_RESEND_FRAME_LEN]).DUP— capacity of the duplicate-detection cache (defaultDEFAULT_DUP).
§Lifecycle
- Construct with
Mac::new, supplying concrete driver instances and policy. - Register identities via
Mac::add_identity; callMac::load_persisted_counteron each long-term identity to restore the safe frame-counter start point from non-volatile storage. - Register peers via
Mac::add_peer. Secure unicast and blind-unicast state is derived lazily from the local private key and peer public key on first use. - Register channels via
Mac::add_channelorMac::add_named_channel. - Drive the event loop via
Mac::run/Mac::run_quietfor long-lived tasks, or by awaitingMac::next_eventwhen you need to multiplex MAC progress with other async work. The coordinator handles incoming frames, outgoing transmits, forwarding, ACK matching, retransmission scheduling, and timer deadlines — no external polling required. - Send traffic by calling
queue_broadcast,queue_unicast,queue_multicast, etc. from application code between (or concurrent with) event-loop iterations. - Persist counters by calling
Mac::service_counter_persistencewhenevernext_eventsignals that pending persistence work is ready to flush.
§Example (pseudo-code)
let mut mac = Mac::<MyPlatform>::new(
radio, crypto, clock, rng, counter_store,
RepeaterConfig::default(), OperatingPolicy::default(),
);
let id = mac.add_identity(my_identity)?;
mac.load_persisted_counter(id).await?;
mac.run(|id, event| {
let _ = (id, event);
// handle deliveries / ACKs here and schedule persistence work as needed
}).await?;Cumulative frame tallies for the coordinator, since construction.
Diagnostic only: nothing in the protocol depends on them, and they are
deliberately not persisted. They exist so an operator can tell a
working node from a deaf one without a capture — a radio whose
rx_frames never moves is not hearing anybody.
Every field saturates rather than wraps. A counter that rolled over would make a long-running node look freshly booted; pinning at the maximum is at least monotone, which is the property a reader is actually using them for.
Fields§
§tx_frames: u32Frames the radio accepted for transmission, including forwards.
tx_abandoned: u32Frames given up on after MAX_CAD_ATTEMPTS busy channels.
rx_frames: u32Frames the radio handed up, whoever they were addressed to.
rx_accepted: u32Receptions that produced an event or a side effect. The shortfall
against Self::rx_frames is other people’s traffic, duplicates,
and undecodable noise.
forwarded: u32Receptions this node repeated onward.
forward_cancelled: u32Queued forwards dropped because the destination’s ack was overheard before they went out. Airtime this node did not have to spend.
Trait Implementations§
Source§impl Clone for MacCounters
impl Clone for MacCounters
Source§fn clone(&self) -> MacCounters
fn clone(&self) -> MacCounters
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MacCounters
impl Debug for MacCounters
Source§impl Default for MacCounters
impl Default for MacCounters
Source§fn default() -> MacCounters
fn default() -> MacCounters
Source§impl PartialEq for MacCounters
impl PartialEq for MacCounters
impl Copy for MacCounters
impl Eq for MacCounters
impl StructuralPartialEq for MacCounters
Auto Trait Implementations§
impl Freeze for MacCounters
impl RefUnwindSafe for MacCounters
impl Send for MacCounters
impl Sync for MacCounters
impl Unpin for MacCounters
impl UnwindSafe for MacCounters
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)