diff --git a/veilid-core/src/network_manager/send_data.rs b/veilid-core/src/network_manager/send_data.rs index 8774f5ad..0d8b336e 100644 --- a/veilid-core/src/network_manager/send_data.rs +++ b/veilid-core/src/network_manager/send_data.rs @@ -357,7 +357,13 @@ impl NetworkManager { ContactMethod::SignalReverse(relay_key, target_key) => { let mut relay_nr = routing_table .lookup_and_filter_noderef(relay_key, routing_domain.into(), dial_info_filter)? - .ok_or_else(|| eyre!("couldn't look up relay"))?; + .ok_or_else(|| { + eyre!( + "couldn't look up relay for signal reverse: {} with filter {:?}", + relay_key, + dial_info_filter + ) + })?; if !target_node_ref.node_ids().contains(&target_key) { bail!("signalreverse target noderef didn't match target key: {:?} != {} for relay {}", target_node_ref, target_key, relay_key ); } @@ -367,7 +373,13 @@ impl NetworkManager { ContactMethod::SignalHolePunch(relay_key, target_key) => { let mut relay_nr = routing_table .lookup_and_filter_noderef(relay_key, routing_domain.into(), dial_info_filter)? - .ok_or_else(|| eyre!("couldn't look up relay"))?; + .ok_or_else(|| { + eyre!( + "couldn't look up relay for hole punch: {} with filter {:?}", + relay_key, + dial_info_filter + ) + })?; if !target_node_ref.node_ids().contains(&target_key) { bail!("signalholepunch target noderef didn't match target key: {:?} != {} for relay {}", target_node_ref, target_key, relay_key ); } @@ -383,14 +395,26 @@ impl NetworkManager { ContactMethod::InboundRelay(relay_key) => { let mut relay_nr = routing_table .lookup_and_filter_noderef(relay_key, routing_domain.into(), dial_info_filter)? - .ok_or_else(|| eyre!("couldn't look up relay"))?; + .ok_or_else(|| { + eyre!( + "couldn't look up relay for inbound relay: {} with filter {:?}", + relay_key, + dial_info_filter + ) + })?; relay_nr.set_sequencing(sequencing); NodeContactMethod::InboundRelay(relay_nr) } ContactMethod::OutboundRelay(relay_key) => { let mut relay_nr = routing_table .lookup_and_filter_noderef(relay_key, routing_domain.into(), dial_info_filter)? - .ok_or_else(|| eyre!("couldn't look up relay"))?; + .ok_or_else(|| { + eyre!( + "couldn't look up relay for outbound relay: {} with filter {:?}", + relay_key, + dial_info_filter + ) + })?; relay_nr.set_sequencing(sequencing); NodeContactMethod::OutboundRelay(relay_nr) } diff --git a/veilid-core/src/network_manager/wasm/protocol/mod.rs b/veilid-core/src/network_manager/wasm/protocol/mod.rs index e6314dd7..4b08e7b1 100644 --- a/veilid-core/src/network_manager/wasm/protocol/mod.rs +++ b/veilid-core/src/network_manager/wasm/protocol/mod.rs @@ -17,7 +17,7 @@ impl ProtocolNetworkConnection { _local_address: Option, dial_info: &DialInfo, timeout_ms: u32, - address_filter: AddressFiltter, + address_filter: AddressFilter, ) -> io::Result> { if address_filter.is_punished(dial_info.address().to_ip_addr()) { return Ok(NetworkResult::no_connection_other("punished")); diff --git a/veilid-core/src/routing_table/routing_table_inner.rs b/veilid-core/src/routing_table/routing_table_inner.rs index 9924efdc..ef1f5401 100644 --- a/veilid-core/src/routing_table/routing_table_inner.rs +++ b/veilid-core/src/routing_table/routing_table_inner.rs @@ -852,6 +852,16 @@ impl RoutingTableInner { } } + // Register relay info first if we have that + if let Some(relay_peer_info) = peer_info.signed_node_info().relay_peer_info() { + self.register_node_with_peer_info( + outer_self.clone(), + routing_domain, + relay_peer_info, + false, + )?; + } + let (node_ids, signed_node_info) = peer_info.destructure(); let mut nr = self.create_node_ref(outer_self, &node_ids, |_rti, e| { e.update_signed_node_info(routing_domain, signed_node_info); diff --git a/veilid-core/src/rpc_processor/coders/operations/operation_watch_value.rs b/veilid-core/src/rpc_processor/coders/operations/operation_watch_value.rs index d2aefa79..1ef425ab 100644 --- a/veilid-core/src/rpc_processor/coders/operations/operation_watch_value.rs +++ b/veilid-core/src/rpc_processor/coders/operations/operation_watch_value.rs @@ -22,7 +22,7 @@ impl RPCOperationWatchValueQ { watcher: PublicKey, signature: Signature, ) -> Result { - if subkeys.len() > MAX_WATCH_VALUE_Q_SUBKEYS_LEN { + if subkeys.len() as usize > MAX_WATCH_VALUE_Q_SUBKEYS_LEN { return Err(RPCError::protocol("WatchValueQ subkeys length too long")); } Ok(Self { @@ -38,7 +38,7 @@ impl RPCOperationWatchValueQ { // signature covers: key, subkeys, expiration, count, using watcher key fn make_signature_data(&self) -> Vec { let mut sig_data = - Vec::with_capacity(PUBLIC_KEY_LENGTH + 4 + (self.subkeys.len() * 8) + 8 + 4); + Vec::with_capacity(PUBLIC_KEY_LENGTH + 4 + (self.subkeys.len() as usize * 8) + 8 + 4); sig_data.extend_from_slice(&self.key.kind.0); sig_data.extend_from_slice(&self.key.value.bytes); for sk in self.subkeys.ranges() { diff --git a/veilid-core/tests/web.rs b/veilid-core/tests/web.rs index 65b3e291..caba3621 100644 --- a/veilid-core/tests/web.rs +++ b/veilid-core/tests/web.rs @@ -2,8 +2,9 @@ #![cfg(target_arch = "wasm32")] #![recursion_limit = "256"] +use cfg_if::*; +use parking_lot::Once; use veilid_core::tests::*; -use veilid_core::tools::*; use wasm_bindgen_test::*; wasm_bindgen_test_configure!(run_in_browser); diff --git a/veilid-flutter/lib/veilid_config.dart b/veilid-flutter/lib/veilid_config.dart index c44e0659..3f98649e 100644 --- a/veilid-flutter/lib/veilid_config.dart +++ b/veilid-flutter/lib/veilid_config.dart @@ -875,11 +875,12 @@ class VeilidConfigCapabilities { Map toJson() { return { - 'disable': disable, + 'disable': disable.map((p) => p).toList(), }; } - VeilidConfigCapabilities.fromJson(dynamic json) : disable = json['disable']; + VeilidConfigCapabilities.fromJson(dynamic json) + : disable = List.from(json['disable'].map((j) => j)); } //////////// diff --git a/veilid-tools/src/must_join_handle.rs b/veilid-tools/src/must_join_handle.rs index a4afd1dc..e2d1f530 100644 --- a/veilid-tools/src/must_join_handle.rs +++ b/veilid-tools/src/must_join_handle.rs @@ -23,8 +23,9 @@ impl MustJoinHandle { } else if #[cfg(feature="rt-tokio")] { self.join_handle = None; } else if #[cfg(target_arch = "wasm32")] { - self.join_handle.take().detach(); - self.completed = true; + if let Some(jh) = self.join_handle.take() { + jh.detach(); + } } else { compile_error!("needs executor implementation") } diff --git a/veilid-tools/src/timeout.rs b/veilid-tools/src/timeout.rs index 1ca2df26..5203c416 100644 --- a/veilid-tools/src/timeout.rs +++ b/veilid-tools/src/timeout.rs @@ -2,6 +2,7 @@ use super::*; cfg_if! { if #[cfg(target_arch = "wasm32")] { + use futures_util::future::{select, Either}; pub async fn timeout(dur_ms: u32, f: F) -> Result where diff --git a/veilid-tools/src/timestamp.rs b/veilid-tools/src/timestamp.rs index c47e0021..94f9871e 100644 --- a/veilid-tools/src/timestamp.rs +++ b/veilid-tools/src/timestamp.rs @@ -14,8 +14,9 @@ cfg_if! { pub fn debug_ts(ts: u64) -> String { if is_browser() { - let mut now = Date::now(); - let mut date = Date::new_0(); + let now = Date::new_0(); + now.set_time(Date::now()); + let date = Date::new_0(); date.set_time((ts / 1000u64) as f64); let show_year = now.get_utc_full_year() != date.get_utc_full_year(); diff --git a/veilid-tools/tests/web.rs b/veilid-tools/tests/web.rs index ae522f3e..e3997307 100644 --- a/veilid-tools/tests/web.rs +++ b/veilid-tools/tests/web.rs @@ -1,6 +1,8 @@ //! Test suite for the Web and headless browsers. #![cfg(target_arch = "wasm32")] +use cfg_if::*; +use parking_lot::Once; use veilid_tools::tests::*; use veilid_tools::*; diff --git a/veilid-wasm/src/lib.rs b/veilid-wasm/src/lib.rs index 5011fbe5..80455917 100644 --- a/veilid-wasm/src/lib.rs +++ b/veilid-wasm/src/lib.rs @@ -9,6 +9,7 @@ use alloc::sync::Arc; use alloc::*; use core::cell::RefCell; use core::fmt::Debug; +use core::sync::atomic::{AtomicBool, Ordering}; use futures_util::FutureExt; use gloo_utils::format::JsValueSerdeExt; use js_sys::*; @@ -185,54 +186,52 @@ pub fn initialize_veilid_wasm() { console_error_panic_hook::set_once(); } -static SETUP_ONCE: Once = Once::new(); +static INITIALIZED: AtomicBool = AtomicBool::new(false); #[wasm_bindgen()] pub fn initialize_veilid_core(platform_config: String) { - SETUP_ONCE.call_once(|| { - let platform_config: VeilidWASMConfig = veilid_core::deserialize_json(&platform_config) - .expect("failed to deserialize platform config json"); + if INITIALIZED.swap(true, Ordering::Relaxed) { + return; + } + let platform_config: VeilidWASMConfig = veilid_core::deserialize_json(&platform_config) + .expect("failed to deserialize platform config json"); - // Set up subscriber and layers - let subscriber = Registry::default(); - let mut layers = Vec::new(); - let mut filters = (*FILTERS).borrow_mut(); + // Set up subscriber and layers + let subscriber = Registry::default(); + let mut layers = Vec::new(); + let mut filters = (*FILTERS).borrow_mut(); - // Performance logger - if platform_config.logging.performance.enabled { - let filter = veilid_core::VeilidLayerFilter::new( - platform_config.logging.performance.level, - None, - ); - let layer = WASMLayer::new( - WASMLayerConfigBuilder::new() - .set_report_logs_in_timings(platform_config.logging.performance.logs_in_timings) - .set_console_config(if platform_config.logging.performance.logs_in_console { - ConsoleConfig::ReportWithConsoleColor - } else { - ConsoleConfig::NoReporting - }) - .build(), - ) - .with_filter(filter.clone()); - filters.insert("performance", filter); - layers.push(layer.boxed()); - }; + // Performance logger + if platform_config.logging.performance.enabled { + let filter = + veilid_core::VeilidLayerFilter::new(platform_config.logging.performance.level, None); + let layer = WASMLayer::new( + WASMLayerConfigBuilder::new() + .set_report_logs_in_timings(platform_config.logging.performance.logs_in_timings) + .set_console_config(if platform_config.logging.performance.logs_in_console { + ConsoleConfig::ReportWithConsoleColor + } else { + ConsoleConfig::NoReporting + }) + .build(), + ) + .with_filter(filter.clone()); + filters.insert("performance", filter); + layers.push(layer.boxed()); + }; - // API logger - if platform_config.logging.api.enabled { - let filter = - veilid_core::VeilidLayerFilter::new(platform_config.logging.api.level, None); - let layer = veilid_core::ApiTracingLayer::get().with_filter(filter.clone()); - filters.insert("api", filter); - layers.push(layer.boxed()); - } + // API logger + if platform_config.logging.api.enabled { + let filter = veilid_core::VeilidLayerFilter::new(platform_config.logging.api.level, None); + let layer = veilid_core::ApiTracingLayer::get().with_filter(filter.clone()); + filters.insert("api", filter); + layers.push(layer.boxed()); + } - let subscriber = subscriber.with(layers); - subscriber - .try_init() - .map_err(|e| format!("failed to initialize logging: {}", e)) - .expect("failed to initalize WASM platform"); - }); + let subscriber = subscriber.with(layers); + subscriber + .try_init() + .map_err(|e| format!("failed to initialize logging: {}", e)) + .expect("failed to initalize WASM platform"); } #[wasm_bindgen()] @@ -356,14 +355,15 @@ pub fn routing_context_with_privacy(id: u32) -> u32 { } #[wasm_bindgen()] -pub fn routing_context_with_custom_privacy(id: u32, stability: String) -> u32 { - let stability: veilid_core::Stability = veilid_core::deserialize_json(&stability).unwrap(); +pub fn routing_context_with_custom_privacy(id: u32, safety_selection: String) -> u32 { + let safety_selection: veilid_core::SafetySelection = + veilid_core::deserialize_json(&safety_selection).unwrap(); let rc = (*ROUTING_CONTEXTS).borrow(); let Some(routing_context) = rc.get(&id) else { return 0; }; - let Ok(routing_context) = routing_context.clone().with_custom_privacy(stability) else { + let Ok(routing_context) = routing_context.clone().with_custom_privacy(safety_selection) else { return 0; }; let new_id = add_routing_context(routing_context);