fix wasm
This commit is contained in:
parent
e457c0bcc6
commit
b5906a52bc
@ -17,7 +17,7 @@ impl ProtocolNetworkConnection {
|
|||||||
_local_address: Option<SocketAddr>,
|
_local_address: Option<SocketAddr>,
|
||||||
dial_info: &DialInfo,
|
dial_info: &DialInfo,
|
||||||
timeout_ms: u32,
|
timeout_ms: u32,
|
||||||
address_filter: AddressFiltter,
|
address_filter: AddressFilter,
|
||||||
) -> io::Result<NetworkResult<ProtocolNetworkConnection>> {
|
) -> io::Result<NetworkResult<ProtocolNetworkConnection>> {
|
||||||
if address_filter.is_punished(dial_info.address().to_ip_addr()) {
|
if address_filter.is_punished(dial_info.address().to_ip_addr()) {
|
||||||
return Ok(NetworkResult::no_connection_other("punished"));
|
return Ok(NetworkResult::no_connection_other("punished"));
|
||||||
|
@ -22,7 +22,7 @@ impl RPCOperationWatchValueQ {
|
|||||||
watcher: PublicKey,
|
watcher: PublicKey,
|
||||||
signature: Signature,
|
signature: Signature,
|
||||||
) -> Result<Self, RPCError> {
|
) -> 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"));
|
return Err(RPCError::protocol("WatchValueQ subkeys length too long"));
|
||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@ -38,7 +38,7 @@ impl RPCOperationWatchValueQ {
|
|||||||
// signature covers: key, subkeys, expiration, count, using watcher key
|
// signature covers: key, subkeys, expiration, count, using watcher key
|
||||||
fn make_signature_data(&self) -> Vec<u8> {
|
fn make_signature_data(&self) -> Vec<u8> {
|
||||||
let mut sig_data =
|
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.kind.0);
|
||||||
sig_data.extend_from_slice(&self.key.value.bytes);
|
sig_data.extend_from_slice(&self.key.value.bytes);
|
||||||
for sk in self.subkeys.ranges() {
|
for sk in self.subkeys.ranges() {
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
#![cfg(target_arch = "wasm32")]
|
#![cfg(target_arch = "wasm32")]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
|
use cfg_if::*;
|
||||||
|
use parking_lot::Once;
|
||||||
use veilid_core::tests::*;
|
use veilid_core::tests::*;
|
||||||
use veilid_core::tools::*;
|
|
||||||
use wasm_bindgen_test::*;
|
use wasm_bindgen_test::*;
|
||||||
|
|
||||||
wasm_bindgen_test_configure!(run_in_browser);
|
wasm_bindgen_test_configure!(run_in_browser);
|
||||||
|
@ -23,8 +23,9 @@ impl<T> MustJoinHandle<T> {
|
|||||||
} else if #[cfg(feature="rt-tokio")] {
|
} else if #[cfg(feature="rt-tokio")] {
|
||||||
self.join_handle = None;
|
self.join_handle = None;
|
||||||
} else if #[cfg(target_arch = "wasm32")] {
|
} else if #[cfg(target_arch = "wasm32")] {
|
||||||
self.join_handle.take().detach();
|
if let Some(jh) = self.join_handle.take() {
|
||||||
self.completed = true;
|
jh.detach();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
compile_error!("needs executor implementation")
|
compile_error!("needs executor implementation")
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ use super::*;
|
|||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(target_arch = "wasm32")] {
|
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>
|
pub async fn timeout<F, T>(dur_ms: u32, f: F) -> Result<T, TimeoutError>
|
||||||
where
|
where
|
||||||
|
@ -14,8 +14,9 @@ cfg_if! {
|
|||||||
|
|
||||||
pub fn debug_ts(ts: u64) -> String {
|
pub fn debug_ts(ts: u64) -> String {
|
||||||
if is_browser() {
|
if is_browser() {
|
||||||
let mut now = Date::now();
|
let now = Date::new_0();
|
||||||
let mut date = Date::new_0();
|
now.set_time(Date::now());
|
||||||
|
let date = Date::new_0();
|
||||||
date.set_time((ts / 1000u64) as f64);
|
date.set_time((ts / 1000u64) as f64);
|
||||||
|
|
||||||
let show_year = now.get_utc_full_year() != date.get_utc_full_year();
|
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.
|
//! Test suite for the Web and headless browsers.
|
||||||
#![cfg(target_arch = "wasm32")]
|
#![cfg(target_arch = "wasm32")]
|
||||||
|
|
||||||
|
use cfg_if::*;
|
||||||
|
use parking_lot::Once;
|
||||||
use veilid_tools::tests::*;
|
use veilid_tools::tests::*;
|
||||||
use veilid_tools::*;
|
use veilid_tools::*;
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ use alloc::sync::Arc;
|
|||||||
use alloc::*;
|
use alloc::*;
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
|
use core::sync::atomic::{AtomicBool, Ordering};
|
||||||
use futures_util::FutureExt;
|
use futures_util::FutureExt;
|
||||||
use gloo_utils::format::JsValueSerdeExt;
|
use gloo_utils::format::JsValueSerdeExt;
|
||||||
use js_sys::*;
|
use js_sys::*;
|
||||||
@ -185,54 +186,52 @@ pub fn initialize_veilid_wasm() {
|
|||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
}
|
}
|
||||||
|
|
||||||
static SETUP_ONCE: Once = Once::new();
|
static INITIALIZED: AtomicBool = AtomicBool::new(false);
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
pub fn initialize_veilid_core(platform_config: String) {
|
pub fn initialize_veilid_core(platform_config: String) {
|
||||||
SETUP_ONCE.call_once(|| {
|
if INITIALIZED.swap(true, Ordering::Relaxed) {
|
||||||
let platform_config: VeilidWASMConfig = veilid_core::deserialize_json(&platform_config)
|
return;
|
||||||
.expect("failed to deserialize platform config json");
|
}
|
||||||
|
let platform_config: VeilidWASMConfig = veilid_core::deserialize_json(&platform_config)
|
||||||
|
.expect("failed to deserialize platform config json");
|
||||||
|
|
||||||
// Set up subscriber and layers
|
// Set up subscriber and layers
|
||||||
let subscriber = Registry::default();
|
let subscriber = Registry::default();
|
||||||
let mut layers = Vec::new();
|
let mut layers = Vec::new();
|
||||||
let mut filters = (*FILTERS).borrow_mut();
|
let mut filters = (*FILTERS).borrow_mut();
|
||||||
|
|
||||||
// Performance logger
|
// Performance logger
|
||||||
if platform_config.logging.performance.enabled {
|
if platform_config.logging.performance.enabled {
|
||||||
let filter = veilid_core::VeilidLayerFilter::new(
|
let filter =
|
||||||
platform_config.logging.performance.level,
|
veilid_core::VeilidLayerFilter::new(platform_config.logging.performance.level, None);
|
||||||
None,
|
let layer = WASMLayer::new(
|
||||||
);
|
WASMLayerConfigBuilder::new()
|
||||||
let layer = WASMLayer::new(
|
.set_report_logs_in_timings(platform_config.logging.performance.logs_in_timings)
|
||||||
WASMLayerConfigBuilder::new()
|
.set_console_config(if platform_config.logging.performance.logs_in_console {
|
||||||
.set_report_logs_in_timings(platform_config.logging.performance.logs_in_timings)
|
ConsoleConfig::ReportWithConsoleColor
|
||||||
.set_console_config(if platform_config.logging.performance.logs_in_console {
|
} else {
|
||||||
ConsoleConfig::ReportWithConsoleColor
|
ConsoleConfig::NoReporting
|
||||||
} else {
|
})
|
||||||
ConsoleConfig::NoReporting
|
.build(),
|
||||||
})
|
)
|
||||||
.build(),
|
.with_filter(filter.clone());
|
||||||
)
|
filters.insert("performance", filter);
|
||||||
.with_filter(filter.clone());
|
layers.push(layer.boxed());
|
||||||
filters.insert("performance", filter);
|
};
|
||||||
layers.push(layer.boxed());
|
|
||||||
};
|
|
||||||
|
|
||||||
// API logger
|
// API logger
|
||||||
if platform_config.logging.api.enabled {
|
if platform_config.logging.api.enabled {
|
||||||
let filter =
|
let filter = veilid_core::VeilidLayerFilter::new(platform_config.logging.api.level, None);
|
||||||
veilid_core::VeilidLayerFilter::new(platform_config.logging.api.level, None);
|
let layer = veilid_core::ApiTracingLayer::get().with_filter(filter.clone());
|
||||||
let layer = veilid_core::ApiTracingLayer::get().with_filter(filter.clone());
|
filters.insert("api", filter);
|
||||||
filters.insert("api", filter);
|
layers.push(layer.boxed());
|
||||||
layers.push(layer.boxed());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let subscriber = subscriber.with(layers);
|
let subscriber = subscriber.with(layers);
|
||||||
subscriber
|
subscriber
|
||||||
.try_init()
|
.try_init()
|
||||||
.map_err(|e| format!("failed to initialize logging: {}", e))
|
.map_err(|e| format!("failed to initialize logging: {}", e))
|
||||||
.expect("failed to initalize WASM platform");
|
.expect("failed to initalize WASM platform");
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
@ -356,14 +355,15 @@ pub fn routing_context_with_privacy(id: u32) -> u32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
pub fn routing_context_with_custom_privacy(id: u32, stability: String) -> u32 {
|
pub fn routing_context_with_custom_privacy(id: u32, safety_selection: String) -> u32 {
|
||||||
let stability: veilid_core::Stability = veilid_core::deserialize_json(&stability).unwrap();
|
let safety_selection: veilid_core::SafetySelection =
|
||||||
|
veilid_core::deserialize_json(&safety_selection).unwrap();
|
||||||
|
|
||||||
let rc = (*ROUTING_CONTEXTS).borrow();
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
||||||
let Some(routing_context) = rc.get(&id) else {
|
let Some(routing_context) = rc.get(&id) else {
|
||||||
return 0;
|
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;
|
return 0;
|
||||||
};
|
};
|
||||||
let new_id = add_routing_context(routing_context);
|
let new_id = add_routing_context(routing_context);
|
||||||
|
Loading…
Reference in New Issue
Block a user