pub struct CliSession<M, OUT, LOG, PS, CS, PC, const N_PEERS: usize, const N_ALIASES: usize, const N_CHANNELS: usize, const N_EVENTS: usize, const LINE_MAX: usize>where
M: MacBackend,
M::SendError: Debug,
M::CapacityError: Debug,
OUT: CliOutput,
LOG: CliLogger,
PS: PeerStore,
CS: ChannelStore,
PC: PowerControl,{ /* private fields */ }Expand description
The CLI driver. Owns the output half of the CLI transport; the input half
is passed to CliSession::run so the driver can hold a long-lived read
future across wake events without blocking writes to out.
Implementations§
Source§impl<M, OUT, LOG, PS, CS, PC, const N_PEERS: usize, const N_ALIASES: usize, const N_CHANNELS: usize, const N_EVENTS: usize, const LINE_MAX: usize> CliSession<M, OUT, LOG, PS, CS, PC, N_PEERS, N_ALIASES, N_CHANNELS, N_EVENTS, LINE_MAX>where
M: MacBackend,
M::SendError: Debug,
M::CapacityError: Debug,
OUT: CliOutput,
LOG: CliLogger,
PS: PeerStore,
CS: ChannelStore,
PC: PowerControl,
impl<M, OUT, LOG, PS, CS, PC, const N_PEERS: usize, const N_ALIASES: usize, const N_CHANNELS: usize, const N_EVENTS: usize, const LINE_MAX: usize> CliSession<M, OUT, LOG, PS, CS, PC, N_PEERS, N_ALIASES, N_CHANNELS, N_EVENTS, LINE_MAX>where
M: MacBackend,
M::SendError: Debug,
M::CapacityError: Debug,
OUT: CliOutput,
LOG: CliLogger,
PS: PeerStore,
CS: ChannelStore,
PC: PowerControl,
Sourcepub fn new(
node: LocalNode<M>,
local_key: PublicKey,
out: OUT,
logger: LOG,
peer_store: PS,
channel_store: CS,
power: PC,
) -> Self
pub fn new( node: LocalNode<M>, local_key: PublicKey, out: OUT, logger: LOG, peer_store: PS, channel_store: CS, power: PC, ) -> Self
Construct a new session around a cloned LocalNode<M>. local_key
is passed in because the caller already has it; no node-crate accessor
for the local key is added. The session owns the out half of the
CLI transport; the input half is supplied to Self::run.
peer_store and channel_store are called on join/leave and add/rm
to persist changes. Pass umsh_hal::NoPeerStore /
umsh_hal::NoChannelStore when persistence is not needed.
power is invoked by /poweroff; pass umsh_hal::NoPowerControl
on targets without a power-off path.
Sourcepub fn resolve_peer(&self, token: &str) -> Option<PublicKey>
pub fn resolve_peer(&self, token: &str) -> Option<PublicKey>
Resolve a <peer-ref> token to a PublicKey. Alias table first,
then encoded forms (hex / base58 / base64).
Sourcepub async fn register_peer(
&mut self,
key: PublicKey,
alias: Option<&str>,
) -> bool
pub async fn register_peer( &mut self, key: PublicKey, alias: Option<&str>, ) -> bool
Pre-register a peer at startup (e.g. from --peer CLI args).
Returns false if either the peer or alias table is full, or if the
MAC rejects the key (full peer table at the MAC layer).
Also registers the peer in the MAC-layer peer table via node.peer
so inbound frames from this peer can be validated before the user
initiates any outbound traffic.
Sourcepub async fn register_channel(
&mut self,
name: &str,
key_bytes: [u8; 32],
) -> bool
pub async fn register_channel( &mut self, name: &str, key_bytes: [u8; 32], ) -> bool
Pre-register a channel at startup (e.g. from persisted storage).
Joins the channel at the MAC layer and inserts it into the session
channel table. Returns false if the channel or MAC table is full, or
if the key is invalid. Does NOT call channel_store — use this only
when restoring data that is already durable.
Sourcepub async fn load_from_stores(&mut self)
pub async fn load_from_stores(&mut self)
Populate the in-session peer and channel tables from persistent storage.
Loads every peer and channel record from the backing stores and registers
them with both the MAC layer (idempotent) and the CLI display tables.
Call this once before run, or rely on run calling it
automatically at startup.
Sourcepub async fn run<IN>(
&mut self,
input: &mut IN,
) -> Result<(), CliError<OUT::Error>>
pub async fn run<IN>( &mut self, input: &mut IN, ) -> Result<(), CliError<OUT::Error>>
Drive the CLI until /quit or EOF.
Each outer iteration arms one long-lived read_line future and races
it against wake in an inner loop. The read future is only dropped
when it completes — wake-driven iterations preserve it across
select! rearms, so implementations of CliInput do not need to
be cancel-safe.
input is borrowed for the duration of each read; it’s a separate
parameter from self so the driver can continue writing to self.out
while a read is outstanding.