From b1cc0d803c1a07c90ea00a122e79dea1341e45a4 Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 5 Oct 2022 19:12:10 -0400 Subject: [PATCH] xfer --- Cargo.lock | 14 ++++++++ veilid-core/src/network_manager/wasm/mod.rs | 37 +++++++++++++++------ veilid-wasm/Cargo.toml | 1 + veilid-wasm/src/lib.rs | 3 +- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index db7beaf2..8c0adabc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1919,6 +1919,19 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "gloo-utils" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40913a05c8297adca04392f707b1e73b12ba7b8eab7244a4961580b1fd34063c" +dependencies = [ + "js-sys", + "serde", + "serde_json", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "grpcio" version = "0.9.1" @@ -5448,6 +5461,7 @@ dependencies = [ "console_error_panic_hook", "data-encoding", "futures-util", + "gloo-utils", "js-sys", "lazy_static", "send_wrapper 0.6.0", diff --git a/veilid-core/src/network_manager/wasm/mod.rs b/veilid-core/src/network_manager/wasm/mod.rs index 448c1e9e..c36454e5 100644 --- a/veilid-core/src/network_manager/wasm/mod.rs +++ b/veilid-core/src/network_manager/wasm/mod.rs @@ -10,28 +10,37 @@ use std::io; ///////////////////////////////////////////////////////////////// struct NetworkInner { - network_manager: NetworkManager, network_started: bool, network_needs_restart: bool, protocol_config: Option, } +struct NetworkUnlockedInner { + network_manager: NetworkManager, +} + #[derive(Clone)] pub struct Network { config: VeilidConfig, inner: Arc>, + unlocked_inner: Arc, } impl Network { - fn new_inner(network_manager: NetworkManager) -> NetworkInner { + fn new_inner() -> NetworkInner { NetworkInner { - network_manager, network_started: false, network_needs_restart: false, protocol_config: None, //join_handle: None, } } + fn new_unlocked_inner(network_manager: NetworkManager) -> NetworkUnlockedInner { + NetworkUnlockedInner { + network_manager + } + } + pub fn new( network_manager: NetworkManager, routing_table: RoutingTable, @@ -39,15 +48,16 @@ impl Network { ) -> Self { Self { config: network_manager.config(), - inner: Arc::new(Mutex::new(Self::new_inner(network_manager))), + inner: Arc::new(Mutex::new(Self::new_inner())), + unlocked_inner: Arc::new(Self::new_unlocked_inner(network_manager)) } } fn network_manager(&self) -> NetworkManager { - self.inner.lock().network_manager.clone() + self.unlocked_inner.network_manager.clone() } fn connection_manager(&self) -> ConnectionManager { - self.inner.lock().network_manager.connection_manager() + self.unlocked_inner.network_manager.connection_manager() } ///////////////////////////////////////////////////////////////// @@ -269,15 +279,22 @@ impl Network { trace!("stopping network"); // Reset state - let network_manager = self.inner.lock().network_manager.clone(); + let network_manager = self.network_manager(); let routing_table = network_manager.routing_table(); // Drop all dial info - routing_table.clear_dial_info_details(RoutingDomain::PublicInternet); - routing_table.clear_dial_info_details(RoutingDomain::LocalNetwork); + let mut editor = routing_table.edit_routing_domain(RoutingDomain::PublicInternet); + editor.disable_node_info_updates(); + editor.clear_dial_info_details(); + editor.commit().await; + + let mut editor = routing_table.edit_routing_domain(RoutingDomain::LocalNetwork); + editor.disable_node_info_updates(); + editor.clear_dial_info_details(); + editor.commit().await; // Cancels all async background tasks by dropping join handles - *self.inner.lock() = Self::new_inner(network_manager); + *self.inner.lock() = Self::new_inner(); trace!("network stopped"); } diff --git a/veilid-wasm/Cargo.toml b/veilid-wasm/Cargo.toml index 7ca4e42f..758f4f88 100644 --- a/veilid-wasm/Cargo.toml +++ b/veilid-wasm/Cargo.toml @@ -27,6 +27,7 @@ lazy_static = "^1" send_wrapper = "^0" futures-util = { version = "^0", default_features = false, features = ["alloc"] } data-encoding = { version = "^2" } +gloo-utils = { version = "^0", features = ["serde"] } [dev-dependencies] wasm-bindgen-test = "^0" diff --git a/veilid-wasm/src/lib.rs b/veilid-wasm/src/lib.rs index 6baf1e80..e49bb8e6 100644 --- a/veilid-wasm/src/lib.rs +++ b/veilid-wasm/src/lib.rs @@ -10,6 +10,7 @@ use alloc::*; use core::any::{Any, TypeId}; use core::cell::RefCell; use futures_util::FutureExt; +use gloo_utils::format::JsValueSerdeExt; use js_sys::*; use lazy_static::*; use send_wrapper::*; @@ -306,5 +307,5 @@ pub fn veilid_version() -> JsValue { minor, patch, }; - JsValue::from_serde(&vv).unwrap() + ::from_serde(&vv).unwrap() }