sb-mesh 0.1.1

S&B Sovereign Mesh (sb-mesh) — User-Space P2P Overlay Network, WireGuard-compatible Crypto & TUI
Documentation
use clap::{Parser, Subcommand};

#[derive(Parser, Debug)]
#[command(
    name = "sb-mesh",
    about = "S&B Sovereign Mesh — User-Space P2P Overlay Network & Terminal TUI",
    version = "0.1.0"
)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Option<Commands>,
}

#[derive(Subcommand, Debug)]
pub enum Commands {
    /// Launch the interactive Ratatui terminal dashboard (Default)
    Tui,

    /// Run headless mesh node daemon
    Daemon {
        #[arg(short, long)]
        port: Option<u16>,
    },

    /// Display current node status, public keys, and peer count
    Status,

    /// Manage mesh peers
    Peer {
        #[command(subcommand)]
        sub: PeerCommands,
    },

    /// Generate or consume direct device pairing tokens (sbm-pair://)
    Pair {
        #[command(subcommand)]
        sub: PairCommands,
    },

    /// Send an authenticated cryptographic ping to a peer
    Ping {
        /// Callsign, Node ID or Public Key of the peer
        target: String,
    },

    /// Toggle or inspect Air-Gap killswitch status
    Airgap {
        /// Action: 'on', 'off', or 'toggle'
        #[arg(default_value = "toggle")]
        action: String,
    },

    /// Run user-space SOCKS5 proxy (127.0.0.1:1080)
    Proxy {
        /// Local port for SOCKS5 proxy listener
        #[arg(short, long, default_value_t = 1080)]
        port: u16,
    },

    /// Establish a P2P port-forwarding tunnel to a peer
    Tunnel {
        /// Local listening port (e.g. 8080)
        #[arg(short, long)]
        local: u16,
        /// Remote destination address (e.g. 10.240.0.2:80 or target_ip:port)
        #[arg(short, long)]
        remote: String,
    },

    /// Display multi-hop routing table, subnet routes, and exit node status
    Routes,

    /// Revoke a compromised public key via P2P Gossip CRL
    Revoke {
        /// WireGuard Base64 public key to revoke
        pubkey: String,
        /// Reason for revocation
        #[arg(short, long, default_value = "Device compromised or decommissioned")]
        reason: String,
    },

    /// Share a local development port over the P2P Sovereign Mesh (Ngrok alternative)
    Share {
        /// Local port to share (e.g. 3000, 8080)
        port: u16,
        /// Optional service label or custom subdomain name
        #[arg(short, long)]
        label: Option<String>,
        /// Local service bind host (default: 127.0.0.1)
        #[arg(long, default_value = "127.0.0.1")]
        host: String,
        /// Ingress port on mesh interface (default: same as local port)
        #[arg(short, long)]
        ingress_port: Option<u16>,
        /// Optional access token / passphrase requirement for connecting peers
        #[arg(short, long)]
        token: Option<String>,
    },
}

#[derive(Subcommand, Debug)]
pub enum PeerCommands {
    /// Add a new peer manually
    Add {
        /// Callsign / Friendly name for the peer
        callsign: String,
        /// WireGuard-compatible Base64 public key (32 bytes)
        public_key: String,
        /// Peer socket endpoint IP:Port (e.g. 192.168.1.50:58888)
        #[arg(short, long)]
        endpoint: Option<String>,
        /// Optional internal overlay IP (e.g. 10.240.0.2)
        #[arg(short, long)]
        overlay_ip: Option<String>,
    },
    /// List all configured peers
    List,
    /// Remove a peer by public key or callsign
    Remove {
        target: String,
    },
}

#[derive(Subcommand, Debug)]
pub enum PairCommands {
    /// Generate a pairing token to invite another device
    Generate {
        /// Your public or LAN IP:Port endpoint (e.g. 192.168.1.100:58888)
        endpoint: String,
        /// Display high-density terminal QR code for scanning
        #[arg(long, default_value_t = false)]
        qr: bool,
        /// Time-to-Live (TTL) in seconds (default: 300s = 5 min, 0 = unlimited)
        #[arg(long, default_value_t = 300)]
        ttl: u64,
    },
    /// Connect to a device using a pairing token (sbm-pair://...)
    Connect {
        /// Friendly callsign for this new device
        callsign: String,
        /// The pairing token
        token: String,
    },
}