xfer
This commit is contained in:
parent
98f90154f3
commit
b1cc0d803c
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -1919,6 +1919,19 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"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]]
|
[[package]]
|
||||||
name = "grpcio"
|
name = "grpcio"
|
||||||
version = "0.9.1"
|
version = "0.9.1"
|
||||||
@ -5448,6 +5461,7 @@ dependencies = [
|
|||||||
"console_error_panic_hook",
|
"console_error_panic_hook",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
"gloo-utils",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"send_wrapper 0.6.0",
|
"send_wrapper 0.6.0",
|
||||||
|
@ -10,28 +10,37 @@ use std::io;
|
|||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct NetworkInner {
|
struct NetworkInner {
|
||||||
network_manager: NetworkManager,
|
|
||||||
network_started: bool,
|
network_started: bool,
|
||||||
network_needs_restart: bool,
|
network_needs_restart: bool,
|
||||||
protocol_config: Option<ProtocolConfig>,
|
protocol_config: Option<ProtocolConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct NetworkUnlockedInner {
|
||||||
|
network_manager: NetworkManager,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Network {
|
pub struct Network {
|
||||||
config: VeilidConfig,
|
config: VeilidConfig,
|
||||||
inner: Arc<Mutex<NetworkInner>>,
|
inner: Arc<Mutex<NetworkInner>>,
|
||||||
|
unlocked_inner: Arc<NetworkUnlockedInner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Network {
|
impl Network {
|
||||||
fn new_inner(network_manager: NetworkManager) -> NetworkInner {
|
fn new_inner() -> NetworkInner {
|
||||||
NetworkInner {
|
NetworkInner {
|
||||||
network_manager,
|
|
||||||
network_started: false,
|
network_started: false,
|
||||||
network_needs_restart: false,
|
network_needs_restart: false,
|
||||||
protocol_config: None, //join_handle: None,
|
protocol_config: None, //join_handle: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn new_unlocked_inner(network_manager: NetworkManager) -> NetworkUnlockedInner {
|
||||||
|
NetworkUnlockedInner {
|
||||||
|
network_manager
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
network_manager: NetworkManager,
|
network_manager: NetworkManager,
|
||||||
routing_table: RoutingTable,
|
routing_table: RoutingTable,
|
||||||
@ -39,15 +48,16 @@ impl Network {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
config: network_manager.config(),
|
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 {
|
fn network_manager(&self) -> NetworkManager {
|
||||||
self.inner.lock().network_manager.clone()
|
self.unlocked_inner.network_manager.clone()
|
||||||
}
|
}
|
||||||
fn connection_manager(&self) -> ConnectionManager {
|
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");
|
trace!("stopping network");
|
||||||
|
|
||||||
// Reset state
|
// Reset state
|
||||||
let network_manager = self.inner.lock().network_manager.clone();
|
let network_manager = self.network_manager();
|
||||||
let routing_table = network_manager.routing_table();
|
let routing_table = network_manager.routing_table();
|
||||||
|
|
||||||
// Drop all dial info
|
// Drop all dial info
|
||||||
routing_table.clear_dial_info_details(RoutingDomain::PublicInternet);
|
let mut editor = routing_table.edit_routing_domain(RoutingDomain::PublicInternet);
|
||||||
routing_table.clear_dial_info_details(RoutingDomain::LocalNetwork);
|
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
|
// 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");
|
trace!("network stopped");
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ lazy_static = "^1"
|
|||||||
send_wrapper = "^0"
|
send_wrapper = "^0"
|
||||||
futures-util = { version = "^0", default_features = false, features = ["alloc"] }
|
futures-util = { version = "^0", default_features = false, features = ["alloc"] }
|
||||||
data-encoding = { version = "^2" }
|
data-encoding = { version = "^2" }
|
||||||
|
gloo-utils = { version = "^0", features = ["serde"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
wasm-bindgen-test = "^0"
|
wasm-bindgen-test = "^0"
|
||||||
|
@ -10,6 +10,7 @@ use alloc::*;
|
|||||||
use core::any::{Any, TypeId};
|
use core::any::{Any, TypeId};
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
use futures_util::FutureExt;
|
use futures_util::FutureExt;
|
||||||
|
use gloo_utils::format::JsValueSerdeExt;
|
||||||
use js_sys::*;
|
use js_sys::*;
|
||||||
use lazy_static::*;
|
use lazy_static::*;
|
||||||
use send_wrapper::*;
|
use send_wrapper::*;
|
||||||
@ -306,5 +307,5 @@ pub fn veilid_version() -> JsValue {
|
|||||||
minor,
|
minor,
|
||||||
patch,
|
patch,
|
||||||
};
|
};
|
||||||
JsValue::from_serde(&vv).unwrap()
|
<JsValue as JsValueSerdeExt>::from_serde(&vv).unwrap()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user