From f4f5808df290fbd82d8f531dab0b2bd2181b8adb Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 18 May 2022 10:17:04 -0400 Subject: [PATCH] fixes for stats and crash --- .vscode/launch.json | 7 ++++ veilid-cli/src/client_api_connection.rs | 34 +++++++++++++++++-- veilid-core/src/network_manager.rs | 6 ++++ .../src/routing_table/stats_accounting.rs | 4 +-- veilid-core/src/rpc_processor/debug.rs | 8 +++-- veilid-core/src/rpc_processor/mod.rs | 28 ++++++++++----- veilid-core/src/veilid_api/mod.rs | 4 +-- veilid-server/src/cmdline.rs | 16 +++++++-- veilid-server/src/server.rs | 5 +++ 9 files changed, 92 insertions(+), 20 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 40a1d3ca..48d0427e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,13 @@ "program": "${workspaceFolder}/target/debug/veilid-server", "pid": "${command:pickMyProcess}" }, + { + "type": "lldb", + "request": "attach", + "name": "Attach to veilid-cli", + "program": "${workspaceFolder}/target/debug/veilid-cli", + "pid": "${command:pickMyProcess}" + }, { "type": "lldb", "request": "attach", diff --git a/veilid-cli/src/client_api_connection.rs b/veilid-cli/src/client_api_connection.rs index 2a2f073f..2241f6b3 100644 --- a/veilid-cli/src/client_api_connection.rs +++ b/veilid-cli/src/client_api_connection.rs @@ -9,6 +9,14 @@ use std::net::SocketAddr; use std::rc::Rc; use veilid_core::xx::*; +macro_rules! capnp_failed { + ($ex:expr) => {{ + let msg = format!("Capnp Error: {}", $ex); + error!("{}", msg); + Promise::err(capnp::Error::failed(msg)) + }}; +} + struct VeilidClientImpl { comproc: CommandProcessor, } @@ -30,7 +38,7 @@ impl veilid_client::Server for VeilidClientImpl { let which = match veilid_update.which() { Ok(v) => v, Err(e) => { - panic!("(missing update kind in schema: {:?})", e); + return capnp_failed!(format!("(missing update kind in schema: {:?})", e)); } }; match which { @@ -40,8 +48,28 @@ impl veilid_client::Server for VeilidClientImpl { trace!("Attachment: {}", state as u16); self.comproc.update_attachment(state); } - _ => { - panic!("shouldn't get this") + veilid_update::Attachment(Err(e)) => { + return capnp_failed!(format!("Update Attachment Error: {}", e)); + } + veilid_update::Network(Ok(network)) => { + let started = network.get_started(); + let bps_down = network.get_bps_down(); + let bps_up = network.get_bps_up(); + + trace!( + "Network: started: {} bps_down: {} bps_up: {}", + started, + bps_down, + bps_up + ); + self.comproc + .update_network_status(started, bps_down, bps_up); + } + veilid_update::Network(Err(e)) => { + return capnp_failed!(format!("Update Network Error: {}", e)); + } + veilid_update::Shutdown(()) => { + return capnp_failed!("Should not get Shutdown here".to_owned()); } } diff --git a/veilid-core/src/network_manager.rs b/veilid-core/src/network_manager.rs index af0ff314..5007686a 100644 --- a/veilid-core/src/network_manager.rs +++ b/veilid-core/src/network_manager.rs @@ -351,6 +351,12 @@ impl NetworkManager { self.send_network_update(); } + // Run the rolling transfers task + self.unlocked_inner.rolling_transfers_task.tick().await?; + + // Run the relay management task + self.unlocked_inner.relay_management_task.tick().await?; + // Run the routing table tick routing_table.tick().await?; diff --git a/veilid-core/src/routing_table/stats_accounting.rs b/veilid-core/src/routing_table/stats_accounting.rs index 31c86765..c99b7327 100644 --- a/veilid-core/src/routing_table/stats_accounting.rs +++ b/veilid-core/src/routing_table/stats_accounting.rs @@ -10,7 +10,7 @@ const ROLLING_LATENCIES_SIZE: usize = 10; // - Size is number of entries // - Interval is number of seconds in each entry const ROLLING_TRANSFERS_SIZE: usize = 10; -pub const ROLLING_TRANSFERS_INTERVAL_SECS: u32 = 10; +pub const ROLLING_TRANSFERS_INTERVAL_SECS: u32 = 1; #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub struct TransferCount { @@ -71,7 +71,7 @@ impl TransferStatsAccounting { transfer_stats.down.minimum.min_assign(bpsd); transfer_stats.up.minimum.min_assign(bpsu); transfer_stats.down.average += bpsd; - transfer_stats.down.average += bpsu; + transfer_stats.up.average += bpsu; } let len = self.rolling_transfers.len() as u64; transfer_stats.down.average /= len; diff --git a/veilid-core/src/rpc_processor/debug.rs b/veilid-core/src/rpc_processor/debug.rs index 203cc27a..6ef8505f 100644 --- a/veilid-core/src/rpc_processor/debug.rs +++ b/veilid-core/src/rpc_processor/debug.rs @@ -3,7 +3,7 @@ use super::*; #[derive(Debug, Clone, PartialOrd, PartialEq, Eq, Ord)] pub enum RPCError { Timeout, - InvalidFormat, + InvalidFormat(String), Unreachable(DHTKey), Unimplemented(String), Protocol(String), @@ -14,6 +14,10 @@ pub fn rpc_error_internal>(x: T) -> RPCError { error!("RPCError Internal: {}", x.as_ref()); RPCError::Internal(x.as_ref().to_owned()) } +pub fn rpc_error_invalid_format>(x: T) -> RPCError { + error!("RPCError Invalid Format: {}", x.as_ref()); + RPCError::InvalidFormat(x.as_ref().to_owned()) +} pub fn rpc_error_protocol>(x: T) -> RPCError { error!("RPCError Protocol: {}", x.as_ref()); RPCError::Protocol(x.as_ref().to_owned()) @@ -35,7 +39,7 @@ impl fmt::Display for RPCError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { RPCError::Timeout => write!(f, "[RPCError: Timeout]"), - RPCError::InvalidFormat => write!(f, "[RPCError: InvalidFormat]"), + RPCError::InvalidFormat(s) => write!(f, "[RPCError: InvalidFormat({})]", s), RPCError::Unreachable(k) => write!(f, "[RPCError: Unreachable({})]", k), RPCError::Unimplemented(s) => write!(f, "[RPCError: Unimplemented({})]", s), RPCError::Protocol(s) => write!(f, "[RPCError: Protocol({})]", s), diff --git a/veilid-core/src/rpc_processor/mod.rs b/veilid-core/src/rpc_processor/mod.rs index 70426857..affbd947 100644 --- a/veilid-core/src/rpc_processor/mod.rs +++ b/veilid-core/src/rpc_processor/mod.rs @@ -855,7 +855,9 @@ impl RPCProcessor { // This should never want an answer if self.wants_answer(&operation)? { - return Err(RPCError::InvalidFormat); + return Err(rpc_error_invalid_format( + "validate dial info should not want answer", + )); } // get validateDialInfo reader @@ -958,7 +960,7 @@ impl RPCProcessor { // find_node must always want an answer if !self.wants_answer(&operation)? { - return Err(RPCError::InvalidFormat).map_err(logthru_rpc!()); + return Err(rpc_error_invalid_format("find_node_q should want answer")); } // get findNodeQ reader @@ -1030,7 +1032,9 @@ impl RPCProcessor { // This should never want an answer if self.wants_answer(&operation)? { - return Err(RPCError::InvalidFormat); + return Err(rpc_error_invalid_format( + "node_info_update should not want answer", + )); } // get nodeInfoUpdate reader @@ -1048,7 +1052,9 @@ impl RPCProcessor { // Update our routing table with signed node info if !self.filter_peer_scope(&signed_node_info.node_info) { - return Err(RPCError::InvalidFormat); + return Err(rpc_error_invalid_format( + "node_info_update has invalid peer scope", + )); } let _ = self .routing_table() @@ -1092,7 +1098,7 @@ impl RPCProcessor { // This should never want an answer if self.wants_answer(&operation)? { - return Err(RPCError::InvalidFormat); + return Err(rpc_error_invalid_format("signal should not want answer")); } // get signal reader @@ -1123,7 +1129,9 @@ impl RPCProcessor { // This should never want an answer if self.wants_answer(&operation)? { - return Err(RPCError::InvalidFormat); + return Err(rpc_error_invalid_format( + "return receipt should not want answer", + )); } // get returnReceipt reader @@ -1229,7 +1237,9 @@ impl RPCProcessor { { // Sender NodeInfo was specified, update our routing table with it if !self.filter_peer_scope(&sender_ni.node_info) { - return Err(RPCError::InvalidFormat); + return Err(rpc_error_invalid_format( + "respond_to_sender_signed_node_info has invalid peer scope", + )); } let nr = self .routing_table() @@ -1630,7 +1640,9 @@ impl RPCProcessor { let peer_info = decode_peer_info(&p, true)?; if !self.filter_peer_scope(&peer_info.signed_node_info.node_info) { - return Err(RPCError::InvalidFormat); + return Err(rpc_error_invalid_format( + "find_node response has invalid peer scope", + )); } peers.push(peer_info); diff --git a/veilid-core/src/veilid_api/mod.rs b/veilid-core/src/veilid_api/mod.rs index 5ada68f5..40f2769f 100644 --- a/veilid-core/src/veilid_api/mod.rs +++ b/veilid-core/src/veilid_api/mod.rs @@ -123,8 +123,8 @@ fn convert_rpc_error(x: RPCError) -> VeilidAPIError { RPCError::Unimplemented(s) => VeilidAPIError::Unimplemented { message: s }, RPCError::Internal(s) => VeilidAPIError::Internal { message: s }, RPCError::Protocol(s) => VeilidAPIError::Internal { message: s }, - RPCError::InvalidFormat => VeilidAPIError::Internal { - message: "Invalid packet format".to_owned(), + RPCError::InvalidFormat(s) => VeilidAPIError::Internal { + message: format!("Invalid RPC format: {}", s), }, } } diff --git a/veilid-server/src/cmdline.rs b/veilid-server/src/cmdline.rs index 9ba8a936..a9169c7b 100644 --- a/veilid-server/src/cmdline.rs +++ b/veilid-server/src/cmdline.rs @@ -16,6 +16,13 @@ fn do_clap_matches(default_config_path: &OsStr) -> Result Result<(Settings, ArgMatches), String> { settingsrw.daemon.enabled = true; settingsrw.logging.terminal.enabled = false; } + if matches.occurrences_of("foreground") != 0 { + settingsrw.daemon.enabled = false; + } if matches.occurrences_of("subnode-index") != 0 { let subnode_index = match matches.value_of("subnode-index") { Some(x) => x @@ -219,7 +229,7 @@ pub fn process_command_line() -> Result<(Settings, ArgMatches), String> { } if matches.occurrences_of("bootstrap") != 0 { - let bootstrap_list = match matches.value_of("bootstrap-list") { + let bootstrap_list = match matches.value_of("bootstrap") { Some(x) => { println!("Overriding bootstrap list with: "); let mut out: Vec = Vec::new(); @@ -231,14 +241,14 @@ pub fn process_command_line() -> Result<(Settings, ArgMatches), String> { out } None => { - return Err("value not specified for bootstrap list".to_owned()); + return Err("value not specified for bootstrap".to_owned()); } }; settingsrw.core.network.bootstrap = bootstrap_list; } if matches.occurrences_of("bootstrap-nodes") != 0 { - let bootstrap_list = match matches.value_of("bootstrap-list") { + let bootstrap_list = match matches.value_of("bootstrap-nodes") { Some(x) => { println!("Overriding bootstrap node list with: "); let mut out: Vec = Vec::new(); diff --git a/veilid-server/src/server.rs b/veilid-server/src/server.rs index fa75897a..8f0a4693 100644 --- a/veilid-server/src/server.rs +++ b/veilid-server/src/server.rs @@ -159,6 +159,11 @@ pub async fn run_veilid_server( shutdown(); } + // Process shutdown-immediate + if matches!(server_mode, ServerMode::ShutdownImmediate) { + shutdown(); + } + // Idle while waiting to exit let shutdown_switch = { let shutdown_switch_locked = SHUTDOWN_SWITCH.lock();