pub struct MachineClient { /* private fields */ }Expand description
The sessions on one machine, and the in-process bus they use when the peer is one of them.
Implementations§
Source§impl MachineClient
impl MachineClient
Sourcepub fn open(
homeserver_url: &str,
store_root: &Path,
sessions: Vec<HostSession>,
) -> Result<Self, ShellError>
pub fn open( homeserver_url: &str, store_root: &Path, sessions: Vec<HostSession>, ) -> Result<Self, ShellError>
Registers sessions and opens each sealed store under store_root.
The host built sessions. This does not look for bot processes.
The first drive publishes public keys to the homeserver and mirrors
them onto the in-process bus. A long-poll left by that drive is
dropped so it is not a second sync loop.
Sourcepub fn open_session_dir(
homeserver_url: &str,
store_root: &Path,
sessions_dir: &Path,
) -> Result<Self, ShellError>
pub fn open_session_dir( homeserver_url: &str, store_root: &Path, sessions_dir: &Path, ) -> Result<Self, ShellError>
load_session_records then Self::open. Records have no bearer
and no routine URL; those stay unset.
Sourcepub fn from_env() -> Result<Self, ShellError>
pub fn from_env() -> Result<Self, ShellError>
Web machine client open path.
HOMESERVER_URL_ENV, STORE_ROOT_ENV. Discovery prefers the
agents directory (AGENTS_DIR_ENV or DEFAULT_AGENTS_DIR) when
that folder exists; otherwise SESSIONS_DIR_ENV. One webhook
routine per agent, from the gateway file ([GATEWAY_FILE_ENV], or
the host gateway file when that is unset). The token is the file’s
token, or [GATEWAY_TOKEN_ENV] when the host injected one. A missing
file leaves routines unset and does not fail this open. URLs and
keys are not read from disk and are not written back.
crate::LEADER_SOCK_ENV is not read.
Sourcepub fn from_env_for(nick: &str) -> Result<Self, ShellError>
pub fn from_env_for(nick: &str) -> Result<Self, ShellError>
Self::from_env with only the session whose nick is nick: the
path m4a-send takes when no client is running. Does not listen
for sends.
Sourcepub fn poll_agent_directory(&mut self) -> Result<Vec<RoutineReport>, ShellError>
pub fn poll_agent_directory(&mut self) -> Result<Vec<RoutineReport>, ShellError>
Rescans the agents directory when this client was opened from one.
For every bot not skipped and not ready yet: ensures the local
mirror and asks for the credential again. A bot that just created
its own routine turns ready here; when that bot has an open session,
its wake is set in place and saved to the keychain file. A bot that
appeared after open gets its mirror now; its sealed store opens with
the next process. When AGENT_RESCAN_SECS_ENV is set and greater
than zero, returns without scanning until that many seconds have
passed since the last poll. Reports carry no URL and no key.
Sourcepub fn pending_wake_agents(&self) -> Vec<String>
pub fn pending_wake_agents(&self) -> Vec<String>
Agent ids of open sessions that still have no wake.
Sourcepub fn set_local_delivery(&self, enabled: bool)
pub fn set_local_delivery(&self, enabled: bool)
While enabled, drive does not call the homeserver. Requests are
answered by the in-process bus. Turn this on for an exchange whose
peer is a session Self::open holds, and off again before reaching
a session that exists only on the homeserver.
A public channel is not given a separate transport: with this off, create and send use the homeserver, which is what a public channel and a group with a remote member already do. An encrypted direct room between two local sessions uses the bus while this is on, and the room stays encrypted.
Sourcepub fn homeserver_hits(&self) -> u64
pub fn homeserver_hits(&self) -> u64
Homeserver calls counted across every session since Self::open.
In-process bus calls are not included. Registration before the first
drive is not included either.
Sourcepub fn session_mut(
&mut self,
name_or_nick: &str,
) -> Result<&mut OpenedStore, ShellError>
pub fn session_mut( &mut self, name_or_nick: &str, ) -> Result<&mut OpenedStore, ShellError>
The open session whose nick matches name_or_nick.
Sourcepub fn store_dir(&self, name_or_nick: &str) -> Result<PathBuf, ShellError>
pub fn store_dir(&self, name_or_nick: &str) -> Result<PathBuf, ShellError>
Sealed directory for that nick.
Sourcepub fn deliver_pushed(&mut self) -> usize
pub fn deliver_pushed(&mut self) -> usize
Hands pushed room text to the session named by recipient.
Another session on this client does not receive it. This does not
start /sync and it does not post a routine.
Sourcepub fn tick(&mut self, now_ms: i64, full_drive_secs: u64) -> TickReport
pub fn tick(&mut self, now_ms: i64, full_drive_secs: u64) -> TickReport
One step of the long-running client loop.
Drains the push socket and hands each pushed event to its session,
then drives exactly those sessions (waiting for the /sync the push
announced), which decrypts the text and POSTs the wake to that
session’s own routine. Every full_drive_secs it also drives every
session once, which is how DM invites get joined
(OpenedStore::accept_direct_invites) and how a missed push is
caught up. Errors are returned per session, without secrets.
Sourcepub fn listen_for_sends(&mut self, path: &Path) -> Result<(), ShellError>
pub fn listen_for_sends(&mut self, path: &Path) -> Result<(), ShellError>
Listens on path for m4a-send requests (one JSON line each, see
crate::SendRequest). A stale socket file is replaced; a live
listener is refused. Unix is mode 0600. Windows is loopback TCP and
the file holds 127.0.0.1:{port}. The file is removed when the
client drops. Self::tick answers requests: the as session
opens (or reuses) the encrypted DM with to, waits up to two
minutes for to to join, and sends.
Sourcepub fn listen_for_sends_from_env(&mut self) -> Result<PathBuf, ShellError>
pub fn listen_for_sends_from_env(&mut self) -> Result<PathBuf, ShellError>
Self::listen_for_sends on crate::SEND_SOCK_ENV, or
crate::DEFAULT_SOCK_NAME under the store root. Returns the path.
Sourcepub fn send_blocking(
&mut self,
as_nick: &str,
to: &str,
text: &str,
wait: Duration,
) -> SendReply
pub fn send_blocking( &mut self, as_nick: &str, to: &str, text: &str, wait: Duration, ) -> SendReply
Sends text from session as_nick to to in their encrypted DM,
driving until to has joined (up to wait). The direct path of
m4a-send when no client is running.
Sourcepub fn wake_log(&self) -> Vec<(String, WakeAttempt)>
pub fn wake_log(&self) -> Vec<(String, WakeAttempt)>
Every routine POST attempted by every session, as (nick, attempt). Event ids and HTTP statuses only.