mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-10-01 01:26:08 -04:00
api work
This commit is contained in:
parent
1decd333c8
commit
7ef6d407a5
@ -383,7 +383,7 @@ struct Operation {
|
||||
route @9 :OperationRoute;
|
||||
|
||||
# Routable operations
|
||||
getValueQ @10 :OperationGetValueQ;
|
||||
getValueQ @10 :OperationGetValueQ;
|
||||
getValueA @11 :OperationGetValueA;
|
||||
setValueQ @12 :OperationSetValueQ;
|
||||
setValueA @13 :OperationSetValueA;
|
||||
|
@ -88,8 +88,8 @@ impl Network {
|
||||
let (connection_initial_timeout, tls_connection_initial_timeout) = {
|
||||
let c = self.config.get();
|
||||
(
|
||||
c.network.connection_initial_timeout,
|
||||
c.network.tls.connection_initial_timeout,
|
||||
ms_to_us(c.network.connection_initial_timeout_ms),
|
||||
ms_to_us(c.network.tls.connection_initial_timeout_ms),
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -106,9 +106,9 @@ impl WebsocketProtocolHandler {
|
||||
format!("GET /{}", c.network.protocol.wss.path.trim_end_matches('/'))
|
||||
};
|
||||
let connection_initial_timeout = if tls {
|
||||
c.network.tls.connection_initial_timeout
|
||||
ms_to_us(c.network.tls.connection_initial_timeout_ms)
|
||||
} else {
|
||||
c.network.connection_initial_timeout
|
||||
ms_to_us(c.network.connection_initial_timeout_ms)
|
||||
};
|
||||
|
||||
Self {
|
||||
|
@ -504,8 +504,8 @@ impl NetworkManager {
|
||||
let (tsbehind, tsahead) = {
|
||||
let c = self.config.get();
|
||||
(
|
||||
c.network.rpc.max_timestamp_behind,
|
||||
c.network.rpc.max_timestamp_ahead,
|
||||
c.network.rpc.max_timestamp_behind_ms.map(ms_to_us),
|
||||
c.network.rpc.max_timestamp_ahead_ms.map(ms_to_us),
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -92,7 +92,7 @@ impl RoutingTable {
|
||||
RoutingTableUnlockedInner {
|
||||
rolling_transfers_task: TickTask::new(ROLLING_TRANSFERS_INTERVAL_SECS),
|
||||
bootstrap_task: TickTask::new(1),
|
||||
peer_minimum_refresh_task: TickTask::new_us(c.network.dht.min_peer_refresh_time),
|
||||
peer_minimum_refresh_task: TickTask::new_ms(c.network.dht.min_peer_refresh_time_ms),
|
||||
ping_validator_task: TickTask::new(1),
|
||||
}
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ impl RPCProcessor {
|
||||
(
|
||||
c.network.dht.resolve_node_count,
|
||||
c.network.dht.resolve_node_fanout,
|
||||
c.network.dht.resolve_node_timeout,
|
||||
c.network.dht.resolve_node_timeout_ms.map(ms_to_us),
|
||||
)
|
||||
};
|
||||
|
||||
@ -1266,7 +1266,7 @@ impl RPCProcessor {
|
||||
// set up channel
|
||||
let mut concurrency = c.network.rpc.concurrency;
|
||||
let mut queue_size = c.network.rpc.queue_size;
|
||||
let mut timeout = c.network.rpc.timeout;
|
||||
let mut timeout = ms_to_us(c.network.rpc.timeout_ms);
|
||||
let mut max_route_hop_count = c.network.rpc.max_route_hop_count as usize;
|
||||
if concurrency == 0 {
|
||||
concurrency = get_concurrency() / 2;
|
||||
@ -1411,12 +1411,13 @@ impl RPCProcessor {
|
||||
alternate_port: bool,
|
||||
) -> Result<bool, RPCError> {
|
||||
let network_manager = self.network_manager();
|
||||
let receipt_time = self
|
||||
.config
|
||||
.get()
|
||||
.network
|
||||
.dht
|
||||
.validate_dial_info_receipt_time;
|
||||
let receipt_time = ms_to_us(
|
||||
self.config
|
||||
.get()
|
||||
.network
|
||||
.dht
|
||||
.validate_dial_info_receipt_time_ms,
|
||||
);
|
||||
//
|
||||
let (vdi_msg, eventual_value) = {
|
||||
let mut vdi_msg = ::capnp::message::Builder::new_default();
|
||||
|
@ -191,36 +191,36 @@ pub fn config_callback(key: String) -> ConfigCallbackReturn {
|
||||
"protected_store.insecure_fallback_directory" => Ok(Box::new(get_protected_store_path())),
|
||||
"protected_store.delete" => Ok(Box::new(false)),
|
||||
"network.max_connections" => Ok(Box::new(16u32)),
|
||||
"network.connection_initial_timeout" => Ok(Box::new(2_000_000u64)),
|
||||
"network.connection_initial_timeout_ms" => Ok(Box::new(2_000u32)),
|
||||
"network.node_id" => Ok(Box::new(dht::key::DHTKey::default())),
|
||||
"network.node_id_secret" => Ok(Box::new(dht::key::DHTKeySecret::default())),
|
||||
"network.bootstrap" => Ok(Box::new(vec![String::from("asdf"), String::from("qwer")])),
|
||||
"network.rpc.concurrency" => Ok(Box::new(2u32)),
|
||||
"network.rpc.queue_size" => Ok(Box::new(128u32)),
|
||||
"network.rpc.max_timestamp_behind" => Ok(Box::new(Some(10_000_000u64))),
|
||||
"network.rpc.max_timestamp_ahead" => Ok(Box::new(Some(10_000_000u64))),
|
||||
"network.rpc.timeout" => Ok(Box::new(10_000_000u64)),
|
||||
"network.rpc.max_timestamp_behind_ms" => Ok(Box::new(Some(10_000u32))),
|
||||
"network.rpc.max_timestamp_ahead_ms" => Ok(Box::new(Some(10_000u32))),
|
||||
"network.rpc.timeout_ms" => Ok(Box::new(10_000u32)),
|
||||
"network.rpc.max_route_hop_count" => Ok(Box::new(7u8)),
|
||||
"network.dht.resolve_node_timeout" => Ok(Box::new(Option::<u64>::None)),
|
||||
"network.dht.resolve_node_timeout_ms" => Ok(Box::new(Option::<u32>::None)),
|
||||
"network.dht.resolve_node_count" => Ok(Box::new(20u32)),
|
||||
"network.dht.resolve_node_fanout" => Ok(Box::new(3u32)),
|
||||
"network.dht.max_find_node_count" => Ok(Box::new(20u32)),
|
||||
"network.dht.get_value_timeout" => Ok(Box::new(Option::<u64>::None)),
|
||||
"network.dht.get_value_timeout_ms" => Ok(Box::new(Option::<u32>::None)),
|
||||
"network.dht.get_value_count" => Ok(Box::new(20u32)),
|
||||
"network.dht.get_value_fanout" => Ok(Box::new(3u32)),
|
||||
"network.dht.set_value_timeout" => Ok(Box::new(Option::<u64>::None)),
|
||||
"network.dht.set_value_timeout_ms" => Ok(Box::new(Option::<u32>::None)),
|
||||
"network.dht.set_value_count" => Ok(Box::new(20u32)),
|
||||
"network.dht.set_value_fanout" => Ok(Box::new(5u32)),
|
||||
"network.dht.min_peer_count" => Ok(Box::new(20u32)),
|
||||
"network.dht.min_peer_refresh_time" => Ok(Box::new(2000000u64)),
|
||||
"network.dht.validate_dial_info_receipt_time" => Ok(Box::new(5000000u64)),
|
||||
"network.dht.min_peer_refresh_time_ms" => Ok(Box::new(2_000u32)),
|
||||
"network.dht.validate_dial_info_receipt_time_ms" => Ok(Box::new(5_000u32)),
|
||||
"network.upnp" => Ok(Box::new(false)),
|
||||
"network.natpmp" => Ok(Box::new(false)),
|
||||
"network.enable_local_peer_scope" => Ok(Box::new(false)),
|
||||
"network.restricted_nat_retries" => Ok(Box::new(3u32)),
|
||||
"network.tls.certificate_path" => Ok(Box::new(get_certfile_path())),
|
||||
"network.tls.private_key_path" => Ok(Box::new(get_keyfile_path())),
|
||||
"network.tls.connection_initial_timeout" => Ok(Box::new(2_000_000u64)),
|
||||
"network.tls.connection_initial_timeout_ms" => Ok(Box::new(2_000u32)),
|
||||
"network.application.https.enabled" => Ok(Box::new(false)),
|
||||
"network.application.https.listen_address" => Ok(Box::new(String::from("[::1]:5150"))),
|
||||
"network.application.https.path" => Ok(Box::new(String::from("app"))),
|
||||
@ -294,7 +294,7 @@ pub async fn test_config() {
|
||||
);
|
||||
assert_eq!(inner.protected_store.delete, false);
|
||||
assert_eq!(inner.network.max_connections, 16);
|
||||
assert_eq!(inner.network.connection_initial_timeout, 2_000_000u64);
|
||||
assert_eq!(inner.network.connection_initial_timeout_ms, 2_000u32);
|
||||
assert!(!inner.network.node_id.valid);
|
||||
assert!(!inner.network.node_id_secret.valid);
|
||||
assert_eq!(
|
||||
@ -303,22 +303,25 @@ pub async fn test_config() {
|
||||
);
|
||||
assert_eq!(inner.network.rpc.concurrency, 2u32);
|
||||
assert_eq!(inner.network.rpc.queue_size, 128u32);
|
||||
assert_eq!(inner.network.rpc.timeout, 10_000_000u64);
|
||||
assert_eq!(inner.network.rpc.timeout_ms, 10_000u32);
|
||||
assert_eq!(inner.network.rpc.max_route_hop_count, 7u8);
|
||||
assert_eq!(inner.network.dht.resolve_node_timeout, Option::<u64>::None);
|
||||
assert_eq!(
|
||||
inner.network.dht.resolve_node_timeout_ms,
|
||||
Option::<u32>::None
|
||||
);
|
||||
assert_eq!(inner.network.dht.resolve_node_count, 20u32);
|
||||
assert_eq!(inner.network.dht.resolve_node_fanout, 3u32);
|
||||
assert_eq!(inner.network.dht.get_value_timeout, Option::<u64>::None);
|
||||
assert_eq!(inner.network.dht.get_value_timeout_ms, Option::<u32>::None);
|
||||
assert_eq!(inner.network.dht.get_value_count, 20u32);
|
||||
assert_eq!(inner.network.dht.get_value_fanout, 3u32);
|
||||
assert_eq!(inner.network.dht.set_value_timeout, Option::<u64>::None);
|
||||
assert_eq!(inner.network.dht.set_value_timeout_ms, Option::<u32>::None);
|
||||
assert_eq!(inner.network.dht.set_value_count, 20u32);
|
||||
assert_eq!(inner.network.dht.set_value_fanout, 5u32);
|
||||
assert_eq!(inner.network.dht.min_peer_count, 20u32);
|
||||
assert_eq!(inner.network.dht.min_peer_refresh_time, 2000000u64);
|
||||
assert_eq!(inner.network.dht.min_peer_refresh_time_ms, 2_000u32);
|
||||
assert_eq!(
|
||||
inner.network.dht.validate_dial_info_receipt_time,
|
||||
5000000u64
|
||||
inner.network.dht.validate_dial_info_receipt_time_ms,
|
||||
5_000u32
|
||||
);
|
||||
|
||||
assert_eq!(inner.network.upnp, false);
|
||||
@ -327,7 +330,7 @@ pub async fn test_config() {
|
||||
assert_eq!(inner.network.restricted_nat_retries, 3u32);
|
||||
assert_eq!(inner.network.tls.certificate_path, get_certfile_path());
|
||||
assert_eq!(inner.network.tls.private_key_path, get_keyfile_path());
|
||||
assert_eq!(inner.network.tls.connection_initial_timeout, 2_000_000u64);
|
||||
assert_eq!(inner.network.tls.connection_initial_timeout_ms, 2_000u32);
|
||||
|
||||
assert_eq!(inner.network.application.https.enabled, false);
|
||||
assert_eq!(inner.network.application.https.listen_address, "[::1]:5150");
|
||||
|
@ -1196,7 +1196,7 @@ impl VeilidAPI {
|
||||
(
|
||||
c.network.dht.resolve_node_count,
|
||||
c.network.dht.resolve_node_fanout,
|
||||
c.network.dht.resolve_node_timeout,
|
||||
c.network.dht.resolve_node_timeout_ms.map(ms_to_us),
|
||||
)
|
||||
};
|
||||
|
||||
@ -1224,7 +1224,7 @@ impl VeilidAPI {
|
||||
(
|
||||
c.network.dht.resolve_node_count,
|
||||
c.network.dht.resolve_node_fanout,
|
||||
c.network.dht.resolve_node_timeout,
|
||||
c.network.dht.resolve_node_timeout_ms.map(ms_to_us),
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -84,33 +84,33 @@ pub struct VeilidConfigProtocol {
|
||||
pub struct VeilidConfigTLS {
|
||||
pub certificate_path: String,
|
||||
pub private_key_path: String,
|
||||
pub connection_initial_timeout: u64,
|
||||
pub connection_initial_timeout_ms: u32,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct VeilidConfigDHT {
|
||||
pub resolve_node_timeout: Option<u64>,
|
||||
pub resolve_node_timeout_ms: Option<u32>,
|
||||
pub resolve_node_count: u32,
|
||||
pub resolve_node_fanout: u32,
|
||||
pub max_find_node_count: u32,
|
||||
pub get_value_timeout: Option<u64>,
|
||||
pub get_value_timeout_ms: Option<u32>,
|
||||
pub get_value_count: u32,
|
||||
pub get_value_fanout: u32,
|
||||
pub set_value_timeout: Option<u64>,
|
||||
pub set_value_timeout_ms: Option<u32>,
|
||||
pub set_value_count: u32,
|
||||
pub set_value_fanout: u32,
|
||||
pub min_peer_count: u32,
|
||||
pub min_peer_refresh_time: u64,
|
||||
pub validate_dial_info_receipt_time: u64,
|
||||
pub min_peer_refresh_time_ms: u32,
|
||||
pub validate_dial_info_receipt_time_ms: u32,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct VeilidConfigRPC {
|
||||
pub concurrency: u32,
|
||||
pub queue_size: u32,
|
||||
pub max_timestamp_behind: Option<u64>,
|
||||
pub max_timestamp_ahead: Option<u64>,
|
||||
pub timeout: u64,
|
||||
pub max_timestamp_behind_ms: Option<u32>,
|
||||
pub max_timestamp_ahead_ms: Option<u32>,
|
||||
pub timeout_ms: u32,
|
||||
pub max_route_hop_count: u8,
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ pub struct VeilidConfigLeases {
|
||||
#[derive(Default, Clone)]
|
||||
pub struct VeilidConfigNetwork {
|
||||
pub max_connections: u32,
|
||||
pub connection_initial_timeout: u64,
|
||||
pub connection_initial_timeout_ms: u32,
|
||||
pub node_id: key::DHTKey,
|
||||
pub node_id_secret: key::DHTKeySecret,
|
||||
pub bootstrap: Vec<String>,
|
||||
@ -238,26 +238,26 @@ impl VeilidConfig {
|
||||
get_config!(inner.network.node_id);
|
||||
get_config!(inner.network.node_id_secret);
|
||||
get_config!(inner.network.max_connections);
|
||||
get_config!(inner.network.connection_initial_timeout);
|
||||
get_config!(inner.network.connection_initial_timeout_ms);
|
||||
get_config!(inner.network.bootstrap);
|
||||
get_config!(inner.network.dht.resolve_node_timeout);
|
||||
get_config!(inner.network.dht.resolve_node_timeout_ms);
|
||||
get_config!(inner.network.dht.resolve_node_count);
|
||||
get_config!(inner.network.dht.resolve_node_fanout);
|
||||
get_config!(inner.network.dht.max_find_node_count);
|
||||
get_config!(inner.network.dht.get_value_timeout);
|
||||
get_config!(inner.network.dht.get_value_timeout_ms);
|
||||
get_config!(inner.network.dht.get_value_count);
|
||||
get_config!(inner.network.dht.get_value_fanout);
|
||||
get_config!(inner.network.dht.set_value_timeout);
|
||||
get_config!(inner.network.dht.set_value_timeout_ms);
|
||||
get_config!(inner.network.dht.set_value_count);
|
||||
get_config!(inner.network.dht.set_value_fanout);
|
||||
get_config!(inner.network.dht.min_peer_count);
|
||||
get_config!(inner.network.dht.min_peer_refresh_time);
|
||||
get_config!(inner.network.dht.validate_dial_info_receipt_time);
|
||||
get_config!(inner.network.dht.min_peer_refresh_time_ms);
|
||||
get_config!(inner.network.dht.validate_dial_info_receipt_time_ms);
|
||||
get_config!(inner.network.rpc.concurrency);
|
||||
get_config!(inner.network.rpc.queue_size);
|
||||
get_config!(inner.network.rpc.max_timestamp_behind);
|
||||
get_config!(inner.network.rpc.max_timestamp_ahead);
|
||||
get_config!(inner.network.rpc.timeout);
|
||||
get_config!(inner.network.rpc.max_timestamp_behind_ms);
|
||||
get_config!(inner.network.rpc.max_timestamp_ahead_ms);
|
||||
get_config!(inner.network.rpc.timeout_ms);
|
||||
get_config!(inner.network.rpc.max_route_hop_count);
|
||||
get_config!(inner.network.upnp);
|
||||
get_config!(inner.network.natpmp);
|
||||
@ -265,7 +265,7 @@ impl VeilidConfig {
|
||||
get_config!(inner.network.restricted_nat_retries);
|
||||
get_config!(inner.network.tls.certificate_path);
|
||||
get_config!(inner.network.tls.private_key_path);
|
||||
get_config!(inner.network.tls.connection_initial_timeout);
|
||||
get_config!(inner.network.tls.connection_initial_timeout_ms);
|
||||
get_config!(inner.network.application.https.enabled);
|
||||
get_config!(inner.network.application.https.listen_address);
|
||||
get_config!(inner.network.application.https.path);
|
||||
|
@ -32,6 +32,14 @@ impl TickTask {
|
||||
single_future: SingleFuture::new(),
|
||||
}
|
||||
}
|
||||
pub fn new_ms(tick_period_ms: u32) -> Self {
|
||||
Self {
|
||||
last_timestamp_us: AtomicU64::new(0),
|
||||
tick_period_us: (tick_period_ms as u64) * 1000u64,
|
||||
routine: OnceCell::new(),
|
||||
single_future: SingleFuture::new(),
|
||||
}
|
||||
}
|
||||
pub fn new(tick_period_sec: u32) -> Self {
|
||||
Self {
|
||||
last_timestamp_us: AtomicU64::new(0),
|
||||
|
@ -41,6 +41,10 @@ pub fn secs_to_timestamp(secs: f64) -> u64 {
|
||||
(secs * 1000000.0f64) as u64
|
||||
}
|
||||
|
||||
pub fn ms_to_us(ms: u32) -> u64 {
|
||||
(ms as u64) * 1000u64
|
||||
}
|
||||
|
||||
// Calculate retry attempt with logarhythmic falloff
|
||||
pub fn retry_falloff_log(
|
||||
last_us: u64,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,130 +1,45 @@
|
||||
use std::sync::Arc;
|
||||
use flutter_rust_bridge::*;
|
||||
use log::*;
|
||||
use std::collections::HashMap;
|
||||
use async_std::sync::Mutex as AsyncMutex;
|
||||
use anyhow::*;
|
||||
use std::fmt;
|
||||
|
||||
// Globals
|
||||
|
||||
static API: AsyncMutex<Option<veilid_core::VeilidAPI>> = AsyncMutex::new(None);
|
||||
static VEILID_API: AsyncMutex<Option<veilid_core::VeilidAPI>> = AsyncMutex::new(None);
|
||||
async fn get_veilid_api() -> Result<veilid_core::VeilidAPI> {
|
||||
let api_lock = VEILID_API.lock().await;
|
||||
let veilid_api = match &*api_lock {
|
||||
None => {
|
||||
return Err(anyhow!(VeilidAPIError::NotInitialized));
|
||||
}
|
||||
Some(api) => {
|
||||
api.clone()
|
||||
}
|
||||
};
|
||||
Ok(veilid_api)
|
||||
}
|
||||
async fn take_veilid_api() -> Result<veilid_core::VeilidAPI> {
|
||||
let mut api_lock = VEILID_API.lock().await;
|
||||
let veilid_api = match api_lock.take() {
|
||||
None => {
|
||||
return Err(anyhow!(VeilidAPIError::NotInitialized));
|
||||
}
|
||||
Some(api) => {
|
||||
api
|
||||
}
|
||||
};
|
||||
Ok(veilid_api)
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////
|
||||
// Config Settings
|
||||
// Not all settings available through Veilid API are available to Flutter applications
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct VeilidConfigUDP {
|
||||
pub enabled: bool,
|
||||
pub socket_pool_size: u32,
|
||||
pub listen_address: String,
|
||||
pub public_address: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct VeilidConfigTCP {
|
||||
pub connect: bool,
|
||||
pub listen: bool,
|
||||
pub max_connections: u32,
|
||||
pub listen_address: String,
|
||||
pub public_address: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct VeilidConfigWS {
|
||||
pub connect: bool,
|
||||
pub listen: bool,
|
||||
pub max_connections: u32,
|
||||
pub listen_address: String,
|
||||
pub path: String,
|
||||
pub url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct VeilidConfigWSS {
|
||||
pub connect: bool,
|
||||
pub max_connections: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct VeilidConfigProtocol {
|
||||
pub udp: VeilidConfigUDP,
|
||||
pub tcp: VeilidConfigTCP,
|
||||
pub ws: VeilidConfigWS,
|
||||
pub wss: VeilidConfigWSS,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct VeilidConfigDHT {
|
||||
pub resolve_node_timeout: Option<u64>,
|
||||
pub resolve_node_count: u32,
|
||||
pub resolve_node_fanout: u32,
|
||||
pub max_find_node_count: u32,
|
||||
pub get_value_timeout: Option<u64>,
|
||||
pub get_value_count: u32,
|
||||
pub get_value_fanout: u32,
|
||||
pub set_value_timeout: Option<u64>,
|
||||
pub set_value_count: u32,
|
||||
pub set_value_fanout: u32,
|
||||
pub min_peer_count: u32,
|
||||
pub min_peer_refresh_time: u64,
|
||||
pub validate_dial_info_receipt_time: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct VeilidConfigRPC {
|
||||
pub concurrency: u32,
|
||||
pub queue_size: u32,
|
||||
pub max_timestamp_behind: Option<u64>,
|
||||
pub max_timestamp_ahead: Option<u64>,
|
||||
pub timeout: u64,
|
||||
pub max_route_hop_count: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct VeilidConfigLeases {
|
||||
pub max_server_signal_leases: u32,
|
||||
pub max_server_relay_leases: u32,
|
||||
pub max_client_signal_leases: u32,
|
||||
pub max_client_relay_leases: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct VeilidConfigNetwork {
|
||||
pub max_connections: u32,
|
||||
pub connection_initial_timeout: u64,
|
||||
pub node_id: String,
|
||||
pub node_id_secret: String,
|
||||
pub bootstrap: Vec<String>,
|
||||
pub rpc: VeilidConfigRPC,
|
||||
pub dht: VeilidConfigDHT,
|
||||
pub upnp: bool,
|
||||
pub natpmp: bool,
|
||||
pub enable_local_peer_scope: bool,
|
||||
pub restricted_nat_retries: u32,
|
||||
pub protocol: VeilidConfigProtocol,
|
||||
pub leases: VeilidConfigLeases,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct VeilidConfigTableStore {
|
||||
pub directory: String,
|
||||
pub delete: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct VeilidConfigBlockStore {
|
||||
pub directory: String,
|
||||
pub delete: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct VeilidConfigProtectedStore {
|
||||
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
#[allow(non_snake_case)]
|
||||
pub struct VeilidConfig {
|
||||
pub program_name: String,
|
||||
pub namespace: String,
|
||||
@ -142,15 +57,164 @@ pub struct VeilidConfig {
|
||||
pub protected_store__insecure_fallback_directory: String,
|
||||
pub protected_store__delete: bool,
|
||||
// Table Store
|
||||
pub table_store: VeilidConfigTableStore,
|
||||
pub table_store__directory: String,
|
||||
pub table_store__delete: bool,
|
||||
// Block Store
|
||||
pub block_store: VeilidConfigBlockStore,
|
||||
pub block_store__directory: String,
|
||||
pub block_store__delete: bool,
|
||||
// Network
|
||||
pub network: VeilidConfigNetwork,
|
||||
pub network__max_connections: u32,
|
||||
pub network__connection_initial_timeout_ms: u32,
|
||||
pub network__node_id: String,
|
||||
pub network__node_id_secret: String,
|
||||
pub network__bootstrap: Vec<String>,
|
||||
pub network__upnp: bool,
|
||||
pub network__natpmp: bool,
|
||||
pub network__enable_local_peer_scope: bool,
|
||||
pub network__restricted_nat_retries: u32,
|
||||
// Network / RPC
|
||||
pub network__rpc__concurrency: u32,
|
||||
pub network__rpc__queue_size: u32,
|
||||
pub network__rpc__max_timestamp_behind_ms: Option<u32>,
|
||||
pub network__rpc__max_timestamp_ahead_ms: Option<u32>,
|
||||
pub network__rpc__timeout_ms: u32,
|
||||
pub network__rpc__max_route_hop_count: u8,
|
||||
// Network / DHT
|
||||
pub network__dht__resolve_node_timeout_ms: Option<u32>,
|
||||
pub network__dht__resolve_node_count: u32,
|
||||
pub network__dht__resolve_node_fanout: u32,
|
||||
pub network__dht__max_find_node_count: u32,
|
||||
pub network__dht__get_value_timeout_ms: Option<u32>,
|
||||
pub network__dht__get_value_count: u32,
|
||||
pub network__dht__get_value_fanout: u32,
|
||||
pub network__dht__set_value_timeout_ms: Option<u32>,
|
||||
pub network__dht__set_value_count: u32,
|
||||
pub network__dht__set_value_fanout: u32,
|
||||
pub network__dht__min_peer_count: u32,
|
||||
pub network__dht__min_peer_refresh_time_ms: u32,
|
||||
pub network__dht__validate_dial_info_receipt_time_ms: u32,
|
||||
// Network / Protocol
|
||||
// Network / Protocol / UDP
|
||||
pub network__protocol__udp__enabled: bool,
|
||||
pub network__protocol__udp__socket_pool_size: u32,
|
||||
pub network__protocol__udp__listen_address: String,
|
||||
pub network__protocol__udp__public_address: Option<String>,
|
||||
// Network / Protocol / TCP
|
||||
pub network__protocol__tcp__connect: bool,
|
||||
pub network__protocol__tcp__listen: bool,
|
||||
pub network__protocol__tcp__max_connections: u32,
|
||||
pub network__protocol__tcp__listen_address: String,
|
||||
pub network__protocol__tcp__public_address: Option<String>,
|
||||
// Network / Protocol / WS
|
||||
pub network__protocol__ws__connect: bool,
|
||||
pub network__protocol__ws__listen: bool,
|
||||
pub network__protocol__ws__max_connections: u32,
|
||||
pub network__protocol__ws__listen_address: String,
|
||||
pub network__protocol__ws__path: String,
|
||||
pub network__protocol__ws__url: Option<String>,
|
||||
// Network / Protocol / WSS
|
||||
pub network__protocol__wss__connect: bool,
|
||||
pub network__protocol__wss__max_connections: u32,
|
||||
// Network / Leases
|
||||
pub network__leases__max_server_signal_leases: u32,
|
||||
pub network__leases__max_server_relay_leases: u32,
|
||||
pub network__leases__max_client_signal_leases: u32,
|
||||
pub network__leases__max_client_relay_leases: u32,
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
|
||||
impl VeilidConfig {
|
||||
pub fn get_by_str(&self, key: &str) -> std::result::Result<Box<dyn std::any::Any + Send + 'static>, String> {
|
||||
let out: Box<dyn core::any::Any + Send> = match key {
|
||||
"program_name" => Box::new(self.program_name.clone()),
|
||||
"namespace" => Box::new(self.namespace.clone()),
|
||||
"capabilities.protocol_udp" => Box::new(self.capabilities__protocol_udp.clone()),
|
||||
"capabilities.protocol_connect_tcp" => Box::new(self.capabilities__protocol_connect_tcp.clone()),
|
||||
"capabilities.protocol_accept_tcp" => Box::new(self.capabilities__protocol_accept_tcp.clone()),
|
||||
"capabilities.protocol_connect_ws" => Box::new(self.capabilities__protocol_connect_ws.clone()),
|
||||
"capabilities.protocol_accept_ws" => Box::new(self.capabilities__protocol_accept_ws.clone()),
|
||||
"capabilities.protocol_connect_wss" => Box::new(self.capabilities__protocol_connect_wss.clone()),
|
||||
"capabilities.protocol_accept_wss" => Box::new(self.capabilities__protocol_accept_wss.clone()),
|
||||
"table_store.directory" => Box::new(self.table_store__directory.clone()),
|
||||
"table_store.delete" => Box::new(self.table_store__delete.clone()),
|
||||
"block_store.directory" => Box::new(self.block_store__directory.clone()),
|
||||
"block_store.delete" => Box::new(self.block_store__delete.clone()),
|
||||
"protected_store.allow_insecure_fallback" => Box::new(self.protected_store__allow_insecure_fallback.clone()),
|
||||
"protected_store.always_use_insecure_storage" => Box::new(self.protected_store__always_use_insecure_storage.clone()),
|
||||
"protected_store.insecure_fallback_directory" => Box::new(self.protected_store__insecure_fallback_directory.clone()),
|
||||
"protected_store.delete" => Box::new(self.protected_store__delete.clone()),
|
||||
"network.node_id" => Box::new(self.network__node_id.clone()),
|
||||
"network.node_id_secret" => Box::new(self.network__node_id_secret.clone()),
|
||||
"network.max_connections" => Box::new(self.network__max_connections.clone()),
|
||||
"network.connection_initial_timeout_ms" => Box::new(self.network__connection_initial_timeout_ms.clone()),
|
||||
"network.bootstrap" => Box::new(self.network__bootstrap.clone()),
|
||||
"network.dht.resolve_node_timeout_ms" => Box::new(self.network__dht__resolve_node_timeout_ms.clone()),
|
||||
"network.dht.resolve_node_count" => Box::new(self.network__dht__resolve_node_count.clone()),
|
||||
"network.dht.resolve_node_fanout" => Box::new(self.network__dht__resolve_node_fanout.clone()),
|
||||
"network.dht.max_find_node_count" => Box::new(self.network__dht__max_find_node_count.clone()),
|
||||
"network.dht.get_value_timeout_ms" => Box::new(self.network__dht__get_value_timeout_ms.clone()),
|
||||
"network.dht.get_value_count" => Box::new(self.network__dht__get_value_count.clone()),
|
||||
"network.dht.get_value_fanout" => Box::new(self.network__dht__get_value_fanout.clone()),
|
||||
"network.dht.set_value_timeout_ms" => Box::new(self.network__dht__set_value_timeout_ms.clone()),
|
||||
"network.dht.set_value_count" => Box::new(self.network__dht__set_value_count.clone()),
|
||||
"network.dht.set_value_fanout" => Box::new(self.network__dht__set_value_fanout.clone()),
|
||||
"network.dht.min_peer_count" => Box::new(self.network__dht__min_peer_count.clone()),
|
||||
"network.dht.min_peer_refresh_time_ms" => Box::new(self.network__dht__min_peer_refresh_time_ms.clone()),
|
||||
"network.dht.validate_dial_info_receipt_time_ms" => Box::new(self.network__dht__validate_dial_info_receipt_time_ms.clone()),
|
||||
"network.rpc.concurrency" => Box::new(self.network__rpc__concurrency.clone()),
|
||||
"network.rpc.queue_size" => Box::new(self.network__rpc__queue_size.clone()),
|
||||
"network.rpc.max_timestamp_behind_ms" => Box::new(self.network__rpc__max_timestamp_behind_ms.clone()),
|
||||
"network.rpc.max_timestamp_ahead_ms" => Box::new(self.network__rpc__max_timestamp_ahead_ms.clone()),
|
||||
"network.rpc.timeout_ms" => Box::new(self.network__rpc__timeout_ms.clone()),
|
||||
"network.rpc.max_route_hop_count" => Box::new(self.network__rpc__max_route_hop_count.clone()),
|
||||
"network.upnp" => Box::new(self.network__upnp.clone()),
|
||||
"network.natpmp" => Box::new(self.network__natpmp.clone()),
|
||||
"network.enable_local_peer_scope" => Box::new(self.network__enable_local_peer_scope.clone()),
|
||||
"network.restricted_nat_retries" => Box::new(self.network__restricted_nat_retries.clone()),
|
||||
"network.tls.certificate_path" => Box::new("".to_owned()),
|
||||
"network.tls.private_key_path" => Box::new("".to_owned()),
|
||||
"network.tls.connection_initial_timeout" => Box::new(0u32),
|
||||
"network.application.https.enabled" => Box::new(false),
|
||||
"network.application.https.listen_address" => Box::new("".to_owned()),
|
||||
"network.application.https.path" => Box::new("".to_owned()),
|
||||
"network.application.https.url" => Box::new(Option::<String>::None),
|
||||
"network.application.http.enabled" => Box::new(false),
|
||||
"network.application.http.listen_address" => Box::new("".to_owned()),
|
||||
"network.application.http.path" => Box::new("".to_owned()),
|
||||
"network.application.http.url" => Box::new(Option::<String>::None),
|
||||
"network.protocol.udp.enabled" => Box::new(self.network__protocol__udp__enabled.clone()),
|
||||
"network.protocol.udp.socket_pool_size" => Box::new(self.network__protocol__udp__socket_pool_size.clone()),
|
||||
"network.protocol.udp.listen_address" => Box::new(self.network__protocol__udp__listen_address.clone()),
|
||||
"network.protocol.udp.public_address" => Box::new(self.network__protocol__udp__public_address.clone()),
|
||||
"network.protocol.tcp.connect" => Box::new(self.network__protocol__tcp__connect.clone()),
|
||||
"network.protocol.tcp.listen" => Box::new(self.network__protocol__tcp__listen.clone()),
|
||||
"network.protocol.tcp.max_connections" => Box::new(self.network__protocol__tcp__max_connections.clone()),
|
||||
"network.protocol.tcp.listen_address" => Box::new(self.network__protocol__tcp__listen_address.clone()),
|
||||
"network.protocol.tcp.public_address" => Box::new(self.network__protocol__tcp__public_address.clone()),
|
||||
"network.protocol.ws.connect" => Box::new(self.network__protocol__ws__connect.clone()),
|
||||
"network.protocol.ws.listen" => Box::new(self.network__protocol__ws__listen.clone()),
|
||||
"network.protocol.ws.max_connections" => Box::new(self.network__protocol__ws__max_connections.clone()),
|
||||
"network.protocol.ws.listen_address" => Box::new(self.network__protocol__ws__listen_address.clone()),
|
||||
"network.protocol.ws.path" => Box::new(self.network__protocol__ws__path.clone()),
|
||||
"network.protocol.ws.url" => Box::new(self.network__protocol__ws__url.clone()),
|
||||
"network.protocol.wss.connect" => Box::new(self.network__protocol__wss__connect.clone()),
|
||||
"network.protocol.wss.listen" => Box::new(false),
|
||||
"network.protocol.wss.max_connections" => Box::new(self.network__protocol__wss__max_connections.clone()),
|
||||
"network.protocol.wss.listen_address" => Box::new("".to_owned()),
|
||||
"network.protocol.wss.path" => Box::new("".to_owned()),
|
||||
"network.protocol.wss.url" => Box::new(Option::<String>::None),
|
||||
"network.leases.max_server_signal_leases" => Box::new(self.network__leases__max_server_signal_leases.clone()),
|
||||
"network.leases.max_server_relay_leases" => Box::new(self.network__leases__max_server_relay_leases.clone()),
|
||||
"network.leases.max_client_signal_leases" => Box::new(self.network__leases__max_client_signal_leases.clone()),
|
||||
"network.leases.max_client_relay_leases" => Box::new(self.network__leases__max_client_relay_leases.clone()),
|
||||
_ => {
|
||||
let err = format!("config key '{}' doesn't exist", key);
|
||||
error!("{}",err);
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
std::result::Result::Ok(out)
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
|
||||
@ -235,7 +299,7 @@ impl VeilidAPIError {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum AttachmentState {
|
||||
Detached,
|
||||
Attaching,
|
||||
@ -251,19 +315,19 @@ impl AttachmentState {
|
||||
fn from_core(attachment_state: veilid_core::AttachmentState) -> Self {
|
||||
match attachment_state {
|
||||
veilid_core::AttachmentState::Detached => AttachmentState::Detached,
|
||||
veilid_core::AttachmentState::Attaching=> AttachmentState::Attaching,
|
||||
veilid_core::AttachmentState::AttachedWeak=> AttachmentState::AttachedWeak,
|
||||
veilid_core::AttachmentState::AttachedGood=> AttachmentState::AttachedGood,
|
||||
veilid_core::AttachmentState::AttachedStrong=> AttachmentState::AttachedStrong,
|
||||
veilid_core::AttachmentState::FullyAttached=> AttachmentState::FullyAttached,
|
||||
veilid_core::AttachmentState::OverAttached=> AttachmentState::OverAttached,
|
||||
veilid_core::AttachmentState::Detaching=> AttachmentState::Detaching,
|
||||
veilid_core::AttachmentState::Attaching => AttachmentState::Attaching,
|
||||
veilid_core::AttachmentState::AttachedWeak => AttachmentState::AttachedWeak,
|
||||
veilid_core::AttachmentState::AttachedGood => AttachmentState::AttachedGood,
|
||||
veilid_core::AttachmentState::AttachedStrong => AttachmentState::AttachedStrong,
|
||||
veilid_core::AttachmentState::FullyAttached => AttachmentState::FullyAttached,
|
||||
veilid_core::AttachmentState::OverAttached => AttachmentState::OverAttached,
|
||||
veilid_core::AttachmentState::Detaching => AttachmentState::Detaching,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum VeilidUpdate {
|
||||
Attachment (AttachmentState),
|
||||
}
|
||||
@ -277,7 +341,7 @@ impl VeilidUpdate {
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct VeilidState {
|
||||
pub attachment: AttachmentState,
|
||||
}
|
||||
@ -294,110 +358,17 @@ impl VeilidState {
|
||||
pub fn startup_veilid_core(sink: StreamSink<VeilidUpdate>, config: VeilidConfig) -> Result<VeilidState> {
|
||||
async_std::task::block_on( async {
|
||||
|
||||
let api = API.lock().await;
|
||||
if api.is_some() {
|
||||
let mut api_lock = VEILID_API.lock().await;
|
||||
if api_lock.is_some() {
|
||||
return Err(anyhow!(VeilidAPIError::AlreadyInitialized));
|
||||
}
|
||||
|
||||
let core = veilid_core::VeilidCore::new();
|
||||
|
||||
// convert config to hashmap
|
||||
let config_map = HashMap::<String, Box<dyn core::any::Any + Send + 'static>>::new();
|
||||
macro_rules! get_config {
|
||||
($key:expr) => {
|
||||
config_map.insert(stringify!($key)[7..].to_owned(), Box::new($key.clone()));
|
||||
}
|
||||
}
|
||||
macro_rules! default_config {
|
||||
($key:expr, $default_value:expr) => {
|
||||
config_map.insert(stringify!($key)[7..].to_owned(), Box::new($default_value));
|
||||
}
|
||||
}
|
||||
get_config!(config.program_name);
|
||||
get_config!(config.namespace);
|
||||
get_config!(config.capabilities.protocol_udp);
|
||||
get_config!(config.capabilities.protocol_connect_tcp);
|
||||
get_config!(config.capabilities.protocol_accept_tcp);
|
||||
get_config!(config.capabilities.protocol_connect_ws);
|
||||
get_config!(config.capabilities.protocol_accept_ws);
|
||||
get_config!(config.capabilities.protocol_connect_wss);
|
||||
get_config!(config.capabilities.protocol_accept_wss);
|
||||
get_config!(config.table_store.directory);
|
||||
get_config!(config.table_store.delete);
|
||||
get_config!(config.block_store.directory);
|
||||
get_config!(config.block_store.delete);
|
||||
get_config!(config.protected_store.allow_insecure_fallback);
|
||||
get_config!(config.protected_store.always_use_insecure_storage);
|
||||
get_config!(config.protected_store.insecure_fallback_directory);
|
||||
get_config!(config.protected_store.delete);
|
||||
get_config!(config.network.node_id);
|
||||
get_config!(config.network.node_id_secret);
|
||||
get_config!(config.network.max_connections);
|
||||
get_config!(config.network.connection_initial_timeout);
|
||||
get_config!(config.network.bootstrap);
|
||||
get_config!(config.network.dht.resolve_node_timeout);
|
||||
get_config!(config.network.dht.resolve_node_count);
|
||||
get_config!(config.network.dht.resolve_node_fanout);
|
||||
get_config!(config.network.dht.max_find_node_count);
|
||||
get_config!(config.network.dht.get_value_timeout);
|
||||
get_config!(config.network.dht.get_value_count);
|
||||
get_config!(config.network.dht.get_value_fanout);
|
||||
get_config!(config.network.dht.set_value_timeout);
|
||||
get_config!(config.network.dht.set_value_count);
|
||||
get_config!(config.network.dht.set_value_fanout);
|
||||
get_config!(config.network.dht.min_peer_count);
|
||||
get_config!(config.network.dht.min_peer_refresh_time);
|
||||
get_config!(config.network.dht.validate_dial_info_receipt_time);
|
||||
get_config!(config.network.rpc.concurrency);
|
||||
get_config!(config.network.rpc.queue_size);
|
||||
get_config!(config.network.rpc.max_timestamp_behind);
|
||||
get_config!(config.network.rpc.max_timestamp_ahead);
|
||||
get_config!(config.network.rpc.timeout);
|
||||
get_config!(config.network.rpc.max_route_hop_count);
|
||||
get_config!(config.network.upnp);
|
||||
get_config!(config.network.natpmp);
|
||||
get_config!(config.network.enable_local_peer_scope);
|
||||
get_config!(config.network.restricted_nat_retries);
|
||||
default_config!(config.network.tls.certificate_path, "");
|
||||
default_config!(config.network.tls.private_key_path, "");
|
||||
default_config!(config.network.tls.connection_initial_timeout, 0u64);
|
||||
default_config!(config.network.application.https.enabled, false);
|
||||
default_config!(config.network.application.https.listen_address, "");
|
||||
default_config!(config.network.application.https.path, "");
|
||||
default_config!(config.network.application.https.url, Option::<String>::None);
|
||||
default_config!(config.network.application.http.enabled, false);
|
||||
default_config!(config.network.application.http.listen_address, "");
|
||||
default_config!(config.network.application.http.path, "");
|
||||
default_config!(config.network.application.http.url, Option::<String>::None);
|
||||
get_config!(config.network.protocol.udp.enabled);
|
||||
get_config!(config.network.protocol.udp.socket_pool_size);
|
||||
get_config!(config.network.protocol.udp.listen_address);
|
||||
get_config!(config.network.protocol.udp.public_address);
|
||||
get_config!(config.network.protocol.tcp.connect);
|
||||
get_config!(config.network.protocol.tcp.listen);
|
||||
get_config!(config.network.protocol.tcp.max_connections);
|
||||
get_config!(config.network.protocol.tcp.listen_address);
|
||||
get_config!(config.network.protocol.tcp.public_address);
|
||||
get_config!(config.network.protocol.ws.connect);
|
||||
get_config!(config.network.protocol.ws.listen);
|
||||
get_config!(config.network.protocol.ws.max_connections);
|
||||
get_config!(config.network.protocol.ws.listen_address);
|
||||
get_config!(config.network.protocol.ws.path);
|
||||
get_config!(config.network.protocol.ws.url);
|
||||
get_config!(config.network.protocol.wss.connect);
|
||||
default_config!(config.network.protocol.wss.listen, false);
|
||||
get_config!(config.network.protocol.wss.max_connections);
|
||||
default_config!(config.network.protocol.wss.listen_address, "");
|
||||
default_config!(config.network.protocol.wss.path, "");
|
||||
default_config!(config.network.protocol.wss.url, Option::<String>::None);
|
||||
get_config!(config.network.leases.max_server_signal_leases);
|
||||
get_config!(config.network.leases.max_server_relay_leases);
|
||||
get_config!(config.network.leases.max_client_signal_leases);
|
||||
get_config!(config.network.leases.max_client_relay_leases);
|
||||
|
||||
let setup = veilid_core::VeilidCoreSetup {
|
||||
update_callback: Arc::new(
|
||||
move |update: veilid_core::VeilidUpdate| -> veilid_core::SystemPinBoxFuture<()> {
|
||||
let sink = sink.clone();
|
||||
Box::pin(async move {
|
||||
if !sink.add(VeilidUpdate::from_core(update)) {
|
||||
error!("error sending veilid update callback");
|
||||
@ -407,19 +378,13 @@ pub fn startup_veilid_core(sink: StreamSink<VeilidUpdate>, config: VeilidConfig)
|
||||
),
|
||||
config_callback: Arc::new(
|
||||
move |key| {
|
||||
config_map.get(&key).ok_or_else(|| {
|
||||
let err = format!("config key '{}' doesn't exist", key);
|
||||
error!("{}",err);
|
||||
err
|
||||
}).map(|v| {
|
||||
*v.clone()
|
||||
})
|
||||
config.get_by_str(&key)
|
||||
}
|
||||
),
|
||||
};
|
||||
|
||||
let veilid_api = core.startup(setup).await.map_err(|e| VeilidAPIError::InvalidConfig(e.clone()))?;
|
||||
*api = Some(veilid_api.clone());
|
||||
*api_lock = Some(veilid_api.clone());
|
||||
|
||||
let core_state = veilid_api.get_state().await.map_err(VeilidAPIError::from_core)?;
|
||||
Ok(VeilidState::from_core(core_state))
|
||||
@ -428,7 +393,7 @@ pub fn startup_veilid_core(sink: StreamSink<VeilidUpdate>, config: VeilidConfig)
|
||||
|
||||
pub fn get_veilid_state() -> Result<VeilidState> {
|
||||
async_std::task::block_on( async {
|
||||
let veilid_api = API.lock().await.ok_or(anyhow!(VeilidAPIError::NotInitialized))?;
|
||||
let veilid_api = get_veilid_api().await?;
|
||||
let core_state = veilid_api.get_state().await.map_err(VeilidAPIError::from_core)?;
|
||||
Ok(VeilidState::from_core(core_state))
|
||||
})
|
||||
@ -438,7 +403,7 @@ pub fn get_veilid_state() -> Result<VeilidState> {
|
||||
|
||||
pub fn shutdown_veilid_core() -> Result<()> {
|
||||
async_std::task::block_on( async {
|
||||
let veilid_api = API.lock().await.take().ok_or(anyhow!(VeilidAPIError::NotInitialized))?;
|
||||
let veilid_api = get_veilid_api().await?;
|
||||
veilid_api.shutdown().await;
|
||||
Ok(())
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user