From 7ef6d407a5b80f113031e1a906bb0b6d8f4e18c4 Mon Sep 17 00:00:00 2001 From: John Smith Date: Thu, 27 Jan 2022 09:53:01 -0500 Subject: [PATCH] api work --- veilid-core/proto/veilid.capnp | 2 +- .../src/intf/native/network/network_tcp.rs | 4 +- .../src/intf/native/network/protocol/ws.rs | 4 +- veilid-core/src/network_manager.rs | 4 +- veilid-core/src/routing_table/mod.rs | 2 +- veilid-core/src/rpc_processor/mod.rs | 17 +- .../src/tests/common/test_veilid_config.rs | 41 +- veilid-core/src/veilid_api/mod.rs | 4 +- veilid-core/src/veilid_config.rs | 40 +- veilid-core/src/xx/tick_task.rs | 8 + veilid-core/src/xx/tools.rs | 4 + veilid-flutter/lib/bridge_generated.dart | 1048 +++++++---------- veilid-flutter/rust/src/api.rs | 431 ++++--- 13 files changed, 702 insertions(+), 907 deletions(-) diff --git a/veilid-core/proto/veilid.capnp b/veilid-core/proto/veilid.capnp index caf9012e..2a4116c2 100644 --- a/veilid-core/proto/veilid.capnp +++ b/veilid-core/proto/veilid.capnp @@ -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; diff --git a/veilid-core/src/intf/native/network/network_tcp.rs b/veilid-core/src/intf/native/network/network_tcp.rs index 7edef9f1..8a666c7f 100644 --- a/veilid-core/src/intf/native/network/network_tcp.rs +++ b/veilid-core/src/intf/native/network/network_tcp.rs @@ -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), ) }; diff --git a/veilid-core/src/intf/native/network/protocol/ws.rs b/veilid-core/src/intf/native/network/protocol/ws.rs index 8104fcab..14dccaf6 100644 --- a/veilid-core/src/intf/native/network/protocol/ws.rs +++ b/veilid-core/src/intf/native/network/protocol/ws.rs @@ -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 { diff --git a/veilid-core/src/network_manager.rs b/veilid-core/src/network_manager.rs index 9b83c70b..233d4732 100644 --- a/veilid-core/src/network_manager.rs +++ b/veilid-core/src/network_manager.rs @@ -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), ) }; diff --git a/veilid-core/src/routing_table/mod.rs b/veilid-core/src/routing_table/mod.rs index c5582a2e..76696a6f 100644 --- a/veilid-core/src/routing_table/mod.rs +++ b/veilid-core/src/routing_table/mod.rs @@ -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), } } diff --git a/veilid-core/src/rpc_processor/mod.rs b/veilid-core/src/rpc_processor/mod.rs index c2d1db52..22a03ce7 100644 --- a/veilid-core/src/rpc_processor/mod.rs +++ b/veilid-core/src/rpc_processor/mod.rs @@ -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 { 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(); diff --git a/veilid-core/src/tests/common/test_veilid_config.rs b/veilid-core/src/tests/common/test_veilid_config.rs index 4d78e133..a115c6b0 100644 --- a/veilid-core/src/tests/common/test_veilid_config.rs +++ b/veilid-core/src/tests/common/test_veilid_config.rs @@ -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::::None)), + "network.dht.resolve_node_timeout_ms" => Ok(Box::new(Option::::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::::None)), + "network.dht.get_value_timeout_ms" => Ok(Box::new(Option::::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::::None)), + "network.dht.set_value_timeout_ms" => Ok(Box::new(Option::::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::::None); + assert_eq!( + inner.network.dht.resolve_node_timeout_ms, + Option::::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::::None); + assert_eq!(inner.network.dht.get_value_timeout_ms, Option::::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::::None); + assert_eq!(inner.network.dht.set_value_timeout_ms, Option::::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"); diff --git a/veilid-core/src/veilid_api/mod.rs b/veilid-core/src/veilid_api/mod.rs index bede52c7..a63d5136 100644 --- a/veilid-core/src/veilid_api/mod.rs +++ b/veilid-core/src/veilid_api/mod.rs @@ -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), ) }; diff --git a/veilid-core/src/veilid_config.rs b/veilid-core/src/veilid_config.rs index 9474398e..2887b23e 100644 --- a/veilid-core/src/veilid_config.rs +++ b/veilid-core/src/veilid_config.rs @@ -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, + pub resolve_node_timeout_ms: Option, pub resolve_node_count: u32, pub resolve_node_fanout: u32, pub max_find_node_count: u32, - pub get_value_timeout: Option, + pub get_value_timeout_ms: Option, pub get_value_count: u32, pub get_value_fanout: u32, - pub set_value_timeout: Option, + pub set_value_timeout_ms: Option, 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, - pub max_timestamp_ahead: Option, - pub timeout: u64, + pub max_timestamp_behind_ms: Option, + pub max_timestamp_ahead_ms: Option, + 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, @@ -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); diff --git a/veilid-core/src/xx/tick_task.rs b/veilid-core/src/xx/tick_task.rs index 53f1fd90..9e6b5335 100644 --- a/veilid-core/src/xx/tick_task.rs +++ b/veilid-core/src/xx/tick_task.rs @@ -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), diff --git a/veilid-core/src/xx/tools.rs b/veilid-core/src/xx/tools.rs index 3f563e52..96c4bcaf 100644 --- a/veilid-core/src/xx/tools.rs +++ b/veilid-core/src/xx/tools.rs @@ -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, diff --git a/veilid-flutter/lib/bridge_generated.dart b/veilid-flutter/lib/bridge_generated.dart index 83bf7627..50a2a3e6 100644 --- a/veilid-flutter/lib/bridge_generated.dart +++ b/veilid-flutter/lib/bridge_generated.dart @@ -37,242 +37,138 @@ enum AttachmentState { class VeilidConfig { final String programName; final String namespace; - final VeilidConfigCapabilities capabilities; - final VeilidConfigProtectedStore protectedStore; - final VeilidConfigTableStore tableStore; - final VeilidConfigBlockStore blockStore; - final VeilidConfigNetwork network; + final bool capabilitiesProtocolUdp; + final bool capabilitiesProtocolConnectTcp; + final bool capabilitiesProtocolAcceptTcp; + final bool capabilitiesProtocolConnectWs; + final bool capabilitiesProtocolAcceptWs; + final bool capabilitiesProtocolConnectWss; + final bool capabilitiesProtocolAcceptWss; + final bool protectedStoreAllowInsecureFallback; + final bool protectedStoreAlwaysUseInsecureStorage; + final String protectedStoreInsecureFallbackDirectory; + final bool protectedStoreDelete; + final String tableStoreDirectory; + final bool tableStoreDelete; + final String blockStoreDirectory; + final bool blockStoreDelete; + final int networkMaxConnections; + final int networkConnectionInitialTimeoutMs; + final String networkNodeId; + final String networkNodeIdSecret; + final List networkBootstrap; + final bool networkUpnp; + final bool networkNatpmp; + final bool networkEnableLocalPeerScope; + final int networkRestrictedNatRetries; + final int networkRpcConcurrency; + final int networkRpcQueueSize; + final int? networkRpcMaxTimestampBehindMs; + final int? networkRpcMaxTimestampAheadMs; + final int networkRpcTimeoutMs; + final int networkRpcMaxRouteHopCount; + final int? networkDhtResolveNodeTimeoutMs; + final int networkDhtResolveNodeCount; + final int networkDhtResolveNodeFanout; + final int networkDhtMaxFindNodeCount; + final int? networkDhtGetValueTimeoutMs; + final int networkDhtGetValueCount; + final int networkDhtGetValueFanout; + final int? networkDhtSetValueTimeoutMs; + final int networkDhtSetValueCount; + final int networkDhtSetValueFanout; + final int networkDhtMinPeerCount; + final int networkDhtMinPeerRefreshTimeMs; + final int networkDhtValidateDialInfoReceiptTimeMs; + final bool networkProtocolUdpEnabled; + final int networkProtocolUdpSocketPoolSize; + final String networkProtocolUdpListenAddress; + final String? networkProtocolUdpPublicAddress; + final bool networkProtocolTcpConnect; + final bool networkProtocolTcpListen; + final int networkProtocolTcpMaxConnections; + final String networkProtocolTcpListenAddress; + final String? networkProtocolTcpPublicAddress; + final bool networkProtocolWsConnect; + final bool networkProtocolWsListen; + final int networkProtocolWsMaxConnections; + final String networkProtocolWsListenAddress; + final String networkProtocolWsPath; + final String? networkProtocolWsUrl; + final bool networkProtocolWssConnect; + final int networkProtocolWssMaxConnections; + final int networkLeasesMaxServerSignalLeases; + final int networkLeasesMaxServerRelayLeases; + final int networkLeasesMaxClientSignalLeases; + final int networkLeasesMaxClientRelayLeases; VeilidConfig({ required this.programName, required this.namespace, - required this.capabilities, - required this.protectedStore, - required this.tableStore, - required this.blockStore, - required this.network, - }); -} - -class VeilidConfigBlockStore { - final String directory; - final bool delete; - - VeilidConfigBlockStore({ - required this.directory, - required this.delete, - }); -} - -class VeilidConfigCapabilities { - final bool protocolUdp; - final bool protocolConnectTcp; - final bool protocolAcceptTcp; - final bool protocolConnectWs; - final bool protocolAcceptWs; - final bool protocolConnectWss; - final bool protocolAcceptWss; - - VeilidConfigCapabilities({ - required this.protocolUdp, - required this.protocolConnectTcp, - required this.protocolAcceptTcp, - required this.protocolConnectWs, - required this.protocolAcceptWs, - required this.protocolConnectWss, - required this.protocolAcceptWss, - }); -} - -class VeilidConfigDHT { - final int? resolveNodeTimeout; - final int resolveNodeCount; - final int resolveNodeFanout; - final int maxFindNodeCount; - final int? getValueTimeout; - final int getValueCount; - final int getValueFanout; - final int? setValueTimeout; - final int setValueCount; - final int setValueFanout; - final int minPeerCount; - final int minPeerRefreshTime; - final int validateDialInfoReceiptTime; - - VeilidConfigDHT({ - this.resolveNodeTimeout, - required this.resolveNodeCount, - required this.resolveNodeFanout, - required this.maxFindNodeCount, - this.getValueTimeout, - required this.getValueCount, - required this.getValueFanout, - this.setValueTimeout, - required this.setValueCount, - required this.setValueFanout, - required this.minPeerCount, - required this.minPeerRefreshTime, - required this.validateDialInfoReceiptTime, - }); -} - -class VeilidConfigLeases { - final int maxServerSignalLeases; - final int maxServerRelayLeases; - final int maxClientSignalLeases; - final int maxClientRelayLeases; - - VeilidConfigLeases({ - required this.maxServerSignalLeases, - required this.maxServerRelayLeases, - required this.maxClientSignalLeases, - required this.maxClientRelayLeases, - }); -} - -class VeilidConfigNetwork { - final int maxConnections; - final int connectionInitialTimeout; - final String nodeId; - final String nodeIdSecret; - final List bootstrap; - final VeilidConfigRPC rpc; - final VeilidConfigDHT dht; - final bool upnp; - final bool natpmp; - final bool enableLocalPeerScope; - final int restrictedNatRetries; - final VeilidConfigProtocol protocol; - final VeilidConfigLeases leases; - - VeilidConfigNetwork({ - required this.maxConnections, - required this.connectionInitialTimeout, - required this.nodeId, - required this.nodeIdSecret, - required this.bootstrap, - required this.rpc, - required this.dht, - required this.upnp, - required this.natpmp, - required this.enableLocalPeerScope, - required this.restrictedNatRetries, - required this.protocol, - required this.leases, - }); -} - -class VeilidConfigProtectedStore { - final bool allowInsecureFallback; - final bool alwaysUseInsecureStorage; - final String insecureFallbackDirectory; - final bool delete; - - VeilidConfigProtectedStore({ - required this.allowInsecureFallback, - required this.alwaysUseInsecureStorage, - required this.insecureFallbackDirectory, - required this.delete, - }); -} - -class VeilidConfigProtocol { - final VeilidConfigUDP udp; - final VeilidConfigTCP tcp; - final VeilidConfigWS ws; - final VeilidConfigWSS wss; - - VeilidConfigProtocol({ - required this.udp, - required this.tcp, - required this.ws, - required this.wss, - }); -} - -class VeilidConfigRPC { - final int concurrency; - final int queueSize; - final int? maxTimestampBehind; - final int? maxTimestampAhead; - final int timeout; - final int maxRouteHopCount; - - VeilidConfigRPC({ - required this.concurrency, - required this.queueSize, - this.maxTimestampBehind, - this.maxTimestampAhead, - required this.timeout, - required this.maxRouteHopCount, - }); -} - -class VeilidConfigTableStore { - final String directory; - final bool delete; - - VeilidConfigTableStore({ - required this.directory, - required this.delete, - }); -} - -class VeilidConfigTCP { - final bool connect; - final bool listen; - final int maxConnections; - final String listenAddress; - final String? publicAddress; - - VeilidConfigTCP({ - required this.connect, - required this.listen, - required this.maxConnections, - required this.listenAddress, - this.publicAddress, - }); -} - -class VeilidConfigUDP { - final bool enabled; - final int socketPoolSize; - final String listenAddress; - final String? publicAddress; - - VeilidConfigUDP({ - required this.enabled, - required this.socketPoolSize, - required this.listenAddress, - this.publicAddress, - }); -} - -class VeilidConfigWS { - final bool connect; - final bool listen; - final int maxConnections; - final String listenAddress; - final String path; - final String? url; - - VeilidConfigWS({ - required this.connect, - required this.listen, - required this.maxConnections, - required this.listenAddress, - required this.path, - this.url, - }); -} - -class VeilidConfigWSS { - final bool connect; - final int maxConnections; - - VeilidConfigWSS({ - required this.connect, - required this.maxConnections, + required this.capabilitiesProtocolUdp, + required this.capabilitiesProtocolConnectTcp, + required this.capabilitiesProtocolAcceptTcp, + required this.capabilitiesProtocolConnectWs, + required this.capabilitiesProtocolAcceptWs, + required this.capabilitiesProtocolConnectWss, + required this.capabilitiesProtocolAcceptWss, + required this.protectedStoreAllowInsecureFallback, + required this.protectedStoreAlwaysUseInsecureStorage, + required this.protectedStoreInsecureFallbackDirectory, + required this.protectedStoreDelete, + required this.tableStoreDirectory, + required this.tableStoreDelete, + required this.blockStoreDirectory, + required this.blockStoreDelete, + required this.networkMaxConnections, + required this.networkConnectionInitialTimeoutMs, + required this.networkNodeId, + required this.networkNodeIdSecret, + required this.networkBootstrap, + required this.networkUpnp, + required this.networkNatpmp, + required this.networkEnableLocalPeerScope, + required this.networkRestrictedNatRetries, + required this.networkRpcConcurrency, + required this.networkRpcQueueSize, + this.networkRpcMaxTimestampBehindMs, + this.networkRpcMaxTimestampAheadMs, + required this.networkRpcTimeoutMs, + required this.networkRpcMaxRouteHopCount, + this.networkDhtResolveNodeTimeoutMs, + required this.networkDhtResolveNodeCount, + required this.networkDhtResolveNodeFanout, + required this.networkDhtMaxFindNodeCount, + this.networkDhtGetValueTimeoutMs, + required this.networkDhtGetValueCount, + required this.networkDhtGetValueFanout, + this.networkDhtSetValueTimeoutMs, + required this.networkDhtSetValueCount, + required this.networkDhtSetValueFanout, + required this.networkDhtMinPeerCount, + required this.networkDhtMinPeerRefreshTimeMs, + required this.networkDhtValidateDialInfoReceiptTimeMs, + required this.networkProtocolUdpEnabled, + required this.networkProtocolUdpSocketPoolSize, + required this.networkProtocolUdpListenAddress, + this.networkProtocolUdpPublicAddress, + required this.networkProtocolTcpConnect, + required this.networkProtocolTcpListen, + required this.networkProtocolTcpMaxConnections, + required this.networkProtocolTcpListenAddress, + this.networkProtocolTcpPublicAddress, + required this.networkProtocolWsConnect, + required this.networkProtocolWsListen, + required this.networkProtocolWsMaxConnections, + required this.networkProtocolWsListenAddress, + required this.networkProtocolWsPath, + this.networkProtocolWsUrl, + required this.networkProtocolWssConnect, + required this.networkProtocolWssMaxConnections, + required this.networkLeasesMaxServerSignalLeases, + required this.networkLeasesMaxServerRelayLeases, + required this.networkLeasesMaxClientSignalLeases, + required this.networkLeasesMaxClientRelayLeases, }); } @@ -353,8 +249,8 @@ class VeilidFlutterImpl extends FlutterRustBridgeBase return raw ? 1 : 0; } - ffi.Pointer _api2wire_box_autoadd_u64(int raw) { - return inner.new_box_autoadd_u64(raw); + ffi.Pointer _api2wire_box_autoadd_u32(int raw) { + return inner.new_box_autoadd_u32(raw); } ffi.Pointer _api2wire_box_autoadd_veilid_config( @@ -368,18 +264,14 @@ class VeilidFlutterImpl extends FlutterRustBridgeBase return raw == null ? ffi.nullptr : _api2wire_String(raw); } - ffi.Pointer _api2wire_opt_box_autoadd_u64(int? raw) { - return raw == null ? ffi.nullptr : _api2wire_box_autoadd_u64(raw); + ffi.Pointer _api2wire_opt_box_autoadd_u32(int? raw) { + return raw == null ? ffi.nullptr : _api2wire_box_autoadd_u32(raw); } int _api2wire_u32(int raw) { return raw; } - int _api2wire_u64(int raw) { - return raw; - } - int _api2wire_u8(int raw) { return raw; } @@ -401,155 +293,128 @@ class VeilidFlutterImpl extends FlutterRustBridgeBase VeilidConfig apiObj, wire_VeilidConfig wireObj) { wireObj.program_name = _api2wire_String(apiObj.programName); wireObj.namespace = _api2wire_String(apiObj.namespace); - wireObj.capabilities = - _api2wire_veilid_config_capabilities(apiObj.capabilities); - wireObj.protected_store = - _api2wire_veilid_config_protected_store(apiObj.protectedStore); - wireObj.table_store = - _api2wire_veilid_config_table_store(apiObj.tableStore); - wireObj.block_store = - _api2wire_veilid_config_block_store(apiObj.blockStore); - wireObj.network = _api2wire_veilid_config_network(apiObj.network); - } - - void _api_fill_to_wire_veilid_config_block_store( - VeilidConfigBlockStore apiObj, wire_VeilidConfigBlockStore wireObj) { - wireObj.directory = _api2wire_String(apiObj.directory); - wireObj.delete = _api2wire_bool(apiObj.delete); - } - - void _api_fill_to_wire_veilid_config_capabilities( - VeilidConfigCapabilities apiObj, wire_VeilidConfigCapabilities wireObj) { - wireObj.protocol_udp = _api2wire_bool(apiObj.protocolUdp); - wireObj.protocol_connect_tcp = _api2wire_bool(apiObj.protocolConnectTcp); - wireObj.protocol_accept_tcp = _api2wire_bool(apiObj.protocolAcceptTcp); - wireObj.protocol_connect_ws = _api2wire_bool(apiObj.protocolConnectWs); - wireObj.protocol_accept_ws = _api2wire_bool(apiObj.protocolAcceptWs); - wireObj.protocol_connect_wss = _api2wire_bool(apiObj.protocolConnectWss); - wireObj.protocol_accept_wss = _api2wire_bool(apiObj.protocolAcceptWss); - } - - void _api_fill_to_wire_veilid_config_dht( - VeilidConfigDHT apiObj, wire_VeilidConfigDHT wireObj) { - wireObj.resolve_node_timeout = - _api2wire_opt_box_autoadd_u64(apiObj.resolveNodeTimeout); - wireObj.resolve_node_count = _api2wire_u32(apiObj.resolveNodeCount); - wireObj.resolve_node_fanout = _api2wire_u32(apiObj.resolveNodeFanout); - wireObj.max_find_node_count = _api2wire_u32(apiObj.maxFindNodeCount); - wireObj.get_value_timeout = - _api2wire_opt_box_autoadd_u64(apiObj.getValueTimeout); - wireObj.get_value_count = _api2wire_u32(apiObj.getValueCount); - wireObj.get_value_fanout = _api2wire_u32(apiObj.getValueFanout); - wireObj.set_value_timeout = - _api2wire_opt_box_autoadd_u64(apiObj.setValueTimeout); - wireObj.set_value_count = _api2wire_u32(apiObj.setValueCount); - wireObj.set_value_fanout = _api2wire_u32(apiObj.setValueFanout); - wireObj.min_peer_count = _api2wire_u32(apiObj.minPeerCount); - wireObj.min_peer_refresh_time = _api2wire_u64(apiObj.minPeerRefreshTime); - wireObj.validate_dial_info_receipt_time = - _api2wire_u64(apiObj.validateDialInfoReceiptTime); - } - - void _api_fill_to_wire_veilid_config_leases( - VeilidConfigLeases apiObj, wire_VeilidConfigLeases wireObj) { - wireObj.max_server_signal_leases = - _api2wire_u32(apiObj.maxServerSignalLeases); - wireObj.max_server_relay_leases = - _api2wire_u32(apiObj.maxServerRelayLeases); - wireObj.max_client_signal_leases = - _api2wire_u32(apiObj.maxClientSignalLeases); - wireObj.max_client_relay_leases = - _api2wire_u32(apiObj.maxClientRelayLeases); - } - - void _api_fill_to_wire_veilid_config_network( - VeilidConfigNetwork apiObj, wire_VeilidConfigNetwork wireObj) { - wireObj.max_connections = _api2wire_u32(apiObj.maxConnections); - wireObj.connection_initial_timeout = - _api2wire_u64(apiObj.connectionInitialTimeout); - wireObj.node_id = _api2wire_String(apiObj.nodeId); - wireObj.node_id_secret = _api2wire_String(apiObj.nodeIdSecret); - wireObj.bootstrap = _api2wire_StringList(apiObj.bootstrap); - wireObj.rpc = _api2wire_veilid_config_rpc(apiObj.rpc); - wireObj.dht = _api2wire_veilid_config_dht(apiObj.dht); - wireObj.upnp = _api2wire_bool(apiObj.upnp); - wireObj.natpmp = _api2wire_bool(apiObj.natpmp); - wireObj.enable_local_peer_scope = - _api2wire_bool(apiObj.enableLocalPeerScope); - wireObj.restricted_nat_retries = _api2wire_u32(apiObj.restrictedNatRetries); - wireObj.protocol = _api2wire_veilid_config_protocol(apiObj.protocol); - wireObj.leases = _api2wire_veilid_config_leases(apiObj.leases); - } - - void _api_fill_to_wire_veilid_config_protected_store( - VeilidConfigProtectedStore apiObj, - wire_VeilidConfigProtectedStore wireObj) { - wireObj.allow_insecure_fallback = - _api2wire_bool(apiObj.allowInsecureFallback); - wireObj.always_use_insecure_storage = - _api2wire_bool(apiObj.alwaysUseInsecureStorage); - wireObj.insecure_fallback_directory = - _api2wire_String(apiObj.insecureFallbackDirectory); - wireObj.delete = _api2wire_bool(apiObj.delete); - } - - void _api_fill_to_wire_veilid_config_protocol( - VeilidConfigProtocol apiObj, wire_VeilidConfigProtocol wireObj) { - wireObj.udp = _api2wire_veilid_config_udp(apiObj.udp); - wireObj.tcp = _api2wire_veilid_config_tcp(apiObj.tcp); - wireObj.ws = _api2wire_veilid_config_ws(apiObj.ws); - wireObj.wss = _api2wire_veilid_config_wss(apiObj.wss); - } - - void _api_fill_to_wire_veilid_config_rpc( - VeilidConfigRPC apiObj, wire_VeilidConfigRPC wireObj) { - wireObj.concurrency = _api2wire_u32(apiObj.concurrency); - wireObj.queue_size = _api2wire_u32(apiObj.queueSize); - wireObj.max_timestamp_behind = - _api2wire_opt_box_autoadd_u64(apiObj.maxTimestampBehind); - wireObj.max_timestamp_ahead = - _api2wire_opt_box_autoadd_u64(apiObj.maxTimestampAhead); - wireObj.timeout = _api2wire_u64(apiObj.timeout); - wireObj.max_route_hop_count = _api2wire_u8(apiObj.maxRouteHopCount); - } - - void _api_fill_to_wire_veilid_config_table_store( - VeilidConfigTableStore apiObj, wire_VeilidConfigTableStore wireObj) { - wireObj.directory = _api2wire_String(apiObj.directory); - wireObj.delete = _api2wire_bool(apiObj.delete); - } - - void _api_fill_to_wire_veilid_config_tcp( - VeilidConfigTCP apiObj, wire_VeilidConfigTCP wireObj) { - wireObj.connect = _api2wire_bool(apiObj.connect); - wireObj.listen = _api2wire_bool(apiObj.listen); - wireObj.max_connections = _api2wire_u32(apiObj.maxConnections); - wireObj.listen_address = _api2wire_String(apiObj.listenAddress); - wireObj.public_address = _api2wire_opt_String(apiObj.publicAddress); - } - - void _api_fill_to_wire_veilid_config_udp( - VeilidConfigUDP apiObj, wire_VeilidConfigUDP wireObj) { - wireObj.enabled = _api2wire_bool(apiObj.enabled); - wireObj.socket_pool_size = _api2wire_u32(apiObj.socketPoolSize); - wireObj.listen_address = _api2wire_String(apiObj.listenAddress); - wireObj.public_address = _api2wire_opt_String(apiObj.publicAddress); - } - - void _api_fill_to_wire_veilid_config_ws( - VeilidConfigWS apiObj, wire_VeilidConfigWS wireObj) { - wireObj.connect = _api2wire_bool(apiObj.connect); - wireObj.listen = _api2wire_bool(apiObj.listen); - wireObj.max_connections = _api2wire_u32(apiObj.maxConnections); - wireObj.listen_address = _api2wire_String(apiObj.listenAddress); - wireObj.path = _api2wire_String(apiObj.path); - wireObj.url = _api2wire_opt_String(apiObj.url); - } - - void _api_fill_to_wire_veilid_config_wss( - VeilidConfigWSS apiObj, wire_VeilidConfigWSS wireObj) { - wireObj.connect = _api2wire_bool(apiObj.connect); - wireObj.max_connections = _api2wire_u32(apiObj.maxConnections); + wireObj.capabilities__protocol_udp = + _api2wire_bool(apiObj.capabilitiesProtocolUdp); + wireObj.capabilities__protocol_connect_tcp = + _api2wire_bool(apiObj.capabilitiesProtocolConnectTcp); + wireObj.capabilities__protocol_accept_tcp = + _api2wire_bool(apiObj.capabilitiesProtocolAcceptTcp); + wireObj.capabilities__protocol_connect_ws = + _api2wire_bool(apiObj.capabilitiesProtocolConnectWs); + wireObj.capabilities__protocol_accept_ws = + _api2wire_bool(apiObj.capabilitiesProtocolAcceptWs); + wireObj.capabilities__protocol_connect_wss = + _api2wire_bool(apiObj.capabilitiesProtocolConnectWss); + wireObj.capabilities__protocol_accept_wss = + _api2wire_bool(apiObj.capabilitiesProtocolAcceptWss); + wireObj.protected_store__allow_insecure_fallback = + _api2wire_bool(apiObj.protectedStoreAllowInsecureFallback); + wireObj.protected_store__always_use_insecure_storage = + _api2wire_bool(apiObj.protectedStoreAlwaysUseInsecureStorage); + wireObj.protected_store__insecure_fallback_directory = + _api2wire_String(apiObj.protectedStoreInsecureFallbackDirectory); + wireObj.protected_store__delete = + _api2wire_bool(apiObj.protectedStoreDelete); + wireObj.table_store__directory = + _api2wire_String(apiObj.tableStoreDirectory); + wireObj.table_store__delete = _api2wire_bool(apiObj.tableStoreDelete); + wireObj.block_store__directory = + _api2wire_String(apiObj.blockStoreDirectory); + wireObj.block_store__delete = _api2wire_bool(apiObj.blockStoreDelete); + wireObj.network__max_connections = + _api2wire_u32(apiObj.networkMaxConnections); + wireObj.network__connection_initial_timeout_ms = + _api2wire_u32(apiObj.networkConnectionInitialTimeoutMs); + wireObj.network__node_id = _api2wire_String(apiObj.networkNodeId); + wireObj.network__node_id_secret = + _api2wire_String(apiObj.networkNodeIdSecret); + wireObj.network__bootstrap = _api2wire_StringList(apiObj.networkBootstrap); + wireObj.network__upnp = _api2wire_bool(apiObj.networkUpnp); + wireObj.network__natpmp = _api2wire_bool(apiObj.networkNatpmp); + wireObj.network__enable_local_peer_scope = + _api2wire_bool(apiObj.networkEnableLocalPeerScope); + wireObj.network__restricted_nat_retries = + _api2wire_u32(apiObj.networkRestrictedNatRetries); + wireObj.network__rpc__concurrency = + _api2wire_u32(apiObj.networkRpcConcurrency); + wireObj.network__rpc__queue_size = + _api2wire_u32(apiObj.networkRpcQueueSize); + wireObj.network__rpc__max_timestamp_behind_ms = + _api2wire_opt_box_autoadd_u32(apiObj.networkRpcMaxTimestampBehindMs); + wireObj.network__rpc__max_timestamp_ahead_ms = + _api2wire_opt_box_autoadd_u32(apiObj.networkRpcMaxTimestampAheadMs); + wireObj.network__rpc__timeout_ms = + _api2wire_u32(apiObj.networkRpcTimeoutMs); + wireObj.network__rpc__max_route_hop_count = + _api2wire_u8(apiObj.networkRpcMaxRouteHopCount); + wireObj.network__dht__resolve_node_timeout_ms = + _api2wire_opt_box_autoadd_u32(apiObj.networkDhtResolveNodeTimeoutMs); + wireObj.network__dht__resolve_node_count = + _api2wire_u32(apiObj.networkDhtResolveNodeCount); + wireObj.network__dht__resolve_node_fanout = + _api2wire_u32(apiObj.networkDhtResolveNodeFanout); + wireObj.network__dht__max_find_node_count = + _api2wire_u32(apiObj.networkDhtMaxFindNodeCount); + wireObj.network__dht__get_value_timeout_ms = + _api2wire_opt_box_autoadd_u32(apiObj.networkDhtGetValueTimeoutMs); + wireObj.network__dht__get_value_count = + _api2wire_u32(apiObj.networkDhtGetValueCount); + wireObj.network__dht__get_value_fanout = + _api2wire_u32(apiObj.networkDhtGetValueFanout); + wireObj.network__dht__set_value_timeout_ms = + _api2wire_opt_box_autoadd_u32(apiObj.networkDhtSetValueTimeoutMs); + wireObj.network__dht__set_value_count = + _api2wire_u32(apiObj.networkDhtSetValueCount); + wireObj.network__dht__set_value_fanout = + _api2wire_u32(apiObj.networkDhtSetValueFanout); + wireObj.network__dht__min_peer_count = + _api2wire_u32(apiObj.networkDhtMinPeerCount); + wireObj.network__dht__min_peer_refresh_time_ms = + _api2wire_u32(apiObj.networkDhtMinPeerRefreshTimeMs); + wireObj.network__dht__validate_dial_info_receipt_time_ms = + _api2wire_u32(apiObj.networkDhtValidateDialInfoReceiptTimeMs); + wireObj.network__protocol__udp__enabled = + _api2wire_bool(apiObj.networkProtocolUdpEnabled); + wireObj.network__protocol__udp__socket_pool_size = + _api2wire_u32(apiObj.networkProtocolUdpSocketPoolSize); + wireObj.network__protocol__udp__listen_address = + _api2wire_String(apiObj.networkProtocolUdpListenAddress); + wireObj.network__protocol__udp__public_address = + _api2wire_opt_String(apiObj.networkProtocolUdpPublicAddress); + wireObj.network__protocol__tcp__connect = + _api2wire_bool(apiObj.networkProtocolTcpConnect); + wireObj.network__protocol__tcp__listen = + _api2wire_bool(apiObj.networkProtocolTcpListen); + wireObj.network__protocol__tcp__max_connections = + _api2wire_u32(apiObj.networkProtocolTcpMaxConnections); + wireObj.network__protocol__tcp__listen_address = + _api2wire_String(apiObj.networkProtocolTcpListenAddress); + wireObj.network__protocol__tcp__public_address = + _api2wire_opt_String(apiObj.networkProtocolTcpPublicAddress); + wireObj.network__protocol__ws__connect = + _api2wire_bool(apiObj.networkProtocolWsConnect); + wireObj.network__protocol__ws__listen = + _api2wire_bool(apiObj.networkProtocolWsListen); + wireObj.network__protocol__ws__max_connections = + _api2wire_u32(apiObj.networkProtocolWsMaxConnections); + wireObj.network__protocol__ws__listen_address = + _api2wire_String(apiObj.networkProtocolWsListenAddress); + wireObj.network__protocol__ws__path = + _api2wire_String(apiObj.networkProtocolWsPath); + wireObj.network__protocol__ws__url = + _api2wire_opt_String(apiObj.networkProtocolWsUrl); + wireObj.network__protocol__wss__connect = + _api2wire_bool(apiObj.networkProtocolWssConnect); + wireObj.network__protocol__wss__max_connections = + _api2wire_u32(apiObj.networkProtocolWssMaxConnections); + wireObj.network__leases__max_server_signal_leases = + _api2wire_u32(apiObj.networkLeasesMaxServerSignalLeases); + wireObj.network__leases__max_server_relay_leases = + _api2wire_u32(apiObj.networkLeasesMaxServerRelayLeases); + wireObj.network__leases__max_client_signal_leases = + _api2wire_u32(apiObj.networkLeasesMaxClientSignalLeases); + wireObj.network__leases__max_client_relay_leases = + _api2wire_u32(apiObj.networkLeasesMaxClientRelayLeases); } } @@ -663,19 +528,19 @@ class VeilidFlutterWire implements FlutterRustBridgeWireBase { late final _new_StringList = _new_StringListPtr .asFunction Function(int)>(); - ffi.Pointer new_box_autoadd_u64( + ffi.Pointer new_box_autoadd_u32( int value, ) { - return _new_box_autoadd_u64( + return _new_box_autoadd_u32( value, ); } - late final _new_box_autoadd_u64Ptr = - _lookup Function(ffi.Uint64)>>( - 'new_box_autoadd_u64'); - late final _new_box_autoadd_u64 = _new_box_autoadd_u64Ptr - .asFunction Function(int)>(); + late final _new_box_autoadd_u32Ptr = + _lookup Function(ffi.Uint32)>>( + 'new_box_autoadd_u32'); + late final _new_box_autoadd_u32 = _new_box_autoadd_u32Ptr + .asFunction Function(int)>(); ffi.Pointer new_box_autoadd_veilid_config() { return _new_box_autoadd_veilid_config(); @@ -738,56 +603,6 @@ class wire_uint_8_list extends ffi.Struct { external int len; } -class wire_VeilidConfigCapabilities extends ffi.Struct { - @ffi.Uint8() - external int protocol_udp; - - @ffi.Uint8() - external int protocol_connect_tcp; - - @ffi.Uint8() - external int protocol_accept_tcp; - - @ffi.Uint8() - external int protocol_connect_ws; - - @ffi.Uint8() - external int protocol_accept_ws; - - @ffi.Uint8() - external int protocol_connect_wss; - - @ffi.Uint8() - external int protocol_accept_wss; -} - -class wire_VeilidConfigProtectedStore extends ffi.Struct { - @ffi.Uint8() - external int allow_insecure_fallback; - - @ffi.Uint8() - external int always_use_insecure_storage; - - external ffi.Pointer insecure_fallback_directory; - - @ffi.Uint8() - external int delete_; -} - -class wire_VeilidConfigTableStore extends ffi.Struct { - external ffi.Pointer directory; - - @ffi.Uint8() - external int delete_; -} - -class wire_VeilidConfigBlockStore extends ffi.Struct { - external ffi.Pointer directory; - - @ffi.Uint8() - external int delete_; -} - class wire_StringList extends ffi.Struct { external ffi.Pointer> ptr; @@ -795,186 +610,185 @@ class wire_StringList extends ffi.Struct { external int len; } -class wire_VeilidConfigRPC extends ffi.Struct { - @ffi.Uint32() - external int concurrency; - - @ffi.Uint32() - external int queue_size; - - external ffi.Pointer max_timestamp_behind; - - external ffi.Pointer max_timestamp_ahead; - - @ffi.Uint64() - external int timeout; - - @ffi.Uint8() - external int max_route_hop_count; -} - -class wire_VeilidConfigDHT extends ffi.Struct { - external ffi.Pointer resolve_node_timeout; - - @ffi.Uint32() - external int resolve_node_count; - - @ffi.Uint32() - external int resolve_node_fanout; - - @ffi.Uint32() - external int max_find_node_count; - - external ffi.Pointer get_value_timeout; - - @ffi.Uint32() - external int get_value_count; - - @ffi.Uint32() - external int get_value_fanout; - - external ffi.Pointer set_value_timeout; - - @ffi.Uint32() - external int set_value_count; - - @ffi.Uint32() - external int set_value_fanout; - - @ffi.Uint32() - external int min_peer_count; - - @ffi.Uint64() - external int min_peer_refresh_time; - - @ffi.Uint64() - external int validate_dial_info_receipt_time; -} - -class wire_VeilidConfigUDP extends ffi.Struct { - @ffi.Uint8() - external int enabled; - - @ffi.Uint32() - external int socket_pool_size; - - external ffi.Pointer listen_address; - - external ffi.Pointer public_address; -} - -class wire_VeilidConfigTCP extends ffi.Struct { - @ffi.Uint8() - external int connect; - - @ffi.Uint8() - external int listen; - - @ffi.Uint32() - external int max_connections; - - external ffi.Pointer listen_address; - - external ffi.Pointer public_address; -} - -class wire_VeilidConfigWS extends ffi.Struct { - @ffi.Uint8() - external int connect; - - @ffi.Uint8() - external int listen; - - @ffi.Uint32() - external int max_connections; - - external ffi.Pointer listen_address; - - external ffi.Pointer path; - - external ffi.Pointer url; -} - -class wire_VeilidConfigWSS extends ffi.Struct { - @ffi.Uint8() - external int connect; - - @ffi.Uint32() - external int max_connections; -} - -class wire_VeilidConfigProtocol extends ffi.Struct { - external wire_VeilidConfigUDP udp; - - external wire_VeilidConfigTCP tcp; - - external wire_VeilidConfigWS ws; - - external wire_VeilidConfigWSS wss; -} - -class wire_VeilidConfigLeases extends ffi.Struct { - @ffi.Uint32() - external int max_server_signal_leases; - - @ffi.Uint32() - external int max_server_relay_leases; - - @ffi.Uint32() - external int max_client_signal_leases; - - @ffi.Uint32() - external int max_client_relay_leases; -} - -class wire_VeilidConfigNetwork extends ffi.Struct { - @ffi.Uint32() - external int max_connections; - - @ffi.Uint64() - external int connection_initial_timeout; - - external ffi.Pointer node_id; - - external ffi.Pointer node_id_secret; - - external ffi.Pointer bootstrap; - - external wire_VeilidConfigRPC rpc; - - external wire_VeilidConfigDHT dht; - - @ffi.Uint8() - external int upnp; - - @ffi.Uint8() - external int natpmp; - - @ffi.Uint8() - external int enable_local_peer_scope; - - @ffi.Uint32() - external int restricted_nat_retries; - - external wire_VeilidConfigProtocol protocol; - - external wire_VeilidConfigLeases leases; -} - class wire_VeilidConfig extends ffi.Struct { external ffi.Pointer program_name; external ffi.Pointer namespace_; - external wire_VeilidConfigCapabilities capabilities; + @ffi.Uint8() + external int capabilities__protocol_udp; - external wire_VeilidConfigProtectedStore protected_store; + @ffi.Uint8() + external int capabilities__protocol_connect_tcp; - external wire_VeilidConfigTableStore table_store; + @ffi.Uint8() + external int capabilities__protocol_accept_tcp; - external wire_VeilidConfigBlockStore block_store; + @ffi.Uint8() + external int capabilities__protocol_connect_ws; - external wire_VeilidConfigNetwork network; + @ffi.Uint8() + external int capabilities__protocol_accept_ws; + + @ffi.Uint8() + external int capabilities__protocol_connect_wss; + + @ffi.Uint8() + external int capabilities__protocol_accept_wss; + + @ffi.Uint8() + external int protected_store__allow_insecure_fallback; + + @ffi.Uint8() + external int protected_store__always_use_insecure_storage; + + external ffi.Pointer + protected_store__insecure_fallback_directory; + + @ffi.Uint8() + external int protected_store__delete; + + external ffi.Pointer table_store__directory; + + @ffi.Uint8() + external int table_store__delete; + + external ffi.Pointer block_store__directory; + + @ffi.Uint8() + external int block_store__delete; + + @ffi.Uint32() + external int network__max_connections; + + @ffi.Uint32() + external int network__connection_initial_timeout_ms; + + external ffi.Pointer network__node_id; + + external ffi.Pointer network__node_id_secret; + + external ffi.Pointer network__bootstrap; + + @ffi.Uint8() + external int network__upnp; + + @ffi.Uint8() + external int network__natpmp; + + @ffi.Uint8() + external int network__enable_local_peer_scope; + + @ffi.Uint32() + external int network__restricted_nat_retries; + + @ffi.Uint32() + external int network__rpc__concurrency; + + @ffi.Uint32() + external int network__rpc__queue_size; + + external ffi.Pointer network__rpc__max_timestamp_behind_ms; + + external ffi.Pointer network__rpc__max_timestamp_ahead_ms; + + @ffi.Uint32() + external int network__rpc__timeout_ms; + + @ffi.Uint8() + external int network__rpc__max_route_hop_count; + + external ffi.Pointer network__dht__resolve_node_timeout_ms; + + @ffi.Uint32() + external int network__dht__resolve_node_count; + + @ffi.Uint32() + external int network__dht__resolve_node_fanout; + + @ffi.Uint32() + external int network__dht__max_find_node_count; + + external ffi.Pointer network__dht__get_value_timeout_ms; + + @ffi.Uint32() + external int network__dht__get_value_count; + + @ffi.Uint32() + external int network__dht__get_value_fanout; + + external ffi.Pointer network__dht__set_value_timeout_ms; + + @ffi.Uint32() + external int network__dht__set_value_count; + + @ffi.Uint32() + external int network__dht__set_value_fanout; + + @ffi.Uint32() + external int network__dht__min_peer_count; + + @ffi.Uint32() + external int network__dht__min_peer_refresh_time_ms; + + @ffi.Uint32() + external int network__dht__validate_dial_info_receipt_time_ms; + + @ffi.Uint8() + external int network__protocol__udp__enabled; + + @ffi.Uint32() + external int network__protocol__udp__socket_pool_size; + + external ffi.Pointer network__protocol__udp__listen_address; + + external ffi.Pointer network__protocol__udp__public_address; + + @ffi.Uint8() + external int network__protocol__tcp__connect; + + @ffi.Uint8() + external int network__protocol__tcp__listen; + + @ffi.Uint32() + external int network__protocol__tcp__max_connections; + + external ffi.Pointer network__protocol__tcp__listen_address; + + external ffi.Pointer network__protocol__tcp__public_address; + + @ffi.Uint8() + external int network__protocol__ws__connect; + + @ffi.Uint8() + external int network__protocol__ws__listen; + + @ffi.Uint32() + external int network__protocol__ws__max_connections; + + external ffi.Pointer network__protocol__ws__listen_address; + + external ffi.Pointer network__protocol__ws__path; + + external ffi.Pointer network__protocol__ws__url; + + @ffi.Uint8() + external int network__protocol__wss__connect; + + @ffi.Uint32() + external int network__protocol__wss__max_connections; + + @ffi.Uint32() + external int network__leases__max_server_signal_leases; + + @ffi.Uint32() + external int network__leases__max_server_relay_leases; + + @ffi.Uint32() + external int network__leases__max_client_signal_leases; + + @ffi.Uint32() + external int network__leases__max_client_relay_leases; } typedef DartPostCObjectFnType = ffi.Pointer< diff --git a/veilid-flutter/rust/src/api.rs b/veilid-flutter/rust/src/api.rs index 27873c49..6fc81579 100644 --- a/veilid-flutter/rust/src/api.rs +++ b/veilid-flutter/rust/src/api.rs @@ -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> = AsyncMutex::new(None); +static VEILID_API: AsyncMutex> = AsyncMutex::new(None); +async fn get_veilid_api() -> Result { + 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 { + 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, -} - -#[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, -} - -#[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, -} - -#[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, - pub resolve_node_count: u32, - pub resolve_node_fanout: u32, - pub max_find_node_count: u32, - pub get_value_timeout: Option, - pub get_value_count: u32, - pub get_value_fanout: u32, - pub set_value_timeout: Option, - 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, - pub max_timestamp_ahead: Option, - 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, - 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, + 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, + pub network__rpc__max_timestamp_ahead_ms: Option, + pub network__rpc__timeout_ms: u32, + pub network__rpc__max_route_hop_count: u8, + // Network / DHT + pub network__dht__resolve_node_timeout_ms: Option, + 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, + pub network__dht__get_value_count: u32, + pub network__dht__get_value_fanout: u32, + pub network__dht__set_value_timeout_ms: Option, + 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, + // 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, + // 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, + // 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, String> { + let out: Box = 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::::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::::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::::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, config: VeilidConfig) -> Result { 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::>::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::::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::::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::::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, 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, config: VeilidConfig) pub fn get_veilid_state() -> Result { 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 { 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(()) })