diff --git a/veilid-core/src/rpc_processor/coders/sequencing.rs b/veilid-core/src/rpc_processor/coders/sequencing.rs new file mode 100644 index 00000000..187762fc --- /dev/null +++ b/veilid-core/src/rpc_processor/coders/sequencing.rs @@ -0,0 +1,17 @@ +use super::*; + +pub fn encode_sequencing(sequencing: Sequencing) -> veilid_capnp::Sequencing { + match sequencing { + Sequencing::NoPreference => veilid_capnp::Sequencing::NoPreference, + Sequencing::PreferOrdered => veilid_capnp::Sequencing::PreferOrdered, + Sequencing::EnsureOrdered => veilid_capnp::Sequencing::EnsureOrdered, + } +} + +pub fn decode_sequencing(sequencing: veilid_capnp::Sequencing) -> Sequencing { + match sequencing { + veilid_capnp::Sequencing::NoPreference => Sequencing::NoPreference, + veilid_capnp::Sequencing::PreferOrdered => Sequencing::PreferOrdered, + veilid_capnp::Sequencing::EnsureOrdered => Sequencing::EnsureOrdered, + } +} diff --git a/veilid-core/src/rpc_processor/operation_waiter.rs b/veilid-core/src/rpc_processor/operation_waiter.rs index 32206ded..6ea1e7b3 100644 --- a/veilid-core/src/rpc_processor/operation_waiter.rs +++ b/veilid-core/src/rpc_processor/operation_waiter.rs @@ -121,7 +121,7 @@ where Ok(res .on_timeout(|| { log_rpc!(debug "op wait timed out: {}", handle.op_id); - log_rpc!(debug "backtrace: {}", debug_backtrace()); + debug_print_backtrace(); self.cancel_op_waiter(handle.op_id); }) .map(|res| { diff --git a/veilid-tools/src/tools.rs b/veilid-tools/src/tools.rs index 7ef635d1..632336a1 100644 --- a/veilid-tools/src/tools.rs +++ b/veilid-tools/src/tools.rs @@ -303,3 +303,28 @@ pub fn debug_backtrace() -> String { let bt = backtrace::Backtrace::new(); format!("{:?}", bt) } + +pub fn debug_print_backtrace() { + if is_debug_backtrace_enabled() { + debug!("{}", debug_backtrace()); + } +} + +pub fn is_debug_backtrace_enabled() -> bool { + cfg_if! { + if #[cfg(debug_assertions)] { + cfg_if! { + if #[cfg(target_arch = "wasm32")] { + let rbenv = get_wasm_global_string_value("RUST_BACKTRACE").unwrap_or_default(); + } + else + { + let rbenv = std::env::var("RUST_BACKTRACE").unwrap_or_default(); + } + } + rbenv == "1" || rbenv == "full" + } else { + false + } + } +} diff --git a/veilid-tools/src/wasm.rs b/veilid-tools/src/wasm.rs index bfecbf9b..1a54aee5 100644 --- a/veilid-tools/src/wasm.rs +++ b/veilid-tools/src/wasm.rs @@ -21,7 +21,7 @@ pub fn is_browser() -> bool { return cache != 0; } - let res = Reflect::has(&global().as_ref(), &"window".into()).unwrap_or_default(); + let res = Reflect::has(&global().as_ref(), &"navigator".into()).unwrap_or_default(); CACHE.store(res as i8, Ordering::Relaxed); @@ -35,7 +35,7 @@ pub fn is_browser_https() -> bool { return cache != 0; } - let res = js_sys::eval("window.location.protocol === 'https'") + let res = js_sys::eval("self.location.protocol === 'https'") .map(|res| res.is_truthy()) .unwrap_or_default(); @@ -44,6 +44,13 @@ pub fn is_browser_https() -> bool { res } +pub fn get_wasm_global_string_value>(key: K) -> Option { + let Ok(v) = Reflect::get(&global().as_ref(), &JsValue::from_str(key.as_ref())) else { + return None; + }; + v.as_string() +} + #[derive(ThisError, Debug, Clone, Eq, PartialEq)] #[error("JsValue error")] pub struct JsValueError(String);