fix wasm
This commit is contained in:
parent
e457c0bcc6
commit
b5906a52bc
@ -17,7 +17,7 @@ impl ProtocolNetworkConnection {
|
||||
_local_address: Option<SocketAddr>,
|
||||
dial_info: &DialInfo,
|
||||
timeout_ms: u32,
|
||||
address_filter: AddressFiltter,
|
||||
address_filter: AddressFilter,
|
||||
) -> io::Result<NetworkResult<ProtocolNetworkConnection>> {
|
||||
if address_filter.is_punished(dial_info.address().to_ip_addr()) {
|
||||
return Ok(NetworkResult::no_connection_other("punished"));
|
||||
|
@ -22,7 +22,7 @@ impl RPCOperationWatchValueQ {
|
||||
watcher: PublicKey,
|
||||
signature: Signature,
|
||||
) -> Result<Self, RPCError> {
|
||||
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<u8> {
|
||||
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() {
|
||||
|
@ -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);
|
||||
|
@ -23,8 +23,9 @@ impl<T> MustJoinHandle<T> {
|
||||
} 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")
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ use super::*;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(target_arch = "wasm32")] {
|
||||
use futures_util::future::{select, Either};
|
||||
|
||||
pub async fn timeout<F, T>(dur_ms: u32, f: F) -> Result<T, TimeoutError>
|
||||
where
|
||||
|
@ -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();
|
||||
|
@ -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::*;
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user