From 28b08034f5c0fc97ef90b959ac0a70910b13c042 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sun, 10 Sep 2023 15:53:19 -0400 Subject: [PATCH] appmessage/call commands --- veilid-core/src/routing_table/debug.rs | 1 + veilid-core/src/veilid_api/debug.rs | 93 +++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/veilid-core/src/routing_table/debug.rs b/veilid-core/src/routing_table/debug.rs index 8f3875d9..64207987 100644 --- a/veilid-core/src/routing_table/debug.rs +++ b/veilid-core/src/routing_table/debug.rs @@ -73,6 +73,7 @@ impl RoutingTable { " Self Transfer Stats: {:#?}\n\n", inner.self_transfer_stats ); + out += &format!(" Version: {}\n\n", veilid_version_string()); out } diff --git a/veilid-core/src/veilid_api/debug.rs b/veilid-core/src/veilid_api/debug.rs index 524c0cd8..81920b38 100644 --- a/veilid-core/src/veilid_api/debug.rs +++ b/veilid-core/src/veilid_api/debug.rs @@ -439,6 +439,19 @@ fn get_debug_argument Option>( }; Ok(val) } + +async fn async_get_debug_argument SendPinBoxFuture>>( + value: &str, + context: &str, + argument: &str, + getter: G, +) -> VeilidAPIResult { + let Some(val) = getter(value).await else { + apibail_invalid_argument!(context, argument, value); + }; + Ok(val) +} + fn get_debug_argument_at Option>( debug_args: &[String], pos: usize, @@ -820,7 +833,7 @@ impl VeilidAPI { ) .await?; - // Dump routing table entry + // Send a StatusQ let out = match rpc .rpc_call_status(dest) .await @@ -835,6 +848,78 @@ impl VeilidAPI { Ok(format!("{:#?}", out)) } + async fn debug_app_message(&self, args: String) -> VeilidAPIResult { + let netman = self.network_manager()?; + let routing_table = netman.routing_table(); + let rpc = netman.rpc_processor(); + + let (arg, rest) = args.split_once(' ').unwrap_or((&args, "")); + let rest = rest.trim_start().to_owned(); + + let dest = async_get_debug_argument( + arg, + "debug_app_message", + "destination", + get_destination(routing_table), + ) + .await?; + + let data = get_debug_argument(&rest, "debug_app_message", "data", get_data)?; + let data_len = data.len(); + + // Send a AppMessage + let out = match rpc + .rpc_call_app_message(dest, data) + .await + .map_err(VeilidAPIError::internal)? + { + NetworkResult::Value(_) => format!("Sent {} bytes", data_len), + r => { + return Ok(r.to_string()); + } + }; + + Ok(out) + } + + async fn debug_app_call(&self, args: String) -> VeilidAPIResult { + let netman = self.network_manager()?; + let routing_table = netman.routing_table(); + let rpc = netman.rpc_processor(); + + let (arg, rest) = args.split_once(' ').unwrap_or((&args, "")); + let rest = rest.trim_start().to_owned(); + + let dest = async_get_debug_argument( + arg, + "debug_app_call", + "destination", + get_destination(routing_table), + ) + .await?; + + let data = get_debug_argument(&rest, "debug_app_call", "data", get_data)?; + let data_len = data.len(); + + // Send a AppMessage + let out = match rpc + .rpc_call_app_call(dest, data) + .await + .map_err(VeilidAPIError::internal)? + { + NetworkResult::Value(v) => format!( + "Sent {} bytes, received: {}", + data_len, + print_data(&v.answer, Some(512)) + ), + r => { + return Ok(r.to_string()); + } + }; + + Ok(out) + } + async fn debug_route_allocate(&self, args: Vec) -> VeilidAPIResult { // [ord|*ord] [rel] [] [in|out] [avoid_node_id] @@ -1451,6 +1536,8 @@ detach restart network contact [] ping +appmessage +appcall relay [public|local] punish list route allocate [ord|*ord] [rel] [] [in|out] @@ -1528,6 +1615,10 @@ record list self.debug_relay(rest).await } else if arg == "ping" { self.debug_ping(rest).await + } else if arg == "appmessage" { + self.debug_app_message(rest).await + } else if arg == "appcall" { + self.debug_app_call(rest).await } else if arg == "contact" { self.debug_contact(rest).await } else if arg == "nodeinfo" {