2026-04-26 11:25:46 -06:00
|
|
|
//! Smallest in-process `RemoteShellLeaf` endpoint example.
|
|
|
|
|
//!
|
|
|
|
|
//! This example hosts exactly one protocol endpoint with exactly one leaf, `RemoteShellLeaf`, and
|
|
|
|
|
//! performs a local introspection request against that leaf. It does not open any sockets or spawn
|
|
|
|
|
//! a shell process, so it is the easiest place to see how the endpoint and leaf metadata fit
|
|
|
|
|
//! together.
|
|
|
|
|
|
|
|
|
|
use std::error::Error;
|
|
|
|
|
|
2026-04-26 12:57:56 -06:00
|
|
|
use unshell::leaves::remote_shell;
|
2026-04-26 11:25:46 -06:00
|
|
|
use unshell::protocol::tree::{EndpointOutcome, LocalEvent, ProtocolEndpoint};
|
2026-04-26 12:08:34 -06:00
|
|
|
use unshell::protocol::{INTROSPECTION_PROCEDURE_ID, LeafIntrospection};
|
2026-04-26 11:25:46 -06:00
|
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
let mut endpoint = ProtocolEndpoint::new(
|
2026-04-26 12:57:56 -06:00
|
|
|
agent_path(),
|
2026-04-26 11:25:46 -06:00
|
|
|
Some(Vec::new()),
|
|
|
|
|
Vec::new(),
|
|
|
|
|
vec![unshell::protocol::tree::LeafSpec {
|
2026-04-26 12:57:56 -06:00
|
|
|
name: remote_shell::endpoint::RemoteShellEndpoint::protocol_leaf_name(),
|
|
|
|
|
procedures: vec![remote_shell::endpoint::ProcedureOpen::protocol_procedure_id()],
|
2026-04-26 11:25:46 -06:00
|
|
|
}],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let hook_id = endpoint.allocate_hook_id();
|
|
|
|
|
let outcome = endpoint.send_call(
|
2026-04-26 12:57:56 -06:00
|
|
|
agent_path(),
|
|
|
|
|
Some(remote_shell::endpoint::RemoteShellEndpoint::protocol_leaf_name()),
|
2026-04-26 11:25:46 -06:00
|
|
|
INTROSPECTION_PROCEDURE_ID,
|
|
|
|
|
Some(hook_id),
|
|
|
|
|
Vec::new(),
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
let EndpointOutcome::Local(LocalEvent::Data { message, .. }) = outcome else {
|
|
|
|
|
return Err("expected one local introspection response".into());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let payload = unshell::protocol::tree::decode_call_input::<LeafIntrospection>(&message.data)?;
|
2026-04-26 12:08:34 -06:00
|
|
|
println!(
|
|
|
|
|
"remote-shell examples normally listen on {}",
|
2026-04-26 12:57:56 -06:00
|
|
|
remote_shell::endpoint::LISTEN_ADDR
|
2026-04-26 12:08:34 -06:00
|
|
|
);
|
2026-04-26 12:57:56 -06:00
|
|
|
println!("endpoint path: {:?}", agent_path());
|
2026-04-26 11:25:46 -06:00
|
|
|
println!("leaf: {}", payload.leaf_name);
|
|
|
|
|
println!("procedures: {:?}", payload.procedures);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2026-04-26 12:57:56 -06:00
|
|
|
|
|
|
|
|
fn agent_path() -> Vec<String> {
|
|
|
|
|
vec![String::from("agent")]
|
|
|
|
|
}
|