Merge branch 'veilidchat-work' into 'main'

Fix Flutter Config Issue

See merge request veilid/veilid!56
This commit is contained in:
Christien Rioux 2023-07-05 01:21:31 +00:00
commit d5c174778f
11 changed files with 100 additions and 59 deletions

View File

@ -357,7 +357,13 @@ impl NetworkManager {
ContactMethod::SignalReverse(relay_key, target_key) => { ContactMethod::SignalReverse(relay_key, target_key) => {
let mut relay_nr = routing_table let mut relay_nr = routing_table
.lookup_and_filter_noderef(relay_key, routing_domain.into(), dial_info_filter)? .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) { 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 ); 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) => { ContactMethod::SignalHolePunch(relay_key, target_key) => {
let mut relay_nr = routing_table let mut relay_nr = routing_table
.lookup_and_filter_noderef(relay_key, routing_domain.into(), dial_info_filter)? .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) { 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 ); 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) => { ContactMethod::InboundRelay(relay_key) => {
let mut relay_nr = routing_table let mut relay_nr = routing_table
.lookup_and_filter_noderef(relay_key, routing_domain.into(), dial_info_filter)? .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); relay_nr.set_sequencing(sequencing);
NodeContactMethod::InboundRelay(relay_nr) NodeContactMethod::InboundRelay(relay_nr)
} }
ContactMethod::OutboundRelay(relay_key) => { ContactMethod::OutboundRelay(relay_key) => {
let mut relay_nr = routing_table let mut relay_nr = routing_table
.lookup_and_filter_noderef(relay_key, routing_domain.into(), dial_info_filter)? .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); relay_nr.set_sequencing(sequencing);
NodeContactMethod::OutboundRelay(relay_nr) NodeContactMethod::OutboundRelay(relay_nr)
} }

View File

@ -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"));

View File

@ -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 (node_ids, signed_node_info) = peer_info.destructure();
let mut nr = self.create_node_ref(outer_self, &node_ids, |_rti, e| { let mut nr = self.create_node_ref(outer_self, &node_ids, |_rti, e| {
e.update_signed_node_info(routing_domain, signed_node_info); e.update_signed_node_info(routing_domain, signed_node_info);

View File

@ -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() {

View File

@ -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);

View File

@ -875,11 +875,12 @@ class VeilidConfigCapabilities {
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return { return {
'disable': disable, 'disable': disable.map((p) => p).toList(),
}; };
} }
VeilidConfigCapabilities.fromJson(dynamic json) : disable = json['disable']; VeilidConfigCapabilities.fromJson(dynamic json)
: disable = List<String>.from(json['disable'].map((j) => j));
} }
//////////// ////////////

View File

@ -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")
} }

View File

@ -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

View File

@ -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();

View File

@ -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::*;

View File

@ -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,10 +186,12 @@ 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) {
return;
}
let platform_config: VeilidWASMConfig = veilid_core::deserialize_json(&platform_config) let platform_config: VeilidWASMConfig = veilid_core::deserialize_json(&platform_config)
.expect("failed to deserialize platform config json"); .expect("failed to deserialize platform config json");
@ -199,10 +202,8 @@ pub fn initialize_veilid_core(platform_config: String) {
// 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( let layer = WASMLayer::new(
WASMLayerConfigBuilder::new() WASMLayerConfigBuilder::new()
.set_report_logs_in_timings(platform_config.logging.performance.logs_in_timings) .set_report_logs_in_timings(platform_config.logging.performance.logs_in_timings)
@ -220,8 +221,7 @@ pub fn initialize_veilid_core(platform_config: String) {
// 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());
@ -232,7 +232,6 @@ pub fn initialize_veilid_core(platform_config: String) {
.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);