Live sync JSON documents over Iroh

This commit is contained in:
Eric Wendland 2026-05-18 18:49:34 +02:00
commit 284207eb01
8 changed files with 370 additions and 7 deletions

View file

@ -359,6 +359,7 @@ pub enum DocumentCommand {
Status { name: String },
Set { name: String, state_json: String },
Get { name: String },
Sync { node: String, name: String },
}
#[derive(Debug, Subcommand)]
@ -672,6 +673,7 @@ fn request_for_command(command: Command) -> Result<ControlRequest> {
ControlRequest::DocumentSet { name, state_json }
}
DocumentCommand::Get { name } => ControlRequest::DocumentGet { name },
DocumentCommand::Sync { node, name } => ControlRequest::DocumentSync { node, name },
},
Command::Ssh { command } => match command {
SshCommand::Proxy { node } => ControlRequest::ModuleStub {
@ -1378,6 +1380,27 @@ fn print_response(response: ControlResponse, json: bool) -> Result<()> {
ControlResponse::DocumentGet { state } => {
println!("{}", state.state_json);
}
ControlResponse::DocumentSynced {
peer_node_id,
peer_agent_id,
endpoint_id,
name,
updated,
allowed,
reason,
note,
} => {
if allowed {
println!("synced document {name} from {peer_node_id}: updated={updated}");
} else {
println!("document sync denied for {name} by {peer_node_id}");
}
println!("agent: {peer_agent_id}");
println!("endpoint: {endpoint_id}");
println!("allowed: {allowed}");
println!("reason: {reason}");
println!("note: {note}");
}
ControlResponse::PubsubPublished { message } => {
println!("published: {}", message.topic);
println!("published_at_ms: {}", message.published_at.0);