CliSession

Struct CliSession 

Source
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,

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub async fn run<IN>( &mut self, input: &mut IN, ) -> Result<(), CliError<OUT::Error>>
where IN: CliInput<Error = 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.

Auto Trait Implementations§

§

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> Freeze for CliSession<M, OUT, LOG, PS, CS, PC, N_PEERS, N_ALIASES, N_CHANNELS, N_EVENTS, LINE_MAX>
where OUT: Freeze, LOG: Freeze, PS: Freeze, CS: Freeze, PC: Freeze, M: Freeze,

§

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> !RefUnwindSafe for CliSession<M, OUT, LOG, PS, CS, PC, N_PEERS, N_ALIASES, N_CHANNELS, N_EVENTS, LINE_MAX>

§

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> !Send for CliSession<M, OUT, LOG, PS, CS, PC, N_PEERS, N_ALIASES, N_CHANNELS, N_EVENTS, LINE_MAX>

§

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> !Sync for CliSession<M, OUT, LOG, PS, CS, PC, N_PEERS, N_ALIASES, N_CHANNELS, N_EVENTS, LINE_MAX>

§

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> Unpin for CliSession<M, OUT, LOG, PS, CS, PC, N_PEERS, N_ALIASES, N_CHANNELS, N_EVENTS, LINE_MAX>
where OUT: Unpin, LOG: Unpin, PS: Unpin, CS: Unpin, PC: Unpin, M: Unpin,

§

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> !UnwindSafe for CliSession<M, OUT, LOG, PS, CS, PC, N_PEERS, N_ALIASES, N_CHANNELS, N_EVENTS, LINE_MAX>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.