//! Mesh networking heartbeat and simple neighbor tracking. use rand::{distributions::Alphanumeric, Rng}; use serde::Serialize; use std::time::{Duration, SystemTime}; #[derive(Debug, Clone, Serialize)] pub struct Heartbeat { pub ts: u64, pub nonce: String, } pub fn heartbeat() -> Heartbeat { let ts = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap_or(Duration::from_secs(0)) .as_secs(); let nonce: String = rand::thread_rng() .sample_iter(&Alphanumeric) .take(8) .map(char::from) .collect(); Heartbeat { ts, nonce } }