Expand description
§NOMAD Protocol
Network-Optimized Mobile Application Datagram
NOMAD is a secure, UDP-based state synchronization protocol designed for real-time applications over unreliable networks. It provides:
- Security: End-to-end authenticated encryption with forward secrecy
- Mobility: Seamless operation across IP address changes (roaming)
- Latency: Sub-100ms reconnection, optional client-side prediction
- Simplicity: Fixed cryptographic suite, no negotiation
- Generality: State-agnostic synchronization framework
§Feature Flags
transport(default): Transport layer (frames, RTT, pacing, sockets)crypto(default): Security layer (Noise_IK, XChaCha20-Poly1305)
§Modules
core: Core traits, constants, and error types (always included)transport: Transport layer (requirestransportfeature)crypto: Security layer (requirescryptofeature)
§Example Usage
use nomad_protocol::prelude::*;
// Define your state type
#[derive(Clone)]
struct MyState {
counter: u64,
}
#[derive(Clone)]
struct MyDiff {
delta: i64,
}
impl SyncState for MyState {
type Diff = MyDiff;
const STATE_TYPE_ID: &'static str = "example.counter.v1";
fn diff_from(&self, old: &Self) -> Self::Diff {
MyDiff {
delta: self.counter as i64 - old.counter as i64,
}
}
fn apply_diff(&mut self, diff: &Self::Diff) -> Result<(), ApplyError> {
self.counter = (self.counter as i64 + diff.delta) as u64;
Ok(())
}
fn encode_diff(diff: &Self::Diff) -> Vec<u8> {
diff.delta.to_le_bytes().to_vec()
}
fn decode_diff(data: &[u8]) -> Result<Self::Diff, DecodeError> {
if data.len() < 8 {
return Err(DecodeError::UnexpectedEof);
}
let delta = i64::from_le_bytes(data[..8].try_into().unwrap());
Ok(MyDiff { delta })
}
}Re-exports§
pub use core::ApplyError;pub use core::DecodeError;pub use core::NomadError;pub use core::SyncState;pub use transport::ConnectionPhase;transportpub use transport::ConnectionState;transportpub use transport::DataFrame;transportpub use transport::DataFrameHeader;transportpub use transport::FrameFlags;transportpub use transport::FramePacer;transportpub use transport::FrameType;transportpub use transport::NomadSocket;transportpub use transport::PayloadHeader;transportpub use transport::RttEstimator;transportpub use transport::SessionId;transport
Modules§
- client
client - NOMAD Protocol - Client Library
- core
- NOMAD Protocol - Core traits, types, and constants.
- crypto
crypto - NOMAD Protocol - Security Layer
- extensions
extensions - NOMAD Protocol - Extensions
- prelude
- Prelude module for convenient imports.
- server
server - NOMAD Protocol - Server Library
- sync
sync - NOMAD Protocol - Sync Layer
- transport
transport - NOMAD Protocol - Transport Layer