EmergencyEvent

Struct EmergencyEvent 

Source
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

Source

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 emergency
  • timestamp - When the emergency was triggered
  • known_peers - List of peer node IDs to track for ACKs

The source node is automatically marked as acknowledged.

Source

pub fn source_node(&self) -> u32

Get the source node that triggered the emergency

Source

pub fn timestamp(&self) -> u64

Get the timestamp when the emergency was triggered

Source

pub fn has_acked(&self, node_id: u32) -> bool

Check if a specific node has acknowledged

Source

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)

Source

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.

Source

pub fn acked_nodes(&self) -> Vec<u32>

Get list of nodes that have acknowledged

Source

pub fn pending_nodes(&self) -> Vec<u32>

Get list of nodes that have NOT acknowledged

Source

pub fn all_nodes(&self) -> Vec<u32>

Get all tracked node IDs (both acked and pending)

Source

pub fn all_acked(&self) -> bool

Check if all tracked nodes have acknowledged

Source

pub fn peer_count(&self) -> usize

Get the total number of tracked nodes

Source

pub fn ack_count(&self) -> usize

Get the number of nodes that have acknowledged

Source

pub fn merge(&mut self, other: &EmergencyEvent) -> bool

Merge with another emergency event (CRDT semantics)

§Returns

true if our state changed

§Semantics
  • Same event (source_node, timestamp): merge ACK maps with OR
  • Different event: take the one with higher timestamp
Source

pub fn encode(&self) -> Vec<u8>

Encode to bytes for transmission

Format: source_node(4) + timestamp(8) + num_acks(4) + acks[N](5 each)

Source

pub fn decode(data: &[u8]) -> Option<Self>

Decode from bytes with validation

§Security

Validates source_node, timestamp, and limits ACK entries to prevent DoS. Rejects garbage data that could indicate spoofing or corruption.

Trait Implementations§

Source§

impl Clone for EmergencyEvent

Source§

fn clone(&self) -> EmergencyEvent

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EmergencyEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EmergencyEvent

Source§

fn default() -> EmergencyEvent

Returns the “default value” for a type. Read more
Source§

impl PartialEq for EmergencyEvent

Source§

fn eq(&self, other: &EmergencyEvent) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for EmergencyEvent

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.