umsh_cli/
events.rs

1//! Event queue variants pushed by subscription callbacks and consumed by
2//! `CliSession::service_events`.
3//!
4//! All variants store bounded data; `OwnedMacCommand` (which contains an
5//! unbounded `Vec<u8>`) is never used as a blanket carrier — only the MAC
6//! commands the CLI actually cares about get dedicated variants.
7
8use heapless::{String, Vec};
9use umsh_core::{NodeHint, PublicKey};
10
11/// Maximum payload length recorded in inbound events (per-event cap).
12pub const EVENT_PAYLOAD_MAX: usize = 64;
13/// Maximum length of a formatted output line buffered for writing.
14pub const EVENT_LINE_MAX: usize = 256;
15/// Maximum raw on-wire frame bytes recorded per RawTx/RawRx event.
16pub const EVENT_RAW_MAX: usize = 256;
17
18#[derive(Debug)]
19pub enum CliEvent {
20    // ─── Inbound (deposited by 'static subscription closures) ───────────────
21    Received {
22        from: PublicKey,
23        hops: u8,
24        rssi: i16,
25        snr: i16,
26        prefix: Vec<u8, EVENT_PAYLOAD_MAX>,
27    },
28    AckReceived {
29        peer: PublicKey,
30    },
31    AckTimeout {
32        peer: PublicKey,
33    },
34    NodeDiscovered {
35        from: PublicKey,
36        name: Option<String<32>>,
37    },
38    Beacon {
39        /// 3-byte source hint from the packet header — always present.
40        hint: NodeHint,
41        /// Full source pubkey, when the beacon carried it (some senders only
42        /// include the hint to save airtime).
43        from: Option<PublicKey>,
44    },
45    PfsEstablished {
46        peer: PublicKey,
47    },
48    PfsEnded {
49        peer: PublicKey,
50    },
51    PfsFailed {
52        peer: PublicKey,
53        reason: umsh_node::PfsFailure,
54    },
55    Pong {
56        peer: PublicKey,
57        rtt_ms: u64,
58    },
59    PingTimeout {
60        peer: PublicKey,
61    },
62    UnknownMacCmdIn {
63        peer: PublicKey,
64        cmd_id: u8,
65    },
66    RawTx {
67        bytes: Vec<u8, EVENT_RAW_MAX>,
68    },
69    RawRx {
70        bytes: Vec<u8, EVENT_RAW_MAX>,
71    },
72
73    // ─── Outbound ────────────────────────────────────────────────────────────
74    // TODO: these variants were designed for a model where `execute()` pushes
75    // outbound work onto the event queue and `service_events()` drains it.
76    // The current implementation calls MAC I/O directly from `execute()` and
77    // none of these variants are ever pushed. Either wire them up (enables
78    // rate-limiting and cancel hooks) or remove them and the dead arms in
79    // `handle_event` to clean up the mismatch.
80    OutputLine {
81        line: String<EVENT_LINE_MAX>,
82    },
83    SendText {
84        peer: PublicKey,
85        body: String<EVENT_LINE_MAX>,
86    },
87    StartPfs {
88        peer: PublicKey,
89        minutes: u16,
90    },
91    EndPfs {
92        peer: PublicKey,
93    },
94    ChannelSend {
95        channel_slot: u8,
96        body: String<EVENT_LINE_MAX>,
97    },
98    SendBeacon,
99    SendRaw {
100        peer: PublicKey,
101        bytes: Vec<u8, EVENT_PAYLOAD_MAX>,
102    },
103}