From a5e17a0d650140dba059d8cf5624626098d6a4a7 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sun, 10 Sep 2023 17:07:22 -0400 Subject: [PATCH] appreply --- veilid-core/src/rpc_processor/mod.rs | 5 +++ .../src/rpc_processor/operation_waiter.rs | 14 ++++++++ veilid-core/src/veilid_api/debug.rs | 34 +++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/veilid-core/src/rpc_processor/mod.rs b/veilid-core/src/rpc_processor/mod.rs index 8f4baea8..38a38ed8 100644 --- a/veilid-core/src/rpc_processor/mod.rs +++ b/veilid-core/src/rpc_processor/mod.rs @@ -434,6 +434,11 @@ impl RPCProcessor { ////////////////////////////////////////////////////////////////////// + /// Get waiting app call id for debugging purposes + pub fn get_app_call_ids(&self) -> Vec { + self.unlocked_inner.waiting_app_call_table.get_operation_ids() + } + /// Determine if a SignedNodeInfo can be placed into the specified routing domain fn verify_node_info( &self, diff --git a/veilid-core/src/rpc_processor/operation_waiter.rs b/veilid-core/src/rpc_processor/operation_waiter.rs index 3588e10e..f7c7bd00 100644 --- a/veilid-core/src/rpc_processor/operation_waiter.rs +++ b/veilid-core/src/rpc_processor/operation_waiter.rs @@ -30,6 +30,7 @@ where C: Unpin + Clone, { context: C, + timestamp: Timestamp, eventual: EventualValue<(Option, T)>, } @@ -82,6 +83,7 @@ where let e = EventualValue::new(); let waiting_op = OperationWaitingOp { context, + timestamp: get_aligned_timestamp(), eventual: e.clone(), }; if inner.waiting_op_table.insert(op_id, waiting_op).is_some() { @@ -98,6 +100,18 @@ where } } + /// Get all waiting operation ids + pub fn get_operation_ids(&self) -> Vec { + let inner = self.inner.lock(); + let mut opids: Vec<(OperationId, Timestamp)> = inner + .waiting_op_table + .iter() + .map(|x| (*x.0, x.1.timestamp)) + .collect(); + opids.sort_by(|a, b| a.1.cmp(&b.1)); + opids.into_iter().map(|x| x.0).collect() + } + /// Get operation context pub fn get_op_context(&self, op_id: OperationId) -> Result { let inner = self.inner.lock(); diff --git a/veilid-core/src/veilid_api/debug.rs b/veilid-core/src/veilid_api/debug.rs index 81920b38..90c144c0 100644 --- a/veilid-core/src/veilid_api/debug.rs +++ b/veilid-core/src/veilid_api/debug.rs @@ -920,6 +920,37 @@ impl VeilidAPI { Ok(out) } + async fn debug_app_reply(&self, args: String) -> VeilidAPIResult { + let netman = self.network_manager()?; + let rpc = netman.rpc_processor(); + + let (call_id, data) = if args.starts_with("#") { + let (arg, rest) = args[1..].split_once(' ').unwrap_or((&args, "")); + let call_id = + OperationId::new(u64::from_str_radix(arg, 16).map_err(VeilidAPIError::generic)?); + let rest = rest.trim_start().to_owned(); + let data = get_debug_argument(&rest, "debug_app_reply", "data", get_data)?; + (call_id, data) + } else { + let call_id = rpc + .get_app_call_ids() + .first() + .cloned() + .ok_or_else(|| VeilidAPIError::generic("no app calls waiting"))?; + let data = get_debug_argument(&args, "debug_app_reply", "data", get_data)?; + (call_id, data) + }; + + let data_len = data.len(); + + // Send a AppCall Reply + self.app_call_reply(call_id, data) + .await + .map_err(VeilidAPIError::internal)?; + + Ok(format!("Replied with {} bytes", data_len)) + } + async fn debug_route_allocate(&self, args: Vec) -> VeilidAPIResult { // [ord|*ord] [rel] [] [in|out] [avoid_node_id] @@ -1538,6 +1569,7 @@ contact [] ping appmessage appcall +appreply [#id] relay [public|local] punish list route allocate [ord|*ord] [rel] [] [in|out] @@ -1619,6 +1651,8 @@ record list self.debug_app_message(rest).await } else if arg == "appcall" { self.debug_app_call(rest).await + } else if arg == "appreply" { + self.debug_app_reply(rest).await } else if arg == "contact" { self.debug_contact(rest).await } else if arg == "nodeinfo" {