2026-04-25 16:27:10 -06:00
|
|
|
#[path = "../../src/leaf/remote_shell/mod.rs"]
|
|
|
|
|
mod remote_shell;
|
2026-04-25 14:41:00 -06:00
|
|
|
|
|
|
|
|
use std::error::Error;
|
|
|
|
|
use std::net::TcpStream;
|
2026-04-25 15:35:08 -06:00
|
|
|
use std::sync::mpsc::RecvTimeoutError;
|
2026-04-25 14:41:00 -06:00
|
|
|
use std::time::Duration;
|
|
|
|
|
|
2026-04-25 15:35:08 -06:00
|
|
|
use unshell::protocol::tree::Ingress;
|
2026-04-25 14:41:00 -06:00
|
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
2026-04-25 16:27:10 -06:00
|
|
|
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();
|
2026-04-25 14:41:00 -06:00
|
|
|
|
2026-04-25 16:27:10 -06:00
|
|
|
println!("connected to controller at {}", remote_shell::LISTEN_ADDR);
|
2026-04-25 14:41:00 -06:00
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
match frame_rx.recv_timeout(Duration::from_millis(25)) {
|
|
|
|
|
Ok(result) => {
|
|
|
|
|
let frame = result?;
|
2026-04-25 15:35:08 -06:00
|
|
|
let outcome = runtime.receive(&Ingress::Parent, frame)?;
|
2026-04-25 16:27:10 -06:00
|
|
|
remote_shell::write_frames(&mut stream, &outcome.frames)?;
|
2026-04-25 14:41:00 -06:00
|
|
|
}
|
|
|
|
|
Err(RecvTimeoutError::Timeout) => {}
|
|
|
|
|
Err(RecvTimeoutError::Disconnected) => break,
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-25 15:35:08 -06:00
|
|
|
let outcome = runtime.poll()?;
|
2026-04-25 16:27:10 -06:00
|
|
|
remote_shell::write_frames(&mut stream, &outcome.frames)?;
|
2026-04-25 14:41:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|