Fix examples for renamed leaf endpoint surface

Update the remote shell examples to use unshell::leaves and the leaf_endpoint feature-gated endpoint module, and restore the local macro aliasing needed after removing the direct unshell dependency from unshell-leaves.
This commit is contained in:
Michael Mikovsky
2026-04-26 12:57:56 -06:00
parent d4100d0604
commit 4f8835bd25
10 changed files with 87 additions and 110 deletions
+10 -7
View File
@@ -9,29 +9,32 @@ use std::net::TcpStream;
use std::sync::mpsc::RecvTimeoutError;
use std::time::Duration;
use unshell::leaves::remote_shell;
use unshell::protocol::tree::Ingress;
use unshell_leaves::remote_shell;
fn main() -> Result<(), Box<dyn Error>> {
let mut stream = TcpStream::connect(remote_shell::LISTEN_ADDR)?;
let frame_rx = remote_shell::spawn_frame_reader(stream.try_clone()?);
let mut runtime = remote_shell::build_agent_runtime();
let mut stream = TcpStream::connect(remote_shell::endpoint::LISTEN_ADDR)?;
let frame_rx = remote_shell::endpoint::spawn_frame_reader(stream.try_clone()?);
let mut runtime = remote_shell::endpoint::build_agent_runtime();
println!("connected to controller at {}", remote_shell::LISTEN_ADDR);
println!(
"connected to controller at {}",
remote_shell::endpoint::LISTEN_ADDR
);
loop {
match frame_rx.recv_timeout(Duration::from_millis(25)) {
Ok(result) => {
let frame = result?;
let outcome = runtime.receive(&Ingress::Parent, frame)?;
remote_shell::write_frames(&mut stream, &outcome.frames)?;
remote_shell::endpoint::write_frames(&mut stream, &outcome.frames)?;
}
Err(RecvTimeoutError::Timeout) => {}
Err(RecvTimeoutError::Disconnected) => break,
}
let outcome = runtime.poll()?;
remote_shell::write_frames(&mut stream, &outcome.frames)?;
remote_shell::endpoint::write_frames(&mut stream, &outcome.frames)?;
}
Ok(())
+19 -13
View File
@@ -6,38 +6,40 @@
use std::error::Error;
use std::net::TcpListener;
use unshell::leaves::remote_shell;
use unshell::leaves::remote_shell::OpenRequest;
use unshell::protocol::tree::encode_call_reply;
use unshell::protocol::tree::{Endpoint, EndpointOutcome, Ingress, LocalEvent};
use unshell_leaves::remote_shell;
fn main() -> Result<(), Box<dyn Error>> {
let listener = TcpListener::bind(remote_shell::LISTEN_ADDR)?;
println!("listening on {}", remote_shell::LISTEN_ADDR);
let listener = TcpListener::bind(remote_shell::endpoint::LISTEN_ADDR)?;
println!("listening on {}", remote_shell::endpoint::LISTEN_ADDR);
let (mut stream, peer_addr) = listener.accept()?;
println!("accepted endpoint connection from {peer_addr}");
let frame_rx = remote_shell::spawn_frame_reader(stream.try_clone()?);
let mut endpoint = remote_shell::build_controller_endpoint();
let frame_rx = remote_shell::endpoint::spawn_frame_reader(stream.try_clone()?);
let mut endpoint = remote_shell::endpoint::build_controller_endpoint();
let hook_id = endpoint.allocate_hook_id();
let shell_leaf_name = remote_shell::shell_leaf_name();
let open_procedure = remote_shell::shell_open_procedure();
let shell_leaf_name = remote_shell::endpoint::RemoteShellEndpoint::protocol_leaf_name();
let open_procedure = remote_shell::endpoint::ProcedureOpen::protocol_procedure_id();
remote_shell::send_forward(
remote_shell::endpoint::send_forward(
&mut stream,
endpoint.send_call(
remote_shell::agent_path(),
agent_path(),
Some(shell_leaf_name),
open_procedure.clone(),
Some(hook_id),
remote_shell::shell_open_payload(),
encode_call_reply(&OpenRequest).expect("remote shell open payload should encode"),
)?,
)?;
for (index, command) in ["pwd\n", "whoami\n", "exit\n"].iter().enumerate() {
remote_shell::send_forward(
remote_shell::endpoint::send_forward(
&mut stream,
endpoint.send_data(
remote_shell::agent_path(),
agent_path(),
hook_id,
open_procedure.clone(),
command.as_bytes().to_vec(),
@@ -48,7 +50,7 @@ fn main() -> Result<(), Box<dyn Error>> {
for result in frame_rx {
let frame = result?;
let outcome = endpoint.receive(&Ingress::Child(remote_shell::agent_path()), frame)?;
let outcome = endpoint.receive(&Ingress::Child(agent_path()), frame)?;
let EndpointOutcome::Local(event) = outcome else {
continue;
};
@@ -71,3 +73,7 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(())
}
fn agent_path() -> Vec<String> {
vec![String::from("agent")]
}
@@ -7,25 +7,25 @@
use std::error::Error;
use unshell::leaves::remote_shell;
use unshell::protocol::tree::{EndpointOutcome, LocalEvent, ProtocolEndpoint};
use unshell::protocol::{INTROSPECTION_PROCEDURE_ID, LeafIntrospection};
use unshell_leaves::remote_shell;
fn main() -> Result<(), Box<dyn Error>> {
let mut endpoint = ProtocolEndpoint::new(
remote_shell::agent_path(),
agent_path(),
Some(Vec::new()),
Vec::new(),
vec![unshell::protocol::tree::LeafSpec {
name: remote_shell::shell_leaf_name(),
procedures: vec![remote_shell::shell_open_procedure()],
name: remote_shell::endpoint::RemoteShellEndpoint::protocol_leaf_name(),
procedures: vec![remote_shell::endpoint::ProcedureOpen::protocol_procedure_id()],
}],
);
let hook_id = endpoint.allocate_hook_id();
let outcome = endpoint.send_call(
remote_shell::agent_path(),
Some(remote_shell::shell_leaf_name()),
agent_path(),
Some(remote_shell::endpoint::RemoteShellEndpoint::protocol_leaf_name()),
INTROSPECTION_PROCEDURE_ID,
Some(hook_id),
Vec::new(),
@@ -38,10 +38,14 @@ fn main() -> Result<(), Box<dyn Error>> {
let payload = unshell::protocol::tree::decode_call_input::<LeafIntrospection>(&message.data)?;
println!(
"remote-shell examples normally listen on {}",
remote_shell::LISTEN_ADDR
remote_shell::endpoint::LISTEN_ADDR
);
println!("endpoint path: {:?}", remote_shell::agent_path());
println!("endpoint path: {:?}", agent_path());
println!("leaf: {}", payload.leaf_name);
println!("procedures: {:?}", payload.procedures);
Ok(())
}
fn agent_path() -> Vec<String> {
vec![String::from("agent")]
}