diff --git a/veilid-core/src/attachment_manager.rs b/veilid-core/src/attachment_manager.rs index 74f507de..a2254429 100644 --- a/veilid-core/src/attachment_manager.rs +++ b/veilid-core/src/attachment_manager.rs @@ -211,7 +211,7 @@ impl AttachmentManager { } } - #[instrument(level = "debug", skip(self))] + #[instrument(level = "debug", skip_all)] async fn attachment_maintainer(self) { log_net!(debug "attachment starting"); self.update_attaching_detaching_state(AttachmentState::Attaching); @@ -286,7 +286,7 @@ impl AttachmentManager { Ok(()) } - #[instrument(level = "debug", skip(self))] + #[instrument(level = "debug", skip_all)] pub async fn terminate(&self) { // Ensure we detached self.detach().await; @@ -294,7 +294,7 @@ impl AttachmentManager { self.inner.lock().update_callback = None; } - #[instrument(level = "trace", skip(self))] + #[instrument(level = "trace", skip_all)] pub async fn attach(&self) -> bool { // Create long-running connection maintenance routine let mut inner = self.inner.lock(); @@ -307,7 +307,7 @@ impl AttachmentManager { true } - #[instrument(level = "trace", skip(self))] + #[instrument(level = "trace", skip_all)] pub async fn detach(&self) -> bool { let attachment_maintainer_jh = { let mut inner = self.inner.lock(); diff --git a/veilid-core/src/core_context.rs b/veilid-core/src/core_context.rs index 6a34f289..d5cf5274 100644 --- a/veilid-core/src/core_context.rs +++ b/veilid-core/src/core_context.rs @@ -62,7 +62,7 @@ impl ServicesContext { } } - #[instrument(err, skip_all)] + #[instrument(level = "trace", target = "core_context", err, skip_all)] pub async fn startup(&mut self) -> EyreResult<()> { info!("Veilid API starting up"); @@ -151,7 +151,7 @@ impl ServicesContext { Ok(()) } - #[instrument(skip_all)] + #[instrument(level = "trace", target = "core_context", skip_all)] pub async fn shutdown(&mut self) { info!("Veilid API shutting down"); @@ -200,7 +200,7 @@ pub(crate) struct VeilidCoreContext { } impl VeilidCoreContext { - #[instrument(err, skip_all)] + #[instrument(level = "trace", target = "core_context", err, skip_all)] async fn new_with_config_callback( update_callback: UpdateCallback, config_callback: ConfigCallback, @@ -212,7 +212,7 @@ impl VeilidCoreContext { Self::new_common(update_callback, config).await } - #[instrument(err, skip_all)] + #[instrument(level = "trace", target = "core_context", err, skip_all)] async fn new_with_config_json( update_callback: UpdateCallback, config_json: String, @@ -223,7 +223,7 @@ impl VeilidCoreContext { Self::new_common(update_callback, config).await } - #[instrument(err, skip_all)] + #[instrument(level = "trace", target = "core_context", err, skip_all)] async fn new_with_config( update_callback: UpdateCallback, config_inner: VeilidConfigInner, @@ -234,7 +234,7 @@ impl VeilidCoreContext { Self::new_common(update_callback, config).await } - #[instrument(err, skip_all)] + #[instrument(level = "trace", target = "core_context", err, skip_all)] async fn new_common( update_callback: UpdateCallback, config: VeilidConfig, @@ -263,7 +263,7 @@ impl VeilidCoreContext { }) } - #[instrument(skip_all)] + #[instrument(level = "trace", target = "core_context", skip_all)] async fn shutdown(self) { let mut sc = ServicesContext::new_full( self.config.clone(), @@ -294,7 +294,7 @@ lazy_static::lazy_static! { /// * `config_callback` - called at startup to supply a configuration object directly to Veilid. /// /// Returns a [VeilidAPI] object that can be used to operate the node. -#[instrument(err, skip_all)] +#[instrument(level = "trace", target = "core_context", err, skip_all)] pub async fn api_startup( update_callback: UpdateCallback, config_callback: ConfigCallback, @@ -325,7 +325,7 @@ pub async fn api_startup( /// * `config_json` - called at startup to supply a JSON configuration object. /// /// Returns a [VeilidAPI] object that can be used to operate the node. -#[instrument(err, skip_all)] +#[instrument(level = "trace", target = "core_context", err, skip_all)] pub async fn api_startup_json( update_callback: UpdateCallback, config_json: String, @@ -355,7 +355,7 @@ pub async fn api_startup_json( /// * `config` - called at startup to supply a configuration object. /// /// Returns a [VeilidAPI] object that can be used to operate the node. -#[instrument(err, skip_all)] +#[instrument(level = "trace", target = "core_context", err, skip_all)] pub async fn api_startup_config( update_callback: UpdateCallback, config: VeilidConfigInner, @@ -377,7 +377,7 @@ pub async fn api_startup_config( Ok(veilid_api) } -#[instrument(skip_all)] +#[instrument(level = "trace", target = "core_context", skip_all)] pub(crate) async fn api_shutdown(context: VeilidCoreContext) { let mut initialized_lock = INITIALIZED.lock().await; context.shutdown().await; diff --git a/veilid-core/src/crypto/mod.rs b/veilid-core/src/crypto/mod.rs index 3ed636e4..9d88a3ca 100644 --- a/veilid-core/src/crypto/mod.rs +++ b/veilid-core/src/crypto/mod.rs @@ -128,7 +128,7 @@ impl Crypto { self.unlocked_inner.config.clone() } - #[instrument(skip_all, err)] + #[instrument(level = "trace", target = "crypto", skip_all, err)] pub async fn init(&self) -> EyreResult<()> { let table_store = self.unlocked_inner.table_store.clone(); // Init node id from config diff --git a/veilid-core/src/lib.rs b/veilid-core/src/lib.rs index 8ee99a56..0a019576 100644 --- a/veilid-core/src/lib.rs +++ b/veilid-core/src/lib.rs @@ -61,7 +61,7 @@ mod wasm_helpers; pub use self::core_context::{api_startup, api_startup_config, api_startup_json, UpdateCallback}; pub use self::logging::{ ApiTracingLayer, VeilidLayerFilter, DEFAULT_LOG_FACILITIES_ENABLED_LIST, - DEFAULT_LOG_FACILITIES_IGNORE_LIST, DURATION_LOG_FACILITIES, + DEFAULT_LOG_FACILITIES_IGNORE_LIST, DURATION_LOG_FACILITIES, FLAME_LOG_FACILITIES_IGNORE_LIST, }; pub use self::veilid_api::*; pub use self::veilid_config::*; diff --git a/veilid-core/src/logging/facilities.rs b/veilid-core/src/logging/facilities.rs index 2d91255f..7e351b68 100644 --- a/veilid-core/src/logging/facilities.rs +++ b/veilid-core/src/logging/facilities.rs @@ -29,6 +29,31 @@ pub static DEFAULT_LOG_FACILITIES_IGNORE_LIST: [&str; 28] = [ "receipt", ]; +pub static FLAME_LOG_FACILITIES_IGNORE_LIST: [&str; 22] = [ + "mio", + "h2", + "hyper", + "tower", + "tonic", + "tokio", + "runtime", + "tokio_util", + "want", + "serial_test", + "async_std", + "async_io", + "polling", + "rustls", + "async_tungstenite", + "tungstenite", + "netlink_proto", + "netlink_sys", + "hickory_resolver", + "hickory_proto", + "attohttpc", + "ws_stream_wasm", +]; + pub static DEFAULT_LOG_FACILITIES_ENABLED_LIST: [&str; 8] = [ "net", "rpc", diff --git a/veilid-core/src/logging/veilid_layer_filter.rs b/veilid-core/src/logging/veilid_layer_filter.rs index a402a531..eaaf98c0 100644 --- a/veilid-core/src/logging/veilid_layer_filter.rs +++ b/veilid-core/src/logging/veilid_layer_filter.rs @@ -16,12 +16,12 @@ pub struct VeilidLayerFilter { impl VeilidLayerFilter { pub fn new( max_level: VeilidConfigLogLevel, - ignore_log_targets: &[String], + ignore_change_list: &[String], ) -> VeilidLayerFilter { let mut ignore_list = DEFAULT_LOG_FACILITIES_IGNORE_LIST .map(|x| x.to_owned()) .to_vec(); - Self::apply_ignore_change_list(&mut ignore_list, ignore_log_targets); + Self::apply_ignore_change_list(&mut ignore_list, ignore_change_list); Self { inner: Arc::new(RwLock::new(VeilidLayerFilterInner { max_level: max_level.to_tracing_level_filter(), @@ -29,6 +29,17 @@ impl VeilidLayerFilter { })), } } + pub fn new_no_default( + max_level: VeilidConfigLogLevel, + ignore_list: &[String], + ) -> VeilidLayerFilter { + Self { + inner: Arc::new(RwLock::new(VeilidLayerFilterInner { + max_level: max_level.to_tracing_level_filter(), + ignore_list: ignore_list.to_vec(), + })), + } + } pub fn max_level(&self) -> VeilidConfigLogLevel { let inner = self.inner.read(); @@ -102,6 +113,9 @@ impl VeilidLayerFilter { .map(|x| x.to_owned()) .collect(); continue; + } else if change == "none" { + ignore_list.clear(); + continue; } else if change == "default" { *ignore_list = [DEFAULT_LOG_FACILITIES_IGNORE_LIST.to_vec()] .concat() diff --git a/veilid-core/src/network_manager/connection_manager.rs b/veilid-core/src/network_manager/connection_manager.rs index d19264d1..ac9ef624 100644 --- a/veilid-core/src/network_manager/connection_manager.rs +++ b/veilid-core/src/network_manager/connection_manager.rs @@ -186,7 +186,7 @@ impl ConnectionManager { // Internal routine to register new connection atomically. // Registers connection in the connection table for later access // and spawns a message processing loop for the connection - #[instrument(level = "trace", skip(self, inner), ret, err)] + //#[instrument(level = "trace", skip(self, inner), ret, err)] fn on_new_protocol_network_connection( &self, inner: &mut ConnectionManagerInner, @@ -420,7 +420,7 @@ impl ConnectionManager { } } - #[instrument(level = "trace", skip_all)] + //#[instrument(level = "trace", skip_all)] async fn async_processor( self, stop_token: StopToken, @@ -438,7 +438,7 @@ impl ConnectionManager { // Called by low-level network when any connection-oriented protocol connection appears // either from incoming connections. - #[cfg_attr(target_arch = "wasm32", allow(dead_code))] + //#[cfg_attr(target_arch = "wasm32", allow(dead_code))] pub(super) async fn on_accepted_protocol_network_connection( &self, protocol_connection: ProtocolNetworkConnection, diff --git a/veilid-core/src/network_manager/mod.rs b/veilid-core/src/network_manager/mod.rs index 694b8368..76e62906 100644 --- a/veilid-core/src/network_manager/mod.rs +++ b/veilid-core/src/network_manager/mod.rs @@ -901,17 +901,6 @@ impl NetworkManager { // and passes it to the RPC handler #[instrument(level = "trace", target = "receipt", skip_all)] async fn on_recv_envelope(&self, data: &mut [u8], flow: Flow) -> EyreResult { - #[cfg(feature = "verbose-tracing")] - let root = span!( - parent: None, - Level::TRACE, - "on_recv_envelope", - "data.len" = data.len(), - "flow" = ?flow - ); - #[cfg(feature = "verbose-tracing")] - let _root_enter = root.enter(); - log_net!("envelope of {} bytes received from {:?}", data.len(), flow); let remote_addr = flow.remote_address().ip_addr(); diff --git a/veilid-core/src/network_manager/native/igd_manager.rs b/veilid-core/src/network_manager/native/igd_manager.rs index 19c9f519..bdd0391a 100644 --- a/veilid-core/src/network_manager/native/igd_manager.rs +++ b/veilid-core/src/network_manager/native/igd_manager.rs @@ -59,6 +59,7 @@ impl IGDManager { } } + #[instrument(level = "trace", target = "net", skip_all)] fn get_routed_local_ip_address(address_type: AddressType) -> Option { let socket = match UdpSocket::bind(match address_type { AddressType::IPV4 => SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0), @@ -90,6 +91,7 @@ impl IGDManager { Some(socket.local_addr().ok()?.ip()) } + #[instrument(level = "trace", target = "net", skip_all)] fn find_local_ip(inner: &mut IGDManagerInner, address_type: AddressType, ) -> Option { @@ -109,6 +111,7 @@ impl IGDManager { Some(ip) } + #[instrument(level = "trace", target = "net", skip_all)] fn get_local_ip( inner: &mut IGDManagerInner, address_type: AddressType, @@ -119,6 +122,7 @@ impl IGDManager { None } + #[instrument(level = "trace", target = "net", skip_all)] fn find_gateway( inner: &mut IGDManagerInner, local_ip: IpAddr, @@ -165,6 +169,7 @@ impl IGDManager { Some(gw) } + #[instrument(level = "trace", target = "net", skip_all)] fn get_gateway( inner: &mut IGDManagerInner, local_ip: IpAddr, @@ -179,6 +184,7 @@ impl IGDManager { format!("{} map {} for port {}", self.config.get().program_name, convert_llpt(llpt), local_port ) } + #[instrument(level = "trace", target = "net", skip_all)] pub async fn unmap_port(&self, llpt: LowLevelProtocolType, at: AddressType, @@ -220,6 +226,7 @@ impl IGDManager { .await } + #[instrument(level = "trace", target = "net", skip_all)] pub async fn map_any_port( &self, llpt: LowLevelProtocolType, @@ -303,6 +310,7 @@ impl IGDManager { .await } + #[instrument(level = "trace", target = "net", skip_all, err)] pub async fn tick(&self) -> EyreResult { // Refresh mappings if we have them // If an error is received, then return false to restart the local network @@ -426,6 +434,6 @@ impl IGDManager { // Normal exit, no restart Ok(true) - }, Err(eyre!("failed to process blocking task"))).await + }, Err(eyre!("failed to process blocking task"))).in_current_span().await } } diff --git a/veilid-core/src/network_manager/native/mod.rs b/veilid-core/src/network_manager/native/mod.rs index 0b664f8e..b8bd9a92 100644 --- a/veilid-core/src/network_manager/native/mod.rs +++ b/veilid-core/src/network_manager/native/mod.rs @@ -976,10 +976,10 @@ impl Network { ////////////////////////////////////////// - #[instrument(level = "trace", skip(self), err)] + #[instrument(level = "trace", target = "net", skip_all, err)] pub async fn network_interfaces_task_routine( self, - stop_token: StopToken, + _stop_token: StopToken, _l: u64, _t: u64, ) -> EyreResult<()> { @@ -988,10 +988,10 @@ impl Network { Ok(()) } - #[instrument(level = "trace", skip(self), err)] + #[instrument(level = "trace", target = "net", skip_all, err)] pub async fn upnp_task_routine( self, - stop_token: StopToken, + _stop_token: StopToken, _l: u64, _t: u64, ) -> EyreResult<()> { @@ -1004,6 +1004,7 @@ impl Network { Ok(()) } + #[instrument(level = "trace", target = "net", skip_all, err)] pub async fn tick(&self) -> EyreResult<()> { let (detect_address_changes, upnp) = { let config = self.network_manager().config(); diff --git a/veilid-core/src/network_manager/network_connection.rs b/veilid-core/src/network_manager/network_connection.rs index e4ecbba6..d798de62 100644 --- a/veilid-core/src/network_manager/network_connection.rs +++ b/veilid-core/src/network_manager/network_connection.rs @@ -299,7 +299,7 @@ impl NetworkConnection { }; let timer = MutableFuture::new(new_timer()); - unord.push(system_boxed(timer.clone().instrument(Span::current()))); + unord.push(system_boxed(timer.clone().in_current_span())); loop { // Add another message sender future if necessary @@ -309,10 +309,6 @@ impl NetworkConnection { match res { Ok((_span_id, message)) => { - let recv_span = span!(Level::TRACE, "process_connection recv"); - // xxx: causes crash (Missing otel data span extensions) - // recv_span.follows_from(span_id); - // Touch the LRU for this connection connection_manager.touch_connection_by_id(connection_id); @@ -321,7 +317,7 @@ impl NetworkConnection { &protocol_connection, stats.clone(), message, - ).instrument(recv_span) + ).in_current_span() .await { // Sending the packet along can fail, if so, this connection is dead @@ -338,7 +334,7 @@ impl NetworkConnection { } } }); - unord.push(system_boxed(sender_fut.instrument(Span::current()))); + unord.push(system_boxed(sender_fut.in_current_span())); } // Add another message receiver future if necessary @@ -393,9 +389,9 @@ impl NetworkConnection { RecvLoopAction::Finish } } - }); + }.in_current_span()); - unord.push(system_boxed(receiver_fut.instrument(Span::current()))); + unord.push(system_boxed(receiver_fut.in_current_span())); } // Process futures @@ -445,7 +441,7 @@ impl NetworkConnection { log_net!(debug "Protocol connection close error: {}", e); } - }.instrument(trace_span!("process_connection"))) + }.in_current_span()) } pub fn debug_print(&self, cur_ts: Timestamp) -> String { diff --git a/veilid-core/src/network_manager/receipt_manager.rs b/veilid-core/src/network_manager/receipt_manager.rs index d510a56c..50109a6a 100644 --- a/veilid-core/src/network_manager/receipt_manager.rs +++ b/veilid-core/src/network_manager/receipt_manager.rs @@ -290,7 +290,11 @@ impl ReceiptManager { if now >= next_oldest_ts { // Single-spawn the timeout task routine let _ = timeout_task - .single_spawn(self.clone().timeout_task_routine(now, stop_token)) + .single_spawn( + self.clone() + .timeout_task_routine(now, stop_token) + .in_current_span(), + ) .await; } } diff --git a/veilid-core/src/network_manager/tasks/mod.rs b/veilid-core/src/network_manager/tasks/mod.rs index ebd47699..0556bdb6 100644 --- a/veilid-core/src/network_manager/tasks/mod.rs +++ b/veilid-core/src/network_manager/tasks/mod.rs @@ -11,14 +11,11 @@ impl NetworkManager { self.unlocked_inner .rolling_transfers_task .set_routine(move |s, l, t| { - Box::pin( - this.clone() - .rolling_transfers_task_routine(s, Timestamp::new(l), Timestamp::new(t)) - .instrument(trace_span!( - parent: None, - "NetworkManager rolling transfers task routine" - )), - ) + Box::pin(this.clone().rolling_transfers_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } @@ -28,18 +25,11 @@ impl NetworkManager { self.unlocked_inner .public_address_check_task .set_routine(move |s, l, t| { - Box::pin( - this.clone() - .public_address_check_task_routine( - s, - Timestamp::new(l), - Timestamp::new(t), - ) - .instrument(trace_span!( - parent: None, - "public address check task routine" - )), - ) + Box::pin(this.clone().public_address_check_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } @@ -49,11 +39,11 @@ impl NetworkManager { self.unlocked_inner .address_filter_task .set_routine(move |s, l, t| { - Box::pin( - this.address_filter() - .address_filter_task_routine(s, Timestamp::new(l), Timestamp::new(t)) - .instrument(trace_span!(parent: None, "address filter task routine")), - ) + Box::pin(this.address_filter().address_filter_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } } diff --git a/veilid-core/src/routing_table/mod.rs b/veilid-core/src/routing_table/mod.rs index 161f34f1..19c0d5e0 100644 --- a/veilid-core/src/routing_table/mod.rs +++ b/veilid-core/src/routing_table/mod.rs @@ -653,6 +653,7 @@ impl RoutingTable { } /// Resolve an existing routing table entry and return a filtered reference to it + #[instrument(level = "trace", skip_all)] pub fn lookup_and_filter_noderef( &self, node_id: TypedKey, @@ -670,6 +671,7 @@ impl RoutingTable { /// Shortcut function to add a node to our routing table if it doesn't exist /// and add the dial info we have for it. Returns a noderef filtered to /// the routing domain in which this node was registered for convenience. + #[instrument(level = "trace", skip_all, err)] pub fn register_node_with_peer_info( &self, routing_domain: RoutingDomain, @@ -686,6 +688,7 @@ impl RoutingTable { /// Shortcut function to add a node to our routing table if it doesn't exist /// and add the last peer address we have for it, since that's pretty common + #[instrument(level = "trace", skip_all, err)] pub fn register_node_with_existing_connection( &self, node_id: TypedKey, @@ -707,6 +710,7 @@ impl RoutingTable { self.inner.read().get_routing_table_health() } + #[instrument(level = "trace", skip_all)] pub fn get_recent_peers(&self) -> Vec<(TypedKey, RecentPeersEntry)> { let mut recent_peers = Vec::new(); let mut dead_peers = Vec::new(); diff --git a/veilid-core/src/routing_table/routing_table_inner.rs b/veilid-core/src/routing_table/routing_table_inner.rs index 265f65b2..90a068ec 100644 --- a/veilid-core/src/routing_table/routing_table_inner.rs +++ b/veilid-core/src/routing_table/routing_table_inner.rs @@ -627,6 +627,7 @@ impl RoutingTableInner { /// Create a node reference, possibly creating a bucket entry /// the 'update_func' closure is called on the node, and, if created, /// in a locked fashion as to ensure the bucket entry state is always valid + #[instrument(level = "trace", skip_all, err)] fn create_node_ref( &mut self, outer_self: RoutingTable, @@ -707,6 +708,7 @@ impl RoutingTableInner { } /// Resolve an existing routing table entry using any crypto kind and return a reference to it + #[instrument(level = "trace", skip_all, err)] pub fn lookup_any_node_ref( &self, outer_self: RoutingTable, @@ -723,6 +725,7 @@ impl RoutingTableInner { } /// Resolve an existing routing table entry and return a reference to it + #[instrument(level = "trace", skip_all, err)] pub fn lookup_node_ref( &self, outer_self: RoutingTable, @@ -743,6 +746,7 @@ impl RoutingTableInner { } /// Resolve an existing routing table entry and return a filtered reference to it + #[instrument(level = "trace", skip_all, err)] pub fn lookup_and_filter_noderef( &self, outer_self: RoutingTable, @@ -781,6 +785,7 @@ impl RoutingTableInner { /// Shortcut function to add a node to our routing table if it doesn't exist /// and add the dial info we have for it. Returns a noderef filtered to /// the routing domain in which this node was registered for convenience. + #[instrument(level = "trace", skip_all, err)] pub fn register_node_with_peer_info( &mut self, outer_self: RoutingTable, @@ -853,6 +858,7 @@ impl RoutingTableInner { /// Shortcut function to add a node to our routing table if it doesn't exist /// and add the last peer address we have for it, since that's pretty common + #[instrument(level = "trace", skip_all, err)] pub fn register_node_with_existing_connection( &mut self, outer_self: RoutingTable, @@ -933,6 +939,7 @@ impl RoutingTableInner { // Find Nodes // Retrieve the fastest nodes in the routing table matching an entry filter + #[instrument(level = "trace", skip_all)] pub fn find_fast_public_nodes_filtered( &self, outer_self: RoutingTable, @@ -965,6 +972,7 @@ impl RoutingTableInner { ) } + #[instrument(level = "trace", skip_all)] pub fn filter_has_valid_signed_node_info( &self, routing_domain: RoutingDomain, @@ -984,6 +992,7 @@ impl RoutingTableInner { } } + #[instrument(level = "trace", skip_all)] pub fn transform_to_peer_info( &self, routing_domain: RoutingDomain, @@ -996,6 +1005,7 @@ impl RoutingTableInner { } } + #[instrument(level = "trace", skip_all)] pub fn find_peers_with_sort_and_filter( &self, node_count: usize, @@ -1058,6 +1068,7 @@ impl RoutingTableInner { out } + #[instrument(level = "trace", skip_all)] pub fn find_preferred_fastest_nodes( &self, node_count: usize, @@ -1136,6 +1147,7 @@ impl RoutingTableInner { self.find_peers_with_sort_and_filter(node_count, cur_ts, filters, sort, transform) } + #[instrument(level = "trace", skip_all)] pub fn find_preferred_closest_nodes( &self, node_count: usize, @@ -1222,6 +1234,7 @@ impl RoutingTableInner { Ok(out) } + #[instrument(level = "trace", skip_all)] pub fn sort_and_clean_closest_noderefs( &self, node_id: TypedKey, @@ -1250,6 +1263,7 @@ impl RoutingTableInner { } } +#[instrument(level = "trace", skip_all)] pub(crate) fn make_closest_noderef_sort( crypto: Crypto, node_id: TypedKey, diff --git a/veilid-core/src/routing_table/tasks/mod.rs b/veilid-core/src/routing_table/tasks/mod.rs index b8e87121..1ebec50c 100644 --- a/veilid-core/src/routing_table/tasks/mod.rs +++ b/veilid-core/src/routing_table/tasks/mod.rs @@ -17,14 +17,11 @@ impl RoutingTable { self.unlocked_inner .rolling_transfers_task .set_routine(move |s, l, t| { - Box::pin( - this.clone() - .rolling_transfers_task_routine(s, Timestamp::new(l), Timestamp::new(t)) - .instrument(trace_span!( - parent: None, - "RoutingTable rolling transfers task routine" - )), - ) + Box::pin(this.clone().rolling_transfers_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } @@ -34,11 +31,11 @@ impl RoutingTable { self.unlocked_inner .kick_buckets_task .set_routine(move |s, l, t| { - Box::pin( - this.clone() - .kick_buckets_task_routine(s, Timestamp::new(l), Timestamp::new(t)) - .instrument(trace_span!(parent: None, "kick buckets task routine")), - ) + Box::pin(this.clone().kick_buckets_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } @@ -47,13 +44,7 @@ impl RoutingTable { let this = self.clone(); self.unlocked_inner .bootstrap_task - .set_routine(move |s, _l, _t| { - Box::pin( - this.clone() - .bootstrap_task_routine(s) - .instrument(trace_span!(parent: None, "bootstrap task routine")), - ) - }); + .set_routine(move |s, _l, _t| Box::pin(this.clone().bootstrap_task_routine(s))); } // Set peer minimum refresh tick task @@ -62,14 +53,7 @@ impl RoutingTable { self.unlocked_inner .peer_minimum_refresh_task .set_routine(move |s, _l, _t| { - Box::pin( - this.clone() - .peer_minimum_refresh_task_routine(s) - .instrument(trace_span!( - parent: None, - "peer minimum refresh task routine" - )), - ) + Box::pin(this.clone().peer_minimum_refresh_task_routine(s)) }); } @@ -79,14 +63,7 @@ impl RoutingTable { self.unlocked_inner .closest_peers_refresh_task .set_routine(move |s, _l, _t| { - Box::pin( - this.clone() - .closest_peers_refresh_task_routine(s) - .instrument(trace_span!( - parent: None, - "closest peers refresh task routine" - )), - ) + Box::pin(this.clone().closest_peers_refresh_task_routine(s)) }); } @@ -96,11 +73,11 @@ impl RoutingTable { self.unlocked_inner .ping_validator_task .set_routine(move |s, l, t| { - Box::pin( - this.clone() - .ping_validator_task_routine(s, Timestamp::new(l), Timestamp::new(t)) - .instrument(trace_span!(parent: None, "ping validator task routine")), - ) + Box::pin(this.clone().ping_validator_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } @@ -110,11 +87,11 @@ impl RoutingTable { self.unlocked_inner .relay_management_task .set_routine(move |s, l, t| { - Box::pin( - this.clone() - .relay_management_task_routine(s, Timestamp::new(l), Timestamp::new(t)) - .instrument(trace_span!(parent: None, "relay management task routine")), - ) + Box::pin(this.clone().relay_management_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } @@ -124,18 +101,11 @@ impl RoutingTable { self.unlocked_inner .private_route_management_task .set_routine(move |s, l, t| { - Box::pin( - this.clone() - .private_route_management_task_routine( - s, - Timestamp::new(l), - Timestamp::new(t), - ) - .instrument(trace_span!( - parent: None, - "private route management task routine" - )), - ) + Box::pin(this.clone().private_route_management_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } } diff --git a/veilid-core/src/routing_table/tasks/relay_management.rs b/veilid-core/src/routing_table/tasks/relay_management.rs index e753f519..1577d8bd 100644 --- a/veilid-core/src/routing_table/tasks/relay_management.rs +++ b/veilid-core/src/routing_table/tasks/relay_management.rs @@ -2,6 +2,7 @@ use super::*; impl RoutingTable { // Check if a relay is desired or not + #[instrument(level = "trace", skip_all)] fn public_internet_wants_relay(&self) -> Option { let own_peer_info = self.get_own_peer_info(RoutingDomain::PublicInternet); let own_node_info = own_peer_info.signed_node_info().node_info(); @@ -47,7 +48,7 @@ impl RoutingTable { } // Keep relays assigned and accessible - #[instrument(level = "trace", skip(self), err)] + #[instrument(level = "trace", skip_all, err)] pub(crate) async fn relay_management_task_routine( self, _stop_token: StopToken, @@ -145,6 +146,7 @@ impl RoutingTable { Ok(()) } + #[instrument(level = "trace", skip_all)] pub fn make_public_internet_relay_node_filter(&self) -> impl Fn(&BucketEntryInner) -> bool { // Get all our outbound protocol/address types let outbound_dif = self.get_outbound_dial_info_filter(RoutingDomain::PublicInternet); diff --git a/veilid-core/src/rpc_processor/mod.rs b/veilid-core/src/rpc_processor/mod.rs index 04d323d8..6c15b135 100644 --- a/veilid-core/src/rpc_processor/mod.rs +++ b/veilid-core/src/rpc_processor/mod.rs @@ -171,7 +171,7 @@ pub(crate) struct RPCMessage { opt_sender_nr: Option, } -#[instrument(skip_all, err)] +#[instrument(level="trace", target="rpc", skip_all, err)] pub fn builder_to_vec<'a, T>(builder: capnp::message::Builder) -> Result, RPCError> where T: capnp::message::Allocator + 'a, @@ -1669,13 +1669,13 @@ impl RPCProcessor { while let Ok(Ok((_span_id, msg))) = receiver.recv_async().timeout_at(stop_token.clone()).await { - let rpc_worker_span = span!(parent: None, Level::TRACE, "rpc_worker recv"); + //let rpc_worker_span = span!(parent: None, Level::TRACE, "rpc_worker recv"); // xxx: causes crash (Missing otel data span extensions) // rpc_worker_span.follows_from(span_id); network_result_value_or_log!(match self - .process_rpc_message(msg) - .instrument(rpc_worker_span) + .process_rpc_message(msg).in_current_span() + //.instrument(rpc_worker_span) .await { Err(e) => { diff --git a/veilid-core/src/storage_manager/get_value.rs b/veilid-core/src/storage_manager/get_value.rs index 2c4627f4..1f2a785a 100644 --- a/veilid-core/src/storage_manager/get_value.rs +++ b/veilid-core/src/storage_manager/get_value.rs @@ -182,7 +182,7 @@ impl StorageManager { log_network_result!(debug "GetValue fanout call returned peers {}", gva.answer.peers.len()); Ok(NetworkResult::value(gva.answer.peers)) - } + }.in_current_span() } }; @@ -271,7 +271,7 @@ impl StorageManager { })) { log_dht!(debug "Sending GetValue result failed: {}", e); } - })) + }.in_current_span())) .detach(); Ok(out_rx) @@ -319,7 +319,7 @@ impl StorageManager { // Return done false - }) + }.in_current_span()) }, ), ); diff --git a/veilid-core/src/storage_manager/inspect_value.rs b/veilid-core/src/storage_manager/inspect_value.rs index 77bb9292..1ec7761e 100644 --- a/veilid-core/src/storage_manager/inspect_value.rs +++ b/veilid-core/src/storage_manager/inspect_value.rs @@ -228,7 +228,7 @@ impl StorageManager { log_network_result!(debug "InspectValue fanout call returned peers {}", answer.peers.len()); Ok(NetworkResult::value(answer.peers)) - } + }.in_current_span() }; // Routine to call to check if we're done at each step diff --git a/veilid-core/src/storage_manager/set_value.rs b/veilid-core/src/storage_manager/set_value.rs index 0b293e77..7e343b80 100644 --- a/veilid-core/src/storage_manager/set_value.rs +++ b/veilid-core/src/storage_manager/set_value.rs @@ -177,7 +177,7 @@ impl StorageManager { ctx.send_partial_update = true; Ok(NetworkResult::value(sva.answer.peers)) - } + }.in_current_span() } }; @@ -267,7 +267,7 @@ impl StorageManager { })) { log_dht!(debug "Sending SetValue result failed: {}", e); } - })) + }.in_current_span())) .detach(); Ok(out_rx) @@ -329,7 +329,7 @@ impl StorageManager { // Return done false - }) + }.in_current_span()) }, ), ); diff --git a/veilid-core/src/storage_manager/tasks/mod.rs b/veilid-core/src/storage_manager/tasks/mod.rs index 3e5df9cb..dc580860 100644 --- a/veilid-core/src/storage_manager/tasks/mod.rs +++ b/veilid-core/src/storage_manager/tasks/mod.rs @@ -15,18 +15,11 @@ impl StorageManager { self.unlocked_inner .flush_record_stores_task .set_routine(move |s, l, t| { - Box::pin( - this.clone() - .flush_record_stores_task_routine( - s, - Timestamp::new(l), - Timestamp::new(t), - ) - .instrument(trace_span!( - parent: None, - "StorageManager flush record stores task routine" - )), - ) + Box::pin(this.clone().flush_record_stores_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } // Set offline subkey writes tick task @@ -36,18 +29,11 @@ impl StorageManager { self.unlocked_inner .offline_subkey_writes_task .set_routine(move |s, l, t| { - Box::pin( - this.clone() - .offline_subkey_writes_task_routine( - s, - Timestamp::new(l), - Timestamp::new(t), - ) - .instrument(trace_span!( - parent: None, - "StorageManager offline subkey writes task routine" - )), - ) + Box::pin(this.clone().offline_subkey_writes_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } // Set send value changes tick task @@ -57,18 +43,11 @@ impl StorageManager { self.unlocked_inner .send_value_changes_task .set_routine(move |s, l, t| { - Box::pin( - this.clone() - .send_value_changes_task_routine( - s, - Timestamp::new(l), - Timestamp::new(t), - ) - .instrument(trace_span!( - parent: None, - "StorageManager send value changes task routine" - )), - ) + Box::pin(this.clone().send_value_changes_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } // Set check active watches tick task @@ -78,18 +57,11 @@ impl StorageManager { self.unlocked_inner .check_active_watches_task .set_routine(move |s, l, t| { - Box::pin( - this.clone() - .check_active_watches_task_routine( - s, - Timestamp::new(l), - Timestamp::new(t), - ) - .instrument(trace_span!( - parent: None, - "StorageManager check active watches task routine" - )), - ) + Box::pin(this.clone().check_active_watches_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } // Set check watched records tick task @@ -99,18 +71,11 @@ impl StorageManager { self.unlocked_inner .check_watched_records_task .set_routine(move |s, l, t| { - Box::pin( - this.clone() - .check_watched_records_task_routine( - s, - Timestamp::new(l), - Timestamp::new(t), - ) - .instrument(trace_span!( - parent: None, - "StorageManager check watched records task routine" - )), - ) + Box::pin(this.clone().check_watched_records_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + )) }); } } diff --git a/veilid-core/src/storage_manager/watch_value.rs b/veilid-core/src/storage_manager/watch_value.rs index 1e94be85..628f5b1f 100644 --- a/veilid-core/src/storage_manager/watch_value.rs +++ b/veilid-core/src/storage_manager/watch_value.rs @@ -294,7 +294,7 @@ impl StorageManager { log_network_result!(debug "WatchValue fanout call returned peers {} ({})", wva.answer.peers.len(), next_node); Ok(NetworkResult::value(wva.answer.peers)) - } + }.in_current_span() }; // Routine to call to check if we're done at each step @@ -408,6 +408,7 @@ impl StorageManager { } /// Handle a received 'Value Changed' statement + #[instrument(level = "trace", target = "dht", skip_all)] pub async fn inbound_value_changed( &self, key: TypedKey, diff --git a/veilid-flutter/rust/src/dart_ffi.rs b/veilid-flutter/rust/src/dart_ffi.rs index 5ef8d69f..df6371c6 100644 --- a/veilid-flutter/rust/src/dart_ffi.rs +++ b/veilid-flutter/rust/src/dart_ffi.rs @@ -319,12 +319,17 @@ pub extern "C" fn initialize_veilid_core(platform_config: FfiStr) { // Flamegraph logger if platform_config.logging.flame.enabled { - let filter = - veilid_core::VeilidLayerFilter::new(veilid_core::VeilidConfigLogLevel::Trace, &[]); + let filter = veilid_core::VeilidLayerFilter::new_no_default( + veilid_core::VeilidConfigLogLevel::Trace, + &veilid_core::FLAME_LOG_FACILITIES_IGNORE_LIST.map(|x| x.to_string()), + ); let (flame_layer, guard) = FlameLayer::with_file(&platform_config.logging.flame.path).unwrap(); *FLAME_GUARD.lock() = Some(guard); - filters.insert("flame", filter.clone()); + + // Do not include this in change_log_level changes, so we keep trace level + // filters.insert("flame", filter.clone()); + layers.push( flame_layer .with_threads_collapsed(true) @@ -408,82 +413,100 @@ pub extern "C" fn change_log_ignore(layer: FfiStr, log_ignore: FfiStr) { } #[no_mangle] -#[instrument] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn startup_veilid_core(port: i64, stream_port: i64, config: FfiStr) { let config = config.into_opt_string(); let stream = DartIsolateStream::new(stream_port); - DartIsolateWrapper::new(port).spawn_result(async move { - let config_json = match config { - Some(v) => v, - None => { - let err = veilid_core::VeilidAPIError::MissingArgument { - context: "startup_veilid_core".to_owned(), - argument: "config".to_owned(), - }; - return APIResult::Err(err); - } - }; + DartIsolateWrapper::new(port).spawn_result( + async move { + let config_json = match config { + Some(v) => v, + None => { + let err = veilid_core::VeilidAPIError::MissingArgument { + context: "startup_veilid_core".to_owned(), + argument: "config".to_owned(), + }; + return APIResult::Err(err); + } + }; - let mut api_lock = VEILID_API.lock().await; - if api_lock.is_some() { - return APIResult::Err(veilid_core::VeilidAPIError::AlreadyInitialized); + let mut api_lock = VEILID_API.lock().await; + if api_lock.is_some() { + return APIResult::Err(veilid_core::VeilidAPIError::AlreadyInitialized); + } + + let sink = stream.clone(); + let update_callback = Arc::new(move |update: veilid_core::VeilidUpdate| { + let sink = sink.clone(); + match update { + veilid_core::VeilidUpdate::Shutdown => { + sink.close(); + } + _ => { + sink.item_json(update); + } + } + }); + + let veilid_api = veilid_core::api_startup_json(update_callback, config_json).await?; + *api_lock = Some(veilid_api); + + APIRESULT_VOID } - - let sink = stream.clone(); - let update_callback = Arc::new(move |update: veilid_core::VeilidUpdate| { - let sink = sink.clone(); - match update { - veilid_core::VeilidUpdate::Shutdown => { - sink.close(); - } - _ => { - sink.item_json(update); - } - } - }); - - let veilid_api = veilid_core::api_startup_json(update_callback, config_json).await?; - *api_lock = Some(veilid_api); - - APIRESULT_VOID - }); + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn get_veilid_state(port: i64) { - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let core_state = veilid_api.get_state().await?; - APIResult::Ok(core_state) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let core_state = veilid_api.get_state().await?; + APIResult::Ok(core_state) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn attach(port: i64) { - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - veilid_api.attach().await?; - APIRESULT_VOID - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + veilid_api.attach().await?; + APIRESULT_VOID + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn detach(port: i64) { - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - veilid_api.detach().await?; - APIRESULT_VOID - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + veilid_api.detach().await?; + APIRESULT_VOID + } + .in_current_span(), + ); } #[no_mangle] -#[instrument] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn shutdown_veilid_core(port: i64) { - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = take_veilid_api().await?; - veilid_api.shutdown().await; - APIRESULT_VOID - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = take_veilid_api().await?; + veilid_api.shutdown().await; + APIRESULT_VOID + } + .in_current_span(), + ); } fn add_routing_context( @@ -499,17 +522,22 @@ fn add_routing_context( } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context(port: i64) { - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let routing_context = veilid_api.routing_context()?; - let mut rc = ROUTING_CONTEXTS.lock(); - let new_id = add_routing_context(&mut rc, routing_context); - APIResult::Ok(new_id) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let routing_context = veilid_api.routing_context()?; + let mut rc = ROUTING_CONTEXTS.lock(); + let new_id = add_routing_context(&mut rc, routing_context); + APIResult::Ok(new_id) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn release_routing_context(id: u32) -> i32 { let mut rc = ROUTING_CONTEXTS.lock(); if rc.remove(&id).is_none() { @@ -519,6 +547,7 @@ pub extern "C" fn release_routing_context(id: u32) -> i32 { } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_with_default_safety(id: u32) -> u32 { let mut rc = ROUTING_CONTEXTS.lock(); let Some(routing_context) = rc.get(&id) else { @@ -532,6 +561,7 @@ pub extern "C" fn routing_context_with_default_safety(id: u32) -> u32 { } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_with_safety(id: u32, safety_selection: FfiStr) -> u32 { let safety_selection: veilid_core::SafetySelection = veilid_core::deserialize_opt_json(safety_selection.into_opt_string()).unwrap(); @@ -548,6 +578,7 @@ pub extern "C" fn routing_context_with_safety(id: u32, safety_selection: FfiStr) } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_with_sequencing(id: u32, sequencing: FfiStr) -> u32 { let sequencing: veilid_core::Sequencing = veilid_core::deserialize_opt_json(sequencing.into_opt_string()).unwrap(); @@ -572,46 +603,57 @@ fn get_routing_context(id: u32, func_name: &str) -> APIResult = data_encoding::BASE64URL_NOPAD .decode(request.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let routing_context = get_routing_context(id, "routing_context_app_call")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let routing_context = get_routing_context(id, "routing_context_app_call")?; - let veilid_api = get_veilid_api().await?; - let target = veilid_api.parse_as_target(target_string)?; - let answer = routing_context.app_call(target, request).await?; - let answer = data_encoding::BASE64URL_NOPAD.encode(&answer); - APIResult::Ok(answer) - }); + let veilid_api = get_veilid_api().await?; + let target = veilid_api.parse_as_target(target_string)?; + let answer = routing_context.app_call(target, request).await?; + let answer = data_encoding::BASE64URL_NOPAD.encode(&answer); + APIResult::Ok(answer) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_app_message(port: i64, id: u32, target: FfiStr, message: FfiStr) { let target_string: String = target.into_opt_string().unwrap(); let message: Vec = data_encoding::BASE64URL_NOPAD .decode(message.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let routing_context = get_routing_context(id, "routing_context_app_message")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let routing_context = get_routing_context(id, "routing_context_app_message")?; - let veilid_api = get_veilid_api().await?; - let target = veilid_api.parse_as_target(target_string)?; - routing_context.app_message(target, message).await?; - APIRESULT_VOID - }); + let veilid_api = get_veilid_api().await?; + let target = veilid_api.parse_as_target(target_string)?; + routing_context.app_message(target, message).await?; + APIRESULT_VOID + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_create_dht_record(port: i64, id: u32, schema: FfiStr, kind: u32) { let crypto_kind = if kind == 0 { None @@ -621,56 +663,72 @@ pub extern "C" fn routing_context_create_dht_record(port: i64, id: u32, schema: let schema: veilid_core::DHTSchema = veilid_core::deserialize_opt_json(schema.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let routing_context = get_routing_context(id, "routing_context_create_dht_record")?; + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let routing_context = get_routing_context(id, "routing_context_create_dht_record")?; - let dht_record_descriptor = routing_context - .create_dht_record(schema, crypto_kind) - .await?; - APIResult::Ok(dht_record_descriptor) - }); + let dht_record_descriptor = routing_context + .create_dht_record(schema, crypto_kind) + .await?; + APIResult::Ok(dht_record_descriptor) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_open_dht_record(port: i64, id: u32, key: FfiStr, writer: FfiStr) { let key: veilid_core::TypedKey = veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap(); let writer: Option = writer .into_opt_string() .map(|s| veilid_core::deserialize_json(&s).unwrap()); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let routing_context = get_routing_context(id, "routing_context_open_dht_record")?; + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let routing_context = get_routing_context(id, "routing_context_open_dht_record")?; - let dht_record_descriptor = routing_context.open_dht_record(key, writer).await?; - APIResult::Ok(dht_record_descriptor) - }); + let dht_record_descriptor = routing_context.open_dht_record(key, writer).await?; + APIResult::Ok(dht_record_descriptor) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_close_dht_record(port: i64, id: u32, key: FfiStr) { let key: veilid_core::TypedKey = veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let routing_context = get_routing_context(id, "routing_context_close_dht_record")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let routing_context = get_routing_context(id, "routing_context_close_dht_record")?; - routing_context.close_dht_record(key).await?; - APIRESULT_VOID - }); + routing_context.close_dht_record(key).await?; + APIRESULT_VOID + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_delete_dht_record(port: i64, id: u32, key: FfiStr) { let key: veilid_core::TypedKey = veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let routing_context = get_routing_context(id, "routing_context_delete_dht_record")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let routing_context = get_routing_context(id, "routing_context_delete_dht_record")?; - routing_context.delete_dht_record(key).await?; - APIRESULT_VOID - }); + routing_context.delete_dht_record(key).await?; + APIRESULT_VOID + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_get_dht_value( port: i64, id: u32, @@ -680,17 +738,21 @@ pub extern "C" fn routing_context_get_dht_value( ) { let key: veilid_core::TypedKey = veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let routing_context = get_routing_context(id, "routing_context_get_dht_value")?; + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let routing_context = get_routing_context(id, "routing_context_get_dht_value")?; - let res = routing_context - .get_dht_value(key, subkey, force_refresh) - .await?; - APIResult::Ok(res) - }); + let res = routing_context + .get_dht_value(key, subkey, force_refresh) + .await?; + APIResult::Ok(res) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_set_dht_value( port: i64, id: u32, @@ -708,17 +770,21 @@ pub extern "C" fn routing_context_set_dht_value( .into_opt_string() .map(|s| veilid_core::deserialize_json(&s).unwrap()); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let routing_context = get_routing_context(id, "routing_context_set_dht_value")?; + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let routing_context = get_routing_context(id, "routing_context_set_dht_value")?; - let res = routing_context - .set_dht_value(key, subkey, data, writer) - .await?; - APIResult::Ok(res) - }); + let res = routing_context + .set_dht_value(key, subkey, data, writer) + .await?; + APIResult::Ok(res) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_watch_dht_values( port: i64, id: u32, @@ -733,17 +799,21 @@ pub extern "C" fn routing_context_watch_dht_values( veilid_core::deserialize_opt_json(subkeys.into_opt_string()).unwrap(); let expiration = veilid_core::Timestamp::from(expiration); - DartIsolateWrapper::new(port).spawn_result(async move { - let routing_context = get_routing_context(id, "routing_context_watch_dht_values")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let routing_context = get_routing_context(id, "routing_context_watch_dht_values")?; - let res = routing_context - .watch_dht_values(key, subkeys, expiration, count) - .await?; - APIResult::Ok(res.as_u64()) - }); + let res = routing_context + .watch_dht_values(key, subkeys, expiration, count) + .await?; + APIResult::Ok(res.as_u64()) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_cancel_dht_watch( port: i64, id: u32, @@ -755,15 +825,19 @@ pub extern "C" fn routing_context_cancel_dht_watch( let subkeys: veilid_core::ValueSubkeyRangeSet = veilid_core::deserialize_opt_json(subkeys.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let routing_context = get_routing_context(id, "routing_context_cancel_dht_watch")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let routing_context = get_routing_context(id, "routing_context_cancel_dht_watch")?; - let res = routing_context.cancel_dht_watch(key, subkeys).await?; - APIResult::Ok(res) - }); + let res = routing_context.cancel_dht_watch(key, subkeys).await?; + APIResult::Ok(res) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn routing_context_inspect_dht_record( port: i64, id: u32, @@ -778,94 +852,117 @@ pub extern "C" fn routing_context_inspect_dht_record( let scope: veilid_core::DHTReportScope = veilid_core::deserialize_opt_json(scope.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let routing_context = get_routing_context(id, "routing_context_inspect_dht_record")?; + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let routing_context = get_routing_context(id, "routing_context_inspect_dht_record")?; - let res = routing_context - .inspect_dht_record(key, subkeys, scope) - .await?; - APIResult::Ok(res) - }); + let res = routing_context + .inspect_dht_record(key, subkeys, scope) + .await?; + APIResult::Ok(res) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn new_private_route(port: i64) { - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; - let (route_id, blob) = veilid_api.new_private_route().await?; + let (route_id, blob) = veilid_api.new_private_route().await?; - let route_blob = VeilidFFIRouteBlob { route_id, blob }; + let route_blob = VeilidFFIRouteBlob { route_id, blob }; - APIResult::Ok(route_blob) - }); + APIResult::Ok(route_blob) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn new_custom_private_route(port: i64, stability: FfiStr, sequencing: FfiStr) { let stability: veilid_core::Stability = veilid_core::deserialize_opt_json(stability.into_opt_string()).unwrap(); let sequencing: veilid_core::Sequencing = veilid_core::deserialize_opt_json(sequencing.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; - let (route_id, blob) = veilid_api - .new_custom_private_route(&veilid_core::VALID_CRYPTO_KINDS, stability, sequencing) - .await?; + let (route_id, blob) = veilid_api + .new_custom_private_route(&veilid_core::VALID_CRYPTO_KINDS, stability, sequencing) + .await?; - let route_blob = VeilidFFIRouteBlob { route_id, blob }; + let route_blob = VeilidFFIRouteBlob { route_id, blob }; - APIResult::Ok(route_blob) - }); + APIResult::Ok(route_blob) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn import_remote_private_route(port: i64, blob: FfiStr) { let blob: Vec = data_encoding::BASE64URL_NOPAD .decode(blob.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; - let route_id = veilid_api.import_remote_private_route(blob)?.encode(); + let route_id = veilid_api.import_remote_private_route(blob)?.encode(); - APIResult::Ok(route_id) - }); + APIResult::Ok(route_id) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn release_private_route(port: i64, route_id: FfiStr) { let route_id = veilid_core::RouteId::try_decode(route_id.into_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - veilid_api.release_private_route(route_id)?; - APIRESULT_VOID - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + veilid_api.release_private_route(route_id)?; + APIRESULT_VOID + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn app_call_reply(port: i64, call_id: FfiStr, message: FfiStr) { let call_id = call_id.into_opt_string().unwrap_or_default(); let message = data_encoding::BASE64URL_NOPAD .decode(message.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let call_id = match call_id.parse() { - Ok(v) => v, - Err(e) => { - return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument( - e, "call_id", call_id, - )) - } - }; + DartIsolateWrapper::new(port).spawn_result( + async move { + let call_id = match call_id.parse() { + Ok(v) => v, + Err(e) => { + return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument( + e, "call_id", call_id, + )) + } + }; - let veilid_api = get_veilid_api().await?; - veilid_api.app_call_reply(call_id, message).await?; - APIRESULT_VOID - }); + let veilid_api = get_veilid_api().await?; + veilid_api.app_call_reply(call_id, message).await?; + APIRESULT_VOID + } + .in_current_span(), + ); } fn add_table_db(table_db: veilid_core::TableDB) -> u32 { @@ -879,21 +976,26 @@ fn add_table_db(table_db: veilid_core::TableDB) -> u32 { } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn open_table_db(port: i64, name: FfiStr, column_count: u32) { let name = name.into_opt_string().unwrap_or_default(); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let tstore = veilid_api.table_store()?; - let table_db = tstore - .open(&name, column_count) - .await - .map_err(veilid_core::VeilidAPIError::generic)?; - let new_id = add_table_db(table_db); - APIResult::Ok(new_id) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let tstore = veilid_api.table_store()?; + let table_db = tstore + .open(&name, column_count) + .await + .map_err(veilid_core::VeilidAPIError::generic)?; + let new_id = add_table_db(table_db); + APIResult::Ok(new_id) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn release_table_db(id: u32) -> i32 { let mut rc = TABLE_DBS.lock(); if rc.remove(&id).is_none() { @@ -903,20 +1005,25 @@ pub extern "C" fn release_table_db(id: u32) -> i32 { } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn delete_table_db(port: i64, name: FfiStr) { let name = name.into_opt_string().unwrap_or_default(); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let tstore = veilid_api.table_store()?; - let deleted = tstore - .delete(&name) - .await - .map_err(veilid_core::VeilidAPIError::generic)?; - APIResult::Ok(deleted) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let tstore = veilid_api.table_store()?; + let deleted = tstore + .delete(&name) + .await + .map_err(veilid_core::VeilidAPIError::generic)?; + APIResult::Ok(deleted) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn table_db_get_column_count(id: u32) -> u32 { let table_dbs = TABLE_DBS.lock(); let Some(table_db) = table_dbs.get(&id) else { @@ -939,17 +1046,21 @@ fn get_table_db(id: u32, func_name: &str) -> APIResult { } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn table_db_get_keys(port: i64, id: u32, col: u32) { - DartIsolateWrapper::new(port).spawn_result_json(async move { - let table_db = get_table_db(id, "table_db_get_keys")?; + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let table_db = get_table_db(id, "table_db_get_keys")?; - let keys = table_db.get_keys(col).await?; - let out: Vec = keys - .into_iter() - .map(|k| BASE64URL_NOPAD.encode(&k)) - .collect(); - APIResult::Ok(out) - }); + let keys = table_db.get_keys(col).await?; + let out: Vec = keys + .into_iter() + .map(|k| BASE64URL_NOPAD.encode(&k)) + .collect(); + APIResult::Ok(out) + } + .in_current_span(), + ); } fn add_table_db_transaction(tdbt: veilid_core::TableDBTransaction) -> u32 { @@ -963,6 +1074,7 @@ fn add_table_db_transaction(tdbt: veilid_core::TableDBTransaction) -> u32 { } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn table_db_transact(id: u32) -> u32 { let table_dbs = TABLE_DBS.lock(); let Some(table_db) = table_dbs.get(&id) else { @@ -974,6 +1086,7 @@ pub extern "C" fn table_db_transact(id: u32) -> u32 { } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn release_table_db_transaction(id: u32) -> i32 { let mut tdbts = TABLE_DB_TRANSACTIONS.lock(); if tdbts.remove(&id).is_none() { @@ -996,25 +1109,34 @@ fn get_table_db_transaction( } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn table_db_transaction_commit(port: i64, id: u32) { - DartIsolateWrapper::new(port).spawn_result(async move { - let tdbt = get_table_db_transaction(id, "table_db_transaction_commit")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let tdbt = get_table_db_transaction(id, "table_db_transaction_commit")?; - tdbt.commit().await?; - APIRESULT_VOID - }); + tdbt.commit().await?; + APIRESULT_VOID + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn table_db_transaction_rollback(port: i64, id: u32) { - DartIsolateWrapper::new(port).spawn_result(async move { - let tdbt = get_table_db_transaction(id, "table_db_transaction_rollback")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let tdbt = get_table_db_transaction(id, "table_db_transaction_rollback")?; - tdbt.rollback(); - APIRESULT_VOID - }); + tdbt.rollback(); + APIRESULT_VOID + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn table_db_transaction_store( port: i64, id: u32, @@ -1028,28 +1150,36 @@ pub extern "C" fn table_db_transaction_store( let value: Vec = data_encoding::BASE64URL_NOPAD .decode(value.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let tdbt = get_table_db_transaction(id, "table_db_transaction_store")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let tdbt = get_table_db_transaction(id, "table_db_transaction_store")?; - tdbt.store(col, &key, &value)?; - APIRESULT_VOID - }); + tdbt.store(col, &key, &value)?; + APIRESULT_VOID + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn table_db_transaction_delete(port: i64, id: u32, col: u32, key: FfiStr) { let key: Vec = data_encoding::BASE64URL_NOPAD .decode(key.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let tdbt = get_table_db_transaction(id, "table_db_transaction_delete")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let tdbt = get_table_db_transaction(id, "table_db_transaction_delete")?; - tdbt.delete(col, &key)?; - APIRESULT_VOID - }); + tdbt.delete(col, &key)?; + APIRESULT_VOID + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn table_db_store(port: i64, id: u32, col: u32, key: FfiStr, value: FfiStr) { let key: Vec = data_encoding::BASE64URL_NOPAD .decode(key.into_opt_string().unwrap().as_bytes()) @@ -1057,43 +1187,55 @@ pub extern "C" fn table_db_store(port: i64, id: u32, col: u32, key: FfiStr, valu let value: Vec = data_encoding::BASE64URL_NOPAD .decode(value.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let table_db = get_table_db(id, "table_db_store")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let table_db = get_table_db(id, "table_db_store")?; - table_db.store(col, &key, &value).await?; - APIRESULT_VOID - }); + table_db.store(col, &key, &value).await?; + APIRESULT_VOID + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn table_db_load(port: i64, id: u32, col: u32, key: FfiStr) { let key: Vec = data_encoding::BASE64URL_NOPAD .decode(key.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let table_db = get_table_db(id, "table_db_load")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let table_db = get_table_db(id, "table_db_load")?; - let out = table_db.load(col, &key).await?; - let out = out.map(|x| data_encoding::BASE64URL_NOPAD.encode(&x)); - APIResult::Ok(out) - }); + let out = table_db.load(col, &key).await?; + let out = out.map(|x| data_encoding::BASE64URL_NOPAD.encode(&x)); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn table_db_delete(port: i64, id: u32, col: u32, key: FfiStr) { let key: Vec = data_encoding::BASE64URL_NOPAD .decode(key.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let table_db = get_table_db(id, "table_db_delete")?; + DartIsolateWrapper::new(port).spawn_result( + async move { + let table_db = get_table_db(id, "table_db_delete")?; - let out = table_db.delete(col, &key).await?; - let out = out.map(|x| data_encoding::BASE64URL_NOPAD.encode(&x)); - APIResult::Ok(out) - }); + let out = table_db.delete(col, &key).await?; + let out = out.map(|x| data_encoding::BASE64URL_NOPAD.encode(&x)); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn valid_crypto_kinds() -> *mut c_char { veilid_core::serialize_json( veilid_core::VALID_CRYPTO_KINDS @@ -1105,11 +1247,13 @@ pub extern "C" fn valid_crypto_kinds() -> *mut c_char { } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn best_crypto_kind() -> u32 { veilid_core::best_crypto_kind().into() } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn verify_signatures(port: i64, node_ids: FfiStr, data: FfiStr, signatures: FfiStr) { let node_ids: Vec = veilid_core::deserialize_opt_json(node_ids.into_opt_string()).unwrap(); @@ -1121,15 +1265,19 @@ pub extern "C" fn verify_signatures(port: i64, node_ids: FfiStr, data: FfiStr, s let typed_signatures: Vec = veilid_core::deserialize_opt_json(signatures.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let out = crypto.verify_signatures(&node_ids, &data, &typed_signatures)?; - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let out = crypto.verify_signatures(&node_ids, &data, &typed_signatures)?; + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn generate_signatures(port: i64, data: FfiStr, key_pairs: FfiStr) { let data: Vec = data_encoding::BASE64URL_NOPAD .decode(data.into_opt_string().unwrap().as_bytes()) @@ -1138,24 +1286,31 @@ pub extern "C" fn generate_signatures(port: i64, data: FfiStr, key_pairs: FfiStr let key_pairs: Vec = veilid_core::deserialize_opt_json(key_pairs.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let out = crypto.generate_signatures(&data, &key_pairs, |k, s| { - veilid_core::TypedSignature::new(k.kind, s) - })?; - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let out = crypto.generate_signatures(&data, &key_pairs, |k, s| { + veilid_core::TypedSignature::new(k.kind, s) + })?; + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn generate_key_pair(port: i64, kind: u32) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let out = veilid_core::Crypto::generate_keypair(kind)?; - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let out = veilid_core::Crypto::generate_keypair(kind)?; + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] @@ -1167,22 +1322,26 @@ pub extern "C" fn crypto_cached_dh(port: i64, kind: u32, key: FfiStr, secret: Ff let secret: veilid_core::SecretKey = veilid_core::deserialize_opt_json(secret.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_cached_dh", - "kind", - kind.to_string(), - ) - })?; - let out = csv.cached_dh(&key, &secret)?; - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_cached_dh", + "kind", + kind.to_string(), + ) + })?; + let out = csv.cached_dh(&key, &secret)?; + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_compute_dh(port: i64, kind: u32, key: FfiStr, secret: FfiStr) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); @@ -1191,22 +1350,26 @@ pub extern "C" fn crypto_compute_dh(port: i64, kind: u32, key: FfiStr, secret: F let secret: veilid_core::SecretKey = veilid_core::deserialize_opt_json(secret.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_compute_dh", - "kind", - kind.to_string(), - ) - })?; - let out = csv.compute_dh(&key, &secret)?; - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_compute_dh", + "kind", + kind.to_string(), + ) + })?; + let out = csv.compute_dh(&key, &secret)?; + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_generate_shared_secret( port: i64, kind: u32, @@ -1224,61 +1387,73 @@ pub extern "C" fn crypto_generate_shared_secret( .decode(domain.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_generate_shared_secret", - "kind", - kind.to_string(), - ) - })?; - let out = csv.generate_shared_secret(&key, &secret, &domain)?; - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_generate_shared_secret", + "kind", + kind.to_string(), + ) + })?; + let out = csv.generate_shared_secret(&key, &secret, &domain)?; + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_random_bytes(port: i64, kind: u32, len: u32) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_random_bytes", - "kind", - kind.to_string(), - ) - })?; - let out = csv.random_bytes(len); - let out = data_encoding::BASE64URL_NOPAD.encode(&out); - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_random_bytes", + "kind", + kind.to_string(), + ) + })?; + let out = csv.random_bytes(len); + let out = data_encoding::BASE64URL_NOPAD.encode(&out); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_default_salt_length(port: i64, kind: u32) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_default_salt_length", - "kind", - kind.to_string(), - ) - })?; - let out = csv.default_salt_length(); - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_default_salt_length", + "kind", + kind.to_string(), + ) + })?; + let out = csv.default_salt_length(); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_hash_password(port: i64, kind: u32, password: FfiStr, salt: FfiStr) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); let password: Vec = data_encoding::BASE64URL_NOPAD @@ -1288,22 +1463,26 @@ pub extern "C" fn crypto_hash_password(port: i64, kind: u32, password: FfiStr, s .decode(salt.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_hash_password", - "kind", - kind.to_string(), - ) - })?; - let out = csv.hash_password(&password, &salt)?; - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_hash_password", + "kind", + kind.to_string(), + ) + })?; + let out = csv.hash_password(&password, &salt)?; + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_verify_password( port: i64, kind: u32, @@ -1316,22 +1495,26 @@ pub extern "C" fn crypto_verify_password( .unwrap(); let password_hash = password_hash.into_opt_string().unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_verify_password", - "kind", - kind.to_string(), - ) - })?; - let out = csv.verify_password(&password, &password_hash)?; - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_verify_password", + "kind", + kind.to_string(), + ) + })?; + let out = csv.verify_password(&password, &password_hash)?; + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_derive_shared_secret( port: i64, kind: u32, @@ -1346,79 +1529,95 @@ pub extern "C" fn crypto_derive_shared_secret( .decode(salt.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_derive_shared_secret", - "kind", - kind.to_string(), - ) - })?; - let out = csv.derive_shared_secret(&password, &salt)?; - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_derive_shared_secret", + "kind", + kind.to_string(), + ) + })?; + let out = csv.derive_shared_secret(&password, &salt)?; + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_random_nonce(port: i64, kind: u32) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_random_nonce", - "kind", - kind.to_string(), - ) - })?; - let out = csv.random_nonce(); - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_random_nonce", + "kind", + kind.to_string(), + ) + })?; + let out = csv.random_nonce(); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_random_shared_secret(port: i64, kind: u32) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_random_shared_secret", - "kind", - kind.to_string(), - ) - })?; - let out = csv.random_shared_secret(); - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_random_shared_secret", + "kind", + kind.to_string(), + ) + })?; + let out = csv.random_shared_secret(); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_generate_key_pair(port: i64, kind: u32) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_generate_key_pair", - "kind", - kind.to_string(), - ) - })?; - let out = csv.generate_keypair(); - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_generate_key_pair", + "kind", + kind.to_string(), + ) + })?; + let out = csv.generate_keypair(); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_generate_hash(port: i64, kind: u32, data: FfiStr) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); @@ -1426,22 +1625,26 @@ pub extern "C" fn crypto_generate_hash(port: i64, kind: u32, data: FfiStr) { .decode(data.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_generate_hash", - "kind", - kind.to_string(), - ) - })?; - let out = csv.generate_hash(&data); - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_generate_hash", + "kind", + kind.to_string(), + ) + })?; + let out = csv.generate_hash(&data); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_validate_key_pair(port: i64, kind: u32, key: FfiStr, secret: FfiStr) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); @@ -1450,22 +1653,26 @@ pub extern "C" fn crypto_validate_key_pair(port: i64, kind: u32, key: FfiStr, se let secret: veilid_core::SecretKey = veilid_core::deserialize_opt_json(secret.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_validate_key_pair", - "kind", - kind.to_string(), - ) - })?; - let out = csv.validate_keypair(&key, &secret); - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_validate_key_pair", + "kind", + kind.to_string(), + ) + })?; + let out = csv.validate_keypair(&key, &secret); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_validate_hash(port: i64, kind: u32, data: FfiStr, hash: FfiStr) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); @@ -1476,22 +1683,26 @@ pub extern "C" fn crypto_validate_hash(port: i64, kind: u32, data: FfiStr, hash: let hash: veilid_core::HashDigest = veilid_core::deserialize_opt_json(hash.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_validate_hash", - "kind", - kind.to_string(), - ) - })?; - let out = csv.validate_hash(&data, &hash); - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_validate_hash", + "kind", + kind.to_string(), + ) + })?; + let out = csv.validate_hash(&data, &hash); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_distance(port: i64, kind: u32, key1: FfiStr, key2: FfiStr) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); @@ -1500,22 +1711,26 @@ pub extern "C" fn crypto_distance(port: i64, kind: u32, key1: FfiStr, key2: FfiS let key2: veilid_core::CryptoKey = veilid_core::deserialize_opt_json(key2.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_distance", - "kind", - kind.to_string(), - ) - })?; - let out = csv.distance(&key1, &key2); - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_distance", + "kind", + kind.to_string(), + ) + })?; + let out = csv.distance(&key1, &key2); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_sign(port: i64, kind: u32, key: FfiStr, secret: FfiStr, data: FfiStr) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); @@ -1527,18 +1742,26 @@ pub extern "C" fn crypto_sign(port: i64, kind: u32, key: FfiStr, secret: FfiStr, .decode(data.into_opt_string().unwrap().as_bytes()) .unwrap(); - DartIsolateWrapper::new(port).spawn_result_json(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument("crypto_sign", "kind", kind.to_string()) - })?; - let out = csv.sign(&key, &secret, &data)?; - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result_json( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_sign", + "kind", + kind.to_string(), + ) + })?; + let out = csv.sign(&key, &secret, &data)?; + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_verify( port: i64, kind: u32, @@ -1556,37 +1779,49 @@ pub extern "C" fn crypto_verify( let signature: veilid_core::Signature = veilid_core::deserialize_opt_json(signature.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument("crypto_verify", "kind", kind.to_string()) - })?; - let out = csv.verify(&key, &data, &signature)?; - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_verify", + "kind", + kind.to_string(), + ) + })?; + let out = csv.verify(&key, &data, &signature)?; + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_aead_overhead(port: i64, kind: u32) { let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_aead_overhead", - "kind", - kind.to_string(), - ) - })?; - let out = csv.aead_overhead(); - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_aead_overhead", + "kind", + kind.to_string(), + ) + })?; + let out = csv.aead_overhead(); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_decrypt_aead( port: i64, kind: u32, @@ -1611,31 +1846,35 @@ pub extern "C" fn crypto_decrypt_aead( .into_opt_string() .map(|s| data_encoding::BASE64URL_NOPAD.decode(s.as_bytes()).unwrap()); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_decrypt_aead", - "kind", - kind.to_string(), - ) - })?; - let out = csv.decrypt_aead( - &body, - &nonce, - &shared_secret, - match &associated_data { - Some(ad) => Some(ad.as_slice()), - None => None, - }, - )?; - let out = data_encoding::BASE64URL_NOPAD.encode(&out); - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_decrypt_aead", + "kind", + kind.to_string(), + ) + })?; + let out = csv.decrypt_aead( + &body, + &nonce, + &shared_secret, + match &associated_data { + Some(ad) => Some(ad.as_slice()), + None => None, + }, + )?; + let out = data_encoding::BASE64URL_NOPAD.encode(&out); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_encrypt_aead( port: i64, kind: u32, @@ -1660,31 +1899,35 @@ pub extern "C" fn crypto_encrypt_aead( .into_opt_string() .map(|s| data_encoding::BASE64URL_NOPAD.decode(s.as_bytes()).unwrap()); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_encrypt_aead", - "kind", - kind.to_string(), - ) - })?; - let out = csv.encrypt_aead( - &body, - &nonce, - &shared_secret, - match &associated_data { - Some(ad) => Some(ad.as_slice()), - None => None, - }, - )?; - let out = data_encoding::BASE64URL_NOPAD.encode(&out); - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_encrypt_aead", + "kind", + kind.to_string(), + ) + })?; + let out = csv.encrypt_aead( + &body, + &nonce, + &shared_secret, + match &associated_data { + Some(ad) => Some(ad.as_slice()), + None => None, + }, + )?; + let out = data_encoding::BASE64URL_NOPAD.encode(&out); + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn crypto_crypt_no_auth( port: i64, kind: u32, @@ -1704,38 +1947,47 @@ pub extern "C" fn crypto_crypt_no_auth( let shared_secret: veilid_core::SharedSecret = veilid_core::deserialize_opt_json(shared_secret.into_opt_string()).unwrap(); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let crypto = veilid_api.crypto()?; - let csv = crypto.get(kind).ok_or_else(|| { - veilid_core::VeilidAPIError::invalid_argument( - "crypto_crypt_no_auth", - "kind", - kind.to_string(), - ) - })?; - csv.crypt_in_place_no_auth(&mut body, &nonce, &shared_secret); - let body = data_encoding::BASE64URL_NOPAD.encode(&body); - APIResult::Ok(body) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let crypto = veilid_api.crypto()?; + let csv = crypto.get(kind).ok_or_else(|| { + veilid_core::VeilidAPIError::invalid_argument( + "crypto_crypt_no_auth", + "kind", + kind.to_string(), + ) + })?; + csv.crypt_in_place_no_auth(&mut body, &nonce, &shared_secret); + let body = data_encoding::BASE64URL_NOPAD.encode(&body); + APIResult::Ok(body) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn now() -> u64 { veilid_core::get_aligned_timestamp().as_u64() } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn debug(port: i64, command: FfiStr) { let command = command.into_opt_string().unwrap_or_default(); - DartIsolateWrapper::new(port).spawn_result(async move { - let veilid_api = get_veilid_api().await?; - let out = veilid_api.debug(command).await?; - APIResult::Ok(out) - }); + DartIsolateWrapper::new(port).spawn_result( + async move { + let veilid_api = get_veilid_api().await?; + let out = veilid_api.debug(command).await?; + APIResult::Ok(out) + } + .in_current_span(), + ); } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn veilid_version_string() -> *mut c_char { veilid_core::veilid_version_string().into_ffi_value() } @@ -1748,6 +2000,7 @@ pub struct VeilidVersion { } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn veilid_version() -> VeilidVersion { let (major, minor, patch) = veilid_core::veilid_version(); VeilidVersion { @@ -1758,6 +2011,7 @@ pub extern "C" fn veilid_version() -> VeilidVersion { } #[no_mangle] +#[instrument(level = "trace", target = "ffi", skip_all)] pub extern "C" fn default_veilid_config() -> *mut c_char { veilid_core::default_veilid_config().into_ffi_value() } diff --git a/veilid-flutter/rust/src/dart_isolate_wrapper.rs b/veilid-flutter/rust/src/dart_isolate_wrapper.rs index 35b8bbe2..e722e68a 100644 --- a/veilid-flutter/rust/src/dart_isolate_wrapper.rs +++ b/veilid-flutter/rust/src/dart_isolate_wrapper.rs @@ -58,6 +58,7 @@ impl DartIsolateWrapper { Err(e) => self.err_json(e), } } + pub fn result_json( self, result: Result, @@ -67,6 +68,7 @@ impl DartIsolateWrapper { Err(e) => self.err_json(e), } } + pub fn ok(self, value: T) -> bool { self.isolate .post(vec![MESSAGE_OK.into_dart(), value.into_dart()]) diff --git a/veilid-server/src/main.rs b/veilid-server/src/main.rs index 53dcdc03..a28680c7 100644 --- a/veilid-server/src/main.rs +++ b/veilid-server/src/main.rs @@ -151,7 +151,7 @@ pub struct CmdlineArgs { console: bool, } -#[instrument(err)] +#[instrument(level = "trace", skip_all, err)] fn main() -> EyreResult<()> { #[cfg(windows)] let _ = ansi_term::enable_ansi_support(); diff --git a/veilid-server/src/unix.rs b/veilid-server/src/unix.rs index 7f076423..2d3d7fd4 100644 --- a/veilid-server/src/unix.rs +++ b/veilid-server/src/unix.rs @@ -8,7 +8,7 @@ use signal_hook::consts::signal::*; use signal_hook_async_std::Signals; use veilid_core::tools::*; -#[instrument(skip(signals))] +#[instrument(level = "trace", skip_all)] async fn handle_signals(mut signals: Signals) { while let Some(signal) = signals.next().await { match signal { @@ -47,7 +47,7 @@ pub async fn run_veilid_server_with_signals( } #[warn(missing_docs)] -#[instrument(err)] +#[instrument(level = "trace", skip_all, err)] pub fn run_daemon(settings: Settings, _args: CmdlineArgs) -> EyreResult<()> { let daemon = { let mut daemon = daemonize::Daemonize::new(); diff --git a/veilid-server/src/veilid_logs.rs b/veilid-server/src/veilid_logs.rs index 55e7e2b7..56260cc2 100644 --- a/veilid-server/src/veilid_logs.rs +++ b/veilid-server/src/veilid_logs.rs @@ -76,13 +76,14 @@ impl VeilidLogs { // Flamegraph logger let mut flame_guard = None; if settingsr.logging.flame.enabled { - let filter = veilid_core::VeilidLayerFilter::new( - convert_loglevel(LogLevel::Trace), - &[], //&settingsr.logging.terminal.ignore_log_targets, + let filter = veilid_core::VeilidLayerFilter::new_no_default( + veilid_core::VeilidConfigLogLevel::Trace, + &veilid_core::FLAME_LOG_FACILITIES_IGNORE_LIST.map(|x| x.to_string()), ); let (flame_layer, guard) = FlameLayer::with_file(&settingsr.logging.flame.path)?; flame_guard = Some(guard); - filters.insert("flame", filter.clone()); + // Do not include this in change_log_level changes, so we keep trace level + // filters.insert("flame", filter.clone()); layers.push( flame_layer .with_threads_collapsed(true)