pub struct EmergencyEvent { /* private fields */ }Expand description
An emergency event with acknowledgment tracking (CRDT)
Represents a single emergency incident with distributed ACK tracking. Each node in the mesh can acknowledge the emergency, and this state is replicated across all nodes using CRDT semantics.
§CRDT Semantics
- Identity: Events are uniquely identified by (source_node, timestamp)
- Merge for same event: ACK maps merge with OR (once acked, stays acked)
- Merge for different events: Higher timestamp wins (newer emergency replaces older)
- Monotonic: ACK state only moves from false → true, never back
§Wire Format
source_node: 4 bytes (LE)
timestamp: 8 bytes (LE)
num_acks: 4 bytes (LE)
acks[N]:
node_id: 4 bytes (LE)
acked: 1 byte (0 or 1)Implementations§
Source§impl EmergencyEvent
impl EmergencyEvent
Sourcepub fn new(source_node: u32, timestamp: u64, known_peers: &[u32]) -> Self
pub fn new(source_node: u32, timestamp: u64, known_peers: &[u32]) -> Self
Create a new emergency event
§Arguments
source_node- Node ID that triggered the emergencytimestamp- When the emergency was triggeredknown_peers- List of peer node IDs to track for ACKs
The source node is automatically marked as acknowledged.
Sourcepub fn source_node(&self) -> u32
pub fn source_node(&self) -> u32
Get the source node that triggered the emergency
Sourcepub fn ack(&mut self, node_id: u32) -> bool
pub fn ack(&mut self, node_id: u32) -> bool
Record an acknowledgment from a node
Returns true if this was a new ACK (state changed)
Sourcepub fn add_peer(&mut self, node_id: u32)
pub fn add_peer(&mut self, node_id: u32)
Add a peer to track (if not already present)
New peers start as not-acked. This is useful when discovering new peers after the emergency was created.
Sourcepub fn acked_nodes(&self) -> Vec<u32>
pub fn acked_nodes(&self) -> Vec<u32>
Get list of nodes that have acknowledged
Sourcepub fn pending_nodes(&self) -> Vec<u32>
pub fn pending_nodes(&self) -> Vec<u32>
Get list of nodes that have NOT acknowledged
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Get the total number of tracked nodes
Sourcepub fn merge(&mut self, other: &EmergencyEvent) -> bool
pub fn merge(&mut self, other: &EmergencyEvent) -> bool
Trait Implementations§
Source§impl Clone for EmergencyEvent
impl Clone for EmergencyEvent
Source§fn clone(&self) -> EmergencyEvent
fn clone(&self) -> EmergencyEvent
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for EmergencyEvent
impl Debug for EmergencyEvent
Source§impl Default for EmergencyEvent
impl Default for EmergencyEvent
Source§fn default() -> EmergencyEvent
fn default() -> EmergencyEvent
Returns the “default value” for a type. Read more
Source§impl PartialEq for EmergencyEvent
impl PartialEq for EmergencyEvent
impl StructuralPartialEq for EmergencyEvent
Auto Trait Implementations§
impl Freeze for EmergencyEvent
impl RefUnwindSafe for EmergencyEvent
impl Send for EmergencyEvent
impl Sync for EmergencyEvent
impl Unpin for EmergencyEvent
impl UnwindSafe for EmergencyEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more