Crate nomad_protocol

Crate nomad_protocol 

Source
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 (requires transport feature)
  • crypto: Security layer (requires crypto feature)

§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;transport
pub use transport::ConnectionState;transport
pub use transport::DataFrame;transport
pub use transport::DataFrameHeader;transport
pub use transport::FrameFlags;transport
pub use transport::FramePacer;transport
pub use transport::FrameType;transport
pub use transport::NomadSocket;transport
pub use transport::PayloadHeader;transport
pub use transport::RttEstimator;transport
pub use transport::SessionId;transport

Modules§

clientclient
NOMAD Protocol - Client Library
core
NOMAD Protocol - Core traits, types, and constants.
cryptocrypto
NOMAD Protocol - Security Layer
extensionsextensions
NOMAD Protocol - Extensions
prelude
Prelude module for convenient imports.
serverserver
NOMAD Protocol - Server Library
syncsync
NOMAD Protocol - Sync Layer
transporttransport
NOMAD Protocol - Transport Layer