From 38abe7874dda5f7445c01b09dee32c29173c9703 Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 8 Jun 2022 11:18:17 -0400 Subject: [PATCH] refactor for tracing and api logging --- .../src/network_manager/connection_table.rs | 7 +- veilid-server/src/cmdline.rs | 24 +++- veilid-server/src/server.rs | 4 +- veilid-server/src/settings.rs | 136 ++++++++++++++++++ 4 files changed, 161 insertions(+), 10 deletions(-) diff --git a/veilid-core/src/network_manager/connection_table.rs b/veilid-core/src/network_manager/connection_table.rs index fa1f0c54..8873d171 100644 --- a/veilid-core/src/network_manager/connection_table.rs +++ b/veilid-core/src/network_manager/connection_table.rs @@ -64,7 +64,7 @@ impl ConnectionTable { // then drop the least recently used connection if self.conn_by_descriptor[index].len() > self.max_connections[index] { if let Some((lruk, _)) = self.conn_by_descriptor[index].remove_lru() { - warn!("XX: connection lru out: {:?}", lruk); + debug!("connection lru out: {:?}", lruk); self.remove_connection_records(lruk); } } @@ -75,14 +75,12 @@ impl ConnectionTable { .entry(descriptor.remote()) .or_default(); - warn!("add_connection: {:?}", descriptor); descriptors.push(descriptor); Ok(()) } pub fn get_connection(&mut self, descriptor: ConnectionDescriptor) -> Option { - warn!("get_connection: {:?}", descriptor); let index = protocol_to_index(descriptor.protocol_type()); let out = self.conn_by_descriptor[index].get(&descriptor); out.map(|c| c.get_handle()) @@ -92,7 +90,6 @@ impl ConnectionTable { &mut self, remote: PeerAddress, ) -> Option { - warn!("get_last_connection_by_remote: {:?}", remote); let descriptor = self .descriptors_by_remote .get(&remote) @@ -113,7 +110,6 @@ impl ConnectionTable { &mut self, remote: PeerAddress, ) -> Vec { - warn!("get_connection_descriptors_by_remote: {:?}", remote); self.descriptors_by_remote .get(&remote) .cloned() @@ -154,7 +150,6 @@ impl ConnectionTable { } pub fn remove_connection(&mut self, descriptor: ConnectionDescriptor) -> Result<(), String> { - warn!("remove_connection: {:?}", descriptor); let index = protocol_to_index(descriptor.protocol_type()); let _ = self.conn_by_descriptor[index] .remove(&descriptor) diff --git a/veilid-server/src/cmdline.rs b/veilid-server/src/cmdline.rs index a9169c7b..ee44bfa4 100644 --- a/veilid-server/src/cmdline.rs +++ b/veilid-server/src/cmdline.rs @@ -32,7 +32,16 @@ fn do_clap_matches(default_config_path: &OsStr) -> Result Result<(Settings, ArgMatches), String> { }; settingsrw.core.network.bootstrap_nodes = bootstrap_list; } + drop(settingsrw); + + // Set specific config settings + if let Some(set_configs) = matches.values_of("set-config") { + for set_config in set_configs { + if let Some((k, v)) = set_config.split_once('=') { + let k = k.trim(); + let v = v.trim(); + settings.set(k, v)?; + } + } + } // Apply subnode index if we're testing - drop(settingsrw); settings .apply_subnode_index() .map_err(|_| "failed to apply subnode index".to_owned())?; diff --git a/veilid-server/src/server.rs b/veilid-server/src/server.rs index fcc63b65..16fdfc05 100644 --- a/veilid-server/src/server.rs +++ b/veilid-server/src/server.rs @@ -1,6 +1,6 @@ use crate::client_api; use crate::settings::*; -use flume::{bounded, Receiver, Sender}; +use flume::{unbounded, Receiver, Sender}; use lazy_static::*; use parking_lot::Mutex; use std::sync::Arc; @@ -45,7 +45,7 @@ pub async fn run_veilid_server_internal( let (sender, receiver): ( Sender, Receiver, - ) = bounded(1); + ) = unbounded(); // Create VeilidCore setup let update_callback = Arc::new(move |change: veilid_core::VeilidUpdate| { diff --git a/veilid-server/src/settings.rs b/veilid-server/src/settings.rs index 3c155934..d22a36b5 100644 --- a/veilid-server/src/settings.rs +++ b/veilid-server/src/settings.rs @@ -849,6 +849,142 @@ impl Settings { pk_path } + pub fn set(&self, key: &str, value: &str) -> Result<(), String> { + let mut inner = self.inner.write(); + + macro_rules! set_config_value { + ($innerkey:expr, $value:expr) => {{ + let innerkeyname = &stringify!($innerkey)[6..]; + if innerkeyname == key { + match veilid_core::deserialize_json(value) { + Ok(v) => { + $innerkey = v; + return Ok(()); + } + Err(e) => { + return Err(format!( + "invalid type for key {}, value: {}: {}", + key, value, e + )) + } + } + } + }}; + } + set_config_value!(inner.daemon.enabled, value); + set_config_value!(inner.client_api.enabled, value); + set_config_value!(inner.client_api.listen_address, value); + set_config_value!(inner.auto_attach, value); + set_config_value!(inner.logging.system.enabled, value); + set_config_value!(inner.logging.system.level, value); + set_config_value!(inner.logging.terminal.enabled, value); + set_config_value!(inner.logging.terminal.level, value); + set_config_value!(inner.logging.file.enabled, value); + set_config_value!(inner.logging.file.path, value); + set_config_value!(inner.logging.file.append, value); + set_config_value!(inner.logging.file.level, value); + set_config_value!(inner.logging.api.enabled, value); + set_config_value!(inner.logging.api.level, value); + set_config_value!(inner.testing.subnode_index, value); + set_config_value!(inner.core.protected_store.allow_insecure_fallback, value); + set_config_value!( + inner.core.protected_store.always_use_insecure_storage, + value + ); + set_config_value!( + inner.core.protected_store.insecure_fallback_directory, + value + ); + set_config_value!(inner.core.protected_store.delete, value); + set_config_value!(inner.core.table_store.directory, value); + set_config_value!(inner.core.table_store.delete, value); + set_config_value!(inner.core.block_store.directory, value); + set_config_value!(inner.core.block_store.delete, value); + set_config_value!(inner.core.network.connection_initial_timeout_ms, value); + set_config_value!(inner.core.network.connection_inactivity_timeout_ms, value); + set_config_value!(inner.core.network.max_connections_per_ip4, value); + set_config_value!(inner.core.network.max_connections_per_ip6_prefix, value); + set_config_value!( + inner.core.network.max_connections_per_ip6_prefix_size, + value + ); + set_config_value!(inner.core.network.max_connection_frequency_per_min, value); + set_config_value!(inner.core.network.client_whitelist_timeout_ms, value); + set_config_value!(inner.core.network.reverse_connection_receipt_time_ms, value); + set_config_value!(inner.core.network.hole_punch_receipt_time_ms, value); + set_config_value!(inner.core.network.node_id, value); + set_config_value!(inner.core.network.node_id_secret, value); + set_config_value!(inner.core.network.bootstrap, value); + set_config_value!(inner.core.network.bootstrap_nodes, value); + set_config_value!(inner.core.network.routing_table.limit_over_attached, value); + set_config_value!(inner.core.network.routing_table.limit_fully_attached, value); + set_config_value!( + inner.core.network.routing_table.limit_attached_strong, + value + ); + set_config_value!(inner.core.network.routing_table.limit_attached_good, value); + set_config_value!(inner.core.network.routing_table.limit_attached_weak, value); + set_config_value!(inner.core.network.rpc.concurrency, value); + set_config_value!(inner.core.network.rpc.queue_size, value); + set_config_value!(inner.core.network.rpc.max_timestamp_behind_ms, value); + set_config_value!(inner.core.network.rpc.max_timestamp_ahead_ms, value); + set_config_value!(inner.core.network.rpc.timeout_ms, value); + set_config_value!(inner.core.network.rpc.max_route_hop_count, value); + set_config_value!(inner.core.network.dht.resolve_node_timeout_ms, value); + set_config_value!(inner.core.network.dht.resolve_node_count, value); + set_config_value!(inner.core.network.dht.resolve_node_fanout, value); + set_config_value!(inner.core.network.dht.max_find_node_count, value); + set_config_value!(inner.core.network.dht.get_value_timeout_ms, value); + set_config_value!(inner.core.network.dht.get_value_count, value); + set_config_value!(inner.core.network.dht.get_value_fanout, value); + set_config_value!(inner.core.network.dht.set_value_timeout_ms, value); + set_config_value!(inner.core.network.dht.set_value_count, value); + set_config_value!(inner.core.network.dht.set_value_fanout, value); + set_config_value!(inner.core.network.dht.min_peer_count, value); + set_config_value!(inner.core.network.dht.min_peer_refresh_time_ms, value); + set_config_value!( + inner.core.network.dht.validate_dial_info_receipt_time_ms, + value + ); + set_config_value!(inner.core.network.upnp, value); + set_config_value!(inner.core.network.natpmp, value); + set_config_value!(inner.core.network.enable_local_peer_scope, value); + set_config_value!(inner.core.network.restricted_nat_retries, value); + set_config_value!(inner.core.network.tls.certificate_path, value); + set_config_value!(inner.core.network.tls.private_key_path, value); + set_config_value!(inner.core.network.tls.connection_initial_timeout_ms, value); + set_config_value!(inner.core.network.application.https.enabled, value); + set_config_value!(inner.core.network.application.https.listen_address, value); + set_config_value!(inner.core.network.application.https.path, value); + set_config_value!(inner.core.network.application.https.url, value); + set_config_value!(inner.core.network.application.http.enabled, value); + set_config_value!(inner.core.network.application.http.listen_address, value); + set_config_value!(inner.core.network.application.http.path, value); + set_config_value!(inner.core.network.application.http.url, value); + set_config_value!(inner.core.network.protocol.udp.enabled, value); + set_config_value!(inner.core.network.protocol.udp.socket_pool_size, value); + set_config_value!(inner.core.network.protocol.udp.listen_address, value); + set_config_value!(inner.core.network.protocol.udp.public_address, value); + set_config_value!(inner.core.network.protocol.tcp.connect, value); + set_config_value!(inner.core.network.protocol.tcp.listen, value); + set_config_value!(inner.core.network.protocol.tcp.max_connections, value); + set_config_value!(inner.core.network.protocol.tcp.listen_address, value); + set_config_value!(inner.core.network.protocol.tcp.public_address, value); + set_config_value!(inner.core.network.protocol.ws.connect, value); + set_config_value!(inner.core.network.protocol.ws.listen, value); + set_config_value!(inner.core.network.protocol.ws.max_connections, value); + set_config_value!(inner.core.network.protocol.ws.listen_address, value); + set_config_value!(inner.core.network.protocol.ws.path, value); + set_config_value!(inner.core.network.protocol.ws.url, value); + set_config_value!(inner.core.network.protocol.wss.connect, value); + set_config_value!(inner.core.network.protocol.wss.listen, value); + set_config_value!(inner.core.network.protocol.wss.max_connections, value); + set_config_value!(inner.core.network.protocol.wss.listen_address, value); + set_config_value!(inner.core.network.protocol.wss.path, value); + set_config_value!(inner.core.network.protocol.wss.url, value); + Err("settings key not found".to_owned()) + } + pub fn get_core_config_callback(&self) -> veilid_core::ConfigCallback { let inner = self.inner.clone();