From cc328d30fa53aacf24f028d73cdaeedd1ff33b03 Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 31 Jan 2022 08:52:11 -0500 Subject: [PATCH] ios unit test cleanup --- veilid-core/Cargo.toml | 10 +- veilid-core/ios_build.sh | 18 +- .../utils/{ios/mod.rs => ios_test_setup.rs} | 14 +- veilid-core/src/intf/native/utils/mod.rs | 2 +- veilid-core/src/tests/native/mod.rs | 2 +- veilid-flutter/rust/Cargo.toml | 1 + veilid-flutter/rust/src/api.rs | 276 +++-- veilid-flutter/rust/src/bridge_generated.rs | 948 +++++++++--------- veilid-flutter/rust/src/lib.rs | 35 + 9 files changed, 751 insertions(+), 555 deletions(-) rename veilid-core/src/intf/native/utils/{ios/mod.rs => ios_test_setup.rs} (88%) diff --git a/veilid-core/Cargo.toml b/veilid-core/Cargo.toml index d12d8347..6b491aef 100644 --- a/veilid-core/Cargo.toml +++ b/veilid-core/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib", "staticlib", "rlib"] [features] android_tests = [] -ios_tests = [] +ios_tests = [ "simplelog", "backtrace" ] [dependencies] capnp = { version = "^0", default_features = false } @@ -126,14 +126,10 @@ rtnetlink = { version = "^0", default-features = false, features = [ "smol_socke [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "^0", features = [ "iptypes", "iphlpapi" ] } -# Dependencies for MacOS and iOS -#[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies] -# XXX - # Dependencies for iOS [target.'cfg(target_os = "ios")'.dependencies] -simplelog = { version = "^0" } -backtrace = { version = "^0" } +simplelog = { version = "^0", optional = true } +backtrace = { version = "^0", optional = true } # Rusqlite configuration to ensure platforms that don't come with sqlite get it bundled # Except WASM which doesn't use sqlite diff --git a/veilid-core/ios_build.sh b/veilid-core/ios_build.sh index dad8d4b6..1986bfe5 100755 --- a/veilid-core/ios_build.sh +++ b/veilid-core/ios_build.sh @@ -25,8 +25,20 @@ do echo Unsupported ARCH: $arch continue fi - HOMEBREW_DIR=$(dirname `which brew`) - CARGO_DIR=$(dirname `which cargo`) - env -i PATH=/usr/bin:/bin:/usr/local/bin:$HOMEBREW_DIR:$CARGO_DIR HOME="$HOME" USER="$USER" cargo $CARGO_TOOLCHAIN build $EXTRA_CARGO_OPTIONS --target $CARGO_TARGET --manifest-path $CARGO_MANIFEST_PATH + + CARGO=`which cargo` + CARGO=${CARGO:=~/.cargo/bin/cargo} + CARGO_DIR=$(dirname $CARGO) + + # Choose arm64 brew for unit tests by default if we are on M1 + if [ -f /opt/homebrew/bin/brew ]; then + HOMEBREW_DIR=/opt/homebrew/bin + elif [ -f /usr/local/bin/brew ]; then + HOMEBREW_DIR=/usr/local/bin + else + HOMEBREW_DIR=$(dirname `which brew`) + fi + + env -i PATH=/usr/bin:/bin:$HOMEBREW_DIR:$CARGO_DIR HOME="$HOME" USER="$USER" cargo $CARGO_TOOLCHAIN build $EXTRA_CARGO_OPTIONS --target $CARGO_TARGET --manifest-path $CARGO_MANIFEST_PATH done diff --git a/veilid-core/src/intf/native/utils/ios/mod.rs b/veilid-core/src/intf/native/utils/ios_test_setup.rs similarity index 88% rename from veilid-core/src/intf/native/utils/ios/mod.rs rename to veilid-core/src/intf/native/utils/ios_test_setup.rs index 63a9c596..1b45ff01 100644 --- a/veilid-core/src/intf/native/utils/ios/mod.rs +++ b/veilid-core/src/intf/native/utils/ios_test_setup.rs @@ -1,29 +1,22 @@ use crate::xx::*; use backtrace::Backtrace; -use lazy_static::*; use log::*; use simplelog::*; use std::fs::OpenOptions; use std::panic; use std::path::{Path, PathBuf}; -pub struct IOSGlobals {} - -lazy_static! { - pub static ref IOS_GLOBALS: Arc>> = Arc::new(Mutex::new(None)); -} - -pub fn veilid_core_setup_ios<'a>( +pub fn veilid_core_setup<'a>( log_tag: &'a str, terminal_log: Option, file_log: Option<(Level, &Path)>, ) { - if let Err(e) = veilid_core_setup_ios_internal(log_tag, terminal_log, file_log) { + if let Err(e) = veilid_core_setup_internal(log_tag, terminal_log, file_log) { panic!("failed to set up veilid-core: {}", e); } } -fn veilid_core_setup_ios_internal<'a>( +fn veilid_core_setup_internal<'a>( _log_tag: &'a str, terminal_log: Option, file_log: Option<(Level, &Path)>, @@ -94,6 +87,5 @@ fn veilid_core_setup_ios_internal<'a>( error!("Backtrace:\n{:?}", bt); })); - *IOS_GLOBALS.lock() = Some(IOSGlobals {}); Ok(()) } diff --git a/veilid-core/src/intf/native/utils/mod.rs b/veilid-core/src/intf/native/utils/mod.rs index 781be6b4..17371d13 100644 --- a/veilid-core/src/intf/native/utils/mod.rs +++ b/veilid-core/src/intf/native/utils/mod.rs @@ -1,5 +1,5 @@ #[cfg(target_os = "android")] pub mod android; #[cfg(target_os = "ios")] -pub mod ios; +pub mod ios_test_setup; pub mod network_interfaces; diff --git a/veilid-core/src/tests/native/mod.rs b/veilid-core/src/tests/native/mod.rs index 8aa35f24..f13c4067 100644 --- a/veilid-core/src/tests/native/mod.rs +++ b/veilid-core/src/tests/native/mod.rs @@ -31,7 +31,7 @@ pub extern "C" fn run_veilid_core_tests() { ] .iter() .collect(); - crate::intf::utils::ios::veilid_core_setup_ios( + crate::intf::utils::ios_test_setup::veilid_core_setup( "veilid-core", Some(Level::Trace), Some((Level::Trace, log_path.as_path())), diff --git a/veilid-flutter/rust/Cargo.toml b/veilid-flutter/rust/Cargo.toml index 144b202e..b6a8c948 100644 --- a/veilid-flutter/rust/Cargo.toml +++ b/veilid-flutter/rust/Cargo.toml @@ -13,6 +13,7 @@ flutter_rust_bridge = "^1" parking_lot = "^0" log = "^0" anyhow = { version = "^1", features = ["backtrace"] } +cfg-if = "^1" [build-dependencies] cfg-if = "^1" diff --git a/veilid-flutter/rust/src/api.rs b/veilid-flutter/rust/src/api.rs index 5047fa40..da7306a5 100644 --- a/veilid-flutter/rust/src/api.rs +++ b/veilid-flutter/rust/src/api.rs @@ -1,9 +1,9 @@ -use std::sync::Arc; +use anyhow::*; +use async_std::sync::Mutex as AsyncMutex; use flutter_rust_bridge::*; use log::*; -use async_std::sync::Mutex as AsyncMutex; -use anyhow::*; use std::fmt; +use std::sync::Arc; // Globals @@ -14,9 +14,7 @@ async fn get_veilid_api() -> Result { None => { return Err(anyhow!(VeilidAPIError::NotInitialized)); } - Some(api) => { - api.clone() - } + Some(api) => api.clone(), }; Ok(veilid_api) } @@ -26,14 +24,11 @@ async fn take_veilid_api() -> Result { None => { return Err(anyhow!(VeilidAPIError::NotInitialized)); } - Some(api) => { - api - } + Some(api) => api, }; Ok(veilid_api) } - ///////////////////////////////////////// // Config Settings // Not all settings available through Veilid API are available to Flutter applications @@ -123,53 +118,103 @@ pub struct VeilidConfig { } impl VeilidConfig { - pub fn get_by_str(&self, key: &str) -> std::result::Result, String> { + 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.veilid_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()), + "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.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.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.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_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.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.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.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.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), @@ -181,34 +226,66 @@ impl VeilidConfig { "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.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.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.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.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.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()), + "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); + error!("{}", err); return Err(err); } }; @@ -288,13 +365,37 @@ impl VeilidAPIError { match api_error { veilid_core::VeilidAPIError::Timeout => VeilidAPIError::Timeout, veilid_core::VeilidAPIError::Shutdown => VeilidAPIError::Shutdown, - veilid_core::VeilidAPIError::NodeNotFound(node_id) => VeilidAPIError::NodeNotFound(format!("{}",node_id)), - veilid_core::VeilidAPIError::NoDialInfo(node_id) => VeilidAPIError::NodeNotFound(format!("{}",node_id)), + veilid_core::VeilidAPIError::NodeNotFound(node_id) => { + VeilidAPIError::NodeNotFound(format!("{}", node_id)) + } + veilid_core::VeilidAPIError::NoDialInfo(node_id) => { + VeilidAPIError::NodeNotFound(format!("{}", node_id)) + } veilid_core::VeilidAPIError::Internal(msg) => VeilidAPIError::Internal(msg.clone()), - veilid_core::VeilidAPIError::Unimplemented(msg)=> VeilidAPIError::Unimplemented(msg.clone()), - veilid_core::VeilidAPIError::ParseError{message, value} => VeilidAPIError::ParseError{ message: message.clone(), value: value.clone() }, - veilid_core::VeilidAPIError::InvalidArgument { context, argument, value } => VeilidAPIError::InvalidArgument{ context: context.clone(), argument: argument.clone(), value: value.clone() }, - veilid_core::VeilidAPIError::MissingArgument {context, argument } => VeilidAPIError::MissingArgument{ context: context.clone(), argument: argument.clone() }, + veilid_core::VeilidAPIError::Unimplemented(msg) => { + VeilidAPIError::Unimplemented(msg.clone()) + } + veilid_core::VeilidAPIError::ParseError { message, value } => { + VeilidAPIError::ParseError { + message: message.clone(), + value: value.clone(), + } + } + veilid_core::VeilidAPIError::InvalidArgument { + context, + argument, + value, + } => VeilidAPIError::InvalidArgument { + context: context.clone(), + argument: argument.clone(), + value: value.clone(), + }, + veilid_core::VeilidAPIError::MissingArgument { context, argument } => { + VeilidAPIError::MissingArgument { + context: context.clone(), + argument: argument.clone(), + } + } } } } @@ -326,21 +427,21 @@ impl AttachmentState { } } - #[derive(Debug, Clone)] pub enum VeilidUpdate { - Attachment (AttachmentState), + Attachment(AttachmentState), } impl VeilidUpdate { fn from_core(veilid_update: veilid_core::VeilidUpdate) -> Self { match veilid_update { - veilid_core::VeilidUpdate::Attachment(attachment) => Self::Attachment(AttachmentState::from_core(attachment)) + veilid_core::VeilidUpdate::Attachment(attachment) => { + Self::Attachment(AttachmentState::from_core(attachment)) + } } } } - #[derive(Debug, Clone)] pub struct VeilidState { pub attachment: AttachmentState, @@ -349,20 +450,22 @@ pub struct VeilidState { impl VeilidState { fn from_core(veilid_state: veilid_core::VeilidState) -> Self { Self { - attachment: AttachmentState::from_core(veilid_state.attachment) + attachment: AttachmentState::from_core(veilid_state.attachment), } } } ///////////////////////////////////////// -pub fn startup_veilid_core(sink: StreamSink, config: VeilidConfig) -> Result { - async_std::task::block_on( async { - +pub fn startup_veilid_core( + sink: StreamSink, + config: VeilidConfig, +) -> Result { + async_std::task::block_on(async { let mut api_lock = VEILID_API.lock().await; if api_lock.is_some() { return Err(anyhow!(VeilidAPIError::AlreadyInitialized)); } - + let core = veilid_core::VeilidCore::new(); let setup = veilid_core::VeilidCoreSetup { @@ -375,26 +478,31 @@ pub fn startup_veilid_core(sink: StreamSink, config: VeilidConfig) } }) }, - ), - config_callback: Arc::new( - move |key| { - config.get_by_str(&key) - } ), - }; + config_callback: Arc::new(move |key| config.get_by_str(&key)), + }; - let veilid_api = core.startup(setup).await.map_err(|e| VeilidAPIError::InvalidConfig(e.clone()))?; + let veilid_api = core + .startup(setup) + .await + .map_err(|e| VeilidAPIError::InvalidConfig(e.clone()))?; *api_lock = Some(veilid_api.clone()); - - let core_state = veilid_api.get_state().await.map_err(VeilidAPIError::from_core)?; + + let core_state = veilid_api + .get_state() + .await + .map_err(VeilidAPIError::from_core)?; Ok(VeilidState::from_core(core_state)) }) } pub fn get_veilid_state() -> Result { - async_std::task::block_on( async { + async_std::task::block_on(async { let veilid_api = get_veilid_api().await?; - let core_state = veilid_api.get_state().await.map_err(VeilidAPIError::from_core)?; + let core_state = veilid_api + .get_state() + .await + .map_err(VeilidAPIError::from_core)?; Ok(VeilidState::from_core(core_state)) }) } @@ -402,9 +510,9 @@ pub fn get_veilid_state() -> Result { // xxx api functions pub fn shutdown_veilid_core() -> Result<()> { - async_std::task::block_on( async { + async_std::task::block_on(async { let veilid_api = get_veilid_api().await?; - veilid_api.shutdown().await; + veilid_api.shutdown().await; Ok(()) }) } @@ -413,15 +521,17 @@ pub fn veilid_version_string() -> Result { Ok(veilid_core::veilid_version_string()) } -pub struct VeilidVersion{ +pub struct VeilidVersion { pub major: u32, - pub minor: u32, - pub patch: u32 + pub minor: u32, + pub patch: u32, } pub fn veilid_version() -> Result { let (major, minor, patch) = veilid_core::veilid_version(); Ok(VeilidVersion { - major, minor, patch + major, + minor, + patch, }) } diff --git a/veilid-flutter/rust/src/bridge_generated.rs b/veilid-flutter/rust/src/bridge_generated.rs index 11b3bf7f..3fd8758d 100644 --- a/veilid-flutter/rust/src/bridge_generated.rs +++ b/veilid-flutter/rust/src/bridge_generated.rs @@ -1,502 +1,552 @@ -#![allow(non_camel_case_types, unused, clippy::redundant_closure, clippy::useless_conversion, non_snake_case)] - // AUTO GENERATED FILE, DO NOT EDIT. +#![allow( + non_camel_case_types, + unused, + clippy::redundant_closure, + clippy::useless_conversion, + non_snake_case +)] +// AUTO GENERATED FILE, DO NOT EDIT. // Generated by `flutter_rust_bridge`. - use crate::api::*; - use flutter_rust_bridge::*; +use crate::api::*; +use flutter_rust_bridge::*; - // Section: wire functions +// Section: wire functions - - #[no_mangle] - pub extern "C" fn wire_startup_veilid_core(port_: i64, config: *mut wire_VeilidConfig) { - - FLUTTER_RUST_BRIDGE_HANDLER.wrap(WrapInfo{ debug_name: "startup_veilid_core", port: Some(port_), mode: FfiCallMode::Stream }, move || { - let api_config = config.wire2api(); - move |task_callback| startup_veilid_core(task_callback.stream_sink(), api_config) - - }) - - } - +#[no_mangle] +pub extern "C" fn wire_startup_veilid_core(port_: i64, config: *mut wire_VeilidConfig) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap( + WrapInfo { + debug_name: "startup_veilid_core", + port: Some(port_), + mode: FfiCallMode::Stream, + }, + move || { + let api_config = config.wire2api(); + move |task_callback| startup_veilid_core(task_callback.stream_sink(), api_config) + }, + ) +} +#[no_mangle] +pub extern "C" fn wire_get_veilid_state(port_: i64) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap( + WrapInfo { + debug_name: "get_veilid_state", + port: Some(port_), + mode: FfiCallMode::Normal, + }, + move || move |task_callback| get_veilid_state(), + ) +} - #[no_mangle] - pub extern "C" fn wire_get_veilid_state(port_: i64) { - - FLUTTER_RUST_BRIDGE_HANDLER.wrap(WrapInfo{ debug_name: "get_veilid_state", port: Some(port_), mode: FfiCallMode::Normal }, move || { - - move |task_callback| get_veilid_state() - - }) - - } - +#[no_mangle] +pub extern "C" fn wire_shutdown_veilid_core(port_: i64) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap( + WrapInfo { + debug_name: "shutdown_veilid_core", + port: Some(port_), + mode: FfiCallMode::Normal, + }, + move || move |task_callback| shutdown_veilid_core(), + ) +} +#[no_mangle] +pub extern "C" fn wire_veilid_version_string(port_: i64) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap( + WrapInfo { + debug_name: "veilid_version_string", + port: Some(port_), + mode: FfiCallMode::Normal, + }, + move || move |task_callback| veilid_version_string(), + ) +} - #[no_mangle] - pub extern "C" fn wire_shutdown_veilid_core(port_: i64) { - - FLUTTER_RUST_BRIDGE_HANDLER.wrap(WrapInfo{ debug_name: "shutdown_veilid_core", port: Some(port_), mode: FfiCallMode::Normal }, move || { - - move |task_callback| shutdown_veilid_core() - - }) - - } - +#[no_mangle] +pub extern "C" fn wire_veilid_version(port_: i64) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap( + WrapInfo { + debug_name: "veilid_version", + port: Some(port_), + mode: FfiCallMode::Normal, + }, + move || move |task_callback| veilid_version(), + ) +} +// Section: wire structs - #[no_mangle] - pub extern "C" fn wire_veilid_version_string(port_: i64) { - - FLUTTER_RUST_BRIDGE_HANDLER.wrap(WrapInfo{ debug_name: "veilid_version_string", port: Some(port_), mode: FfiCallMode::Normal }, move || { - - move |task_callback| veilid_version_string() - - }) - - } - +#[repr(C)] +#[derive(Clone)] +pub struct wire_StringList { + ptr: *mut *mut wire_uint_8_list, + len: i32, +} +#[repr(C)] +#[derive(Clone)] +pub struct wire_uint_8_list { + ptr: *mut u8, + len: i32, +} - #[no_mangle] - pub extern "C" fn wire_veilid_version(port_: i64) { - - FLUTTER_RUST_BRIDGE_HANDLER.wrap(WrapInfo{ debug_name: "veilid_version", port: Some(port_), mode: FfiCallMode::Normal }, move || { - - move |task_callback| veilid_version() - - }) - - } - +#[repr(C)] +#[derive(Clone)] +pub struct wire_VeilidConfig { + program_name: *mut wire_uint_8_list, + veilid_namespace: *mut wire_uint_8_list, + capabilities__protocol_udp: bool, + capabilities__protocol_connect_tcp: bool, + capabilities__protocol_accept_tcp: bool, + capabilities__protocol_connect_ws: bool, + capabilities__protocol_accept_ws: bool, + capabilities__protocol_connect_wss: bool, + capabilities__protocol_accept_wss: bool, + protected_store__allow_insecure_fallback: bool, + protected_store__always_use_insecure_storage: bool, + protected_store__insecure_fallback_directory: *mut wire_uint_8_list, + protected_store__delete: bool, + table_store__directory: *mut wire_uint_8_list, + table_store__delete: bool, + block_store__directory: *mut wire_uint_8_list, + block_store__delete: bool, + network__max_connections: u32, + network__connection_initial_timeout_ms: u32, + network__node_id: *mut wire_uint_8_list, + network__node_id_secret: *mut wire_uint_8_list, + network__bootstrap: *mut wire_StringList, + network__upnp: bool, + network__natpmp: bool, + network__enable_local_peer_scope: bool, + network__restricted_nat_retries: u32, + network__rpc__concurrency: u32, + network__rpc__queue_size: u32, + network__rpc__max_timestamp_behind_ms: *mut u32, + network__rpc__max_timestamp_ahead_ms: *mut u32, + network__rpc__timeout_ms: u32, + network__rpc__max_route_hop_count: u8, + network__dht__resolve_node_timeout_ms: *mut u32, + network__dht__resolve_node_count: u32, + network__dht__resolve_node_fanout: u32, + network__dht__max_find_node_count: u32, + network__dht__get_value_timeout_ms: *mut u32, + network__dht__get_value_count: u32, + network__dht__get_value_fanout: u32, + network__dht__set_value_timeout_ms: *mut u32, + network__dht__set_value_count: u32, + network__dht__set_value_fanout: u32, + network__dht__min_peer_count: u32, + network__dht__min_peer_refresh_time_ms: u32, + network__dht__validate_dial_info_receipt_time_ms: u32, + network__protocol__udp__enabled: bool, + network__protocol__udp__socket_pool_size: u32, + network__protocol__udp__listen_address: *mut wire_uint_8_list, + network__protocol__udp__public_address: *mut wire_uint_8_list, + network__protocol__tcp__connect: bool, + network__protocol__tcp__listen: bool, + network__protocol__tcp__max_connections: u32, + network__protocol__tcp__listen_address: *mut wire_uint_8_list, + network__protocol__tcp__public_address: *mut wire_uint_8_list, + network__protocol__ws__connect: bool, + network__protocol__ws__listen: bool, + network__protocol__ws__max_connections: u32, + network__protocol__ws__listen_address: *mut wire_uint_8_list, + network__protocol__ws__path: *mut wire_uint_8_list, + network__protocol__ws__url: *mut wire_uint_8_list, + network__protocol__wss__connect: bool, + network__protocol__wss__max_connections: u32, + network__leases__max_server_signal_leases: u32, + network__leases__max_server_relay_leases: u32, + network__leases__max_client_signal_leases: u32, + network__leases__max_client_relay_leases: u32, +} - // Section: wire structs +// Section: wire enums - +// Section: allocate functions +#[no_mangle] +pub extern "C" fn new_StringList(len: i32) -> *mut wire_StringList { + let wrap = wire_StringList { + ptr: support::new_leak_vec_ptr(<*mut wire_uint_8_list>::new_with_null_ptr(), len), + len, + }; + support::new_leak_box_ptr(wrap) +} - #[repr(C)] - #[derive(Clone)] - pub struct wire_StringList { - ptr: *mut *mut wire_uint_8_list, -len: i32 +#[no_mangle] +pub extern "C" fn new_box_autoadd_u32(value: u32) -> *mut u32 { + support::new_leak_box_ptr(value) +} + +#[no_mangle] +pub extern "C" fn new_box_autoadd_veilid_config() -> *mut wire_VeilidConfig { + support::new_leak_box_ptr(wire_VeilidConfig::new_with_null_ptr()) +} + +#[no_mangle] +pub extern "C" fn new_uint_8_list(len: i32) -> *mut wire_uint_8_list { + let ans = wire_uint_8_list { + ptr: support::new_leak_vec_ptr(Default::default(), len), + len, + }; + support::new_leak_box_ptr(ans) +} + +// Section: impl Wire2Api + +pub trait Wire2Api { + fn wire2api(self) -> T; +} + +impl Wire2Api> for *mut S +where + *mut S: Wire2Api, +{ + fn wire2api(self) -> Option { + if self.is_null() { + None + } else { + Some(self.wire2api()) } - + } +} - - - - - - - - - - - - - - - - #[repr(C)] - #[derive(Clone)] - pub struct wire_uint_8_list { - ptr: *mut u8, -len: i32 - } - - - - #[repr(C)] - #[derive(Clone)] - pub struct wire_VeilidConfig { - program_name: *mut wire_uint_8_list, -veilid_namespace: *mut wire_uint_8_list, -capabilities__protocol_udp: bool, -capabilities__protocol_connect_tcp: bool, -capabilities__protocol_accept_tcp: bool, -capabilities__protocol_connect_ws: bool, -capabilities__protocol_accept_ws: bool, -capabilities__protocol_connect_wss: bool, -capabilities__protocol_accept_wss: bool, -protected_store__allow_insecure_fallback: bool, -protected_store__always_use_insecure_storage: bool, -protected_store__insecure_fallback_directory: *mut wire_uint_8_list, -protected_store__delete: bool, -table_store__directory: *mut wire_uint_8_list, -table_store__delete: bool, -block_store__directory: *mut wire_uint_8_list, -block_store__delete: bool, -network__max_connections: u32, -network__connection_initial_timeout_ms: u32, -network__node_id: *mut wire_uint_8_list, -network__node_id_secret: *mut wire_uint_8_list, -network__bootstrap: *mut wire_StringList, -network__upnp: bool, -network__natpmp: bool, -network__enable_local_peer_scope: bool, -network__restricted_nat_retries: u32, -network__rpc__concurrency: u32, -network__rpc__queue_size: u32, -network__rpc__max_timestamp_behind_ms: *mut u32, -network__rpc__max_timestamp_ahead_ms: *mut u32, -network__rpc__timeout_ms: u32, -network__rpc__max_route_hop_count: u8, -network__dht__resolve_node_timeout_ms: *mut u32, -network__dht__resolve_node_count: u32, -network__dht__resolve_node_fanout: u32, -network__dht__max_find_node_count: u32, -network__dht__get_value_timeout_ms: *mut u32, -network__dht__get_value_count: u32, -network__dht__get_value_fanout: u32, -network__dht__set_value_timeout_ms: *mut u32, -network__dht__set_value_count: u32, -network__dht__set_value_fanout: u32, -network__dht__min_peer_count: u32, -network__dht__min_peer_refresh_time_ms: u32, -network__dht__validate_dial_info_receipt_time_ms: u32, -network__protocol__udp__enabled: bool, -network__protocol__udp__socket_pool_size: u32, -network__protocol__udp__listen_address: *mut wire_uint_8_list, -network__protocol__udp__public_address: *mut wire_uint_8_list, -network__protocol__tcp__connect: bool, -network__protocol__tcp__listen: bool, -network__protocol__tcp__max_connections: u32, -network__protocol__tcp__listen_address: *mut wire_uint_8_list, -network__protocol__tcp__public_address: *mut wire_uint_8_list, -network__protocol__ws__connect: bool, -network__protocol__ws__listen: bool, -network__protocol__ws__max_connections: u32, -network__protocol__ws__listen_address: *mut wire_uint_8_list, -network__protocol__ws__path: *mut wire_uint_8_list, -network__protocol__ws__url: *mut wire_uint_8_list, -network__protocol__wss__connect: bool, -network__protocol__wss__max_connections: u32, -network__leases__max_server_signal_leases: u32, -network__leases__max_server_relay_leases: u32, -network__leases__max_client_signal_leases: u32, -network__leases__max_client_relay_leases: u32 - } - - - // Section: wire enums - - - - // Section: allocate functions - - - - - #[no_mangle] - pub extern "C" fn new_StringList(len: i32) -> *mut wire_StringList { - let wrap = wire_StringList { ptr: support::new_leak_vec_ptr(<*mut wire_uint_8_list>::new_with_null_ptr(), len), len }; - support::new_leak_box_ptr(wrap) - } - - - - - - #[no_mangle] - pub extern "C" fn new_box_autoadd_u32(value: u32) -> *mut u32 { - support::new_leak_box_ptr(value) - } - - - - #[no_mangle] - pub extern "C" fn new_box_autoadd_veilid_config() -> *mut wire_VeilidConfig { - support::new_leak_box_ptr(wire_VeilidConfig::new_with_null_ptr()) - } - - - - - - - - - - - - #[no_mangle] - pub extern "C" fn new_uint_8_list(len: i32) -> *mut wire_uint_8_list { - let ans = wire_uint_8_list { ptr: support::new_leak_vec_ptr(Default::default(), len), len }; - support::new_leak_box_ptr(ans) - } - - - - - // Section: impl Wire2Api - - pub trait Wire2Api { - fn wire2api(self) -> T; - } - - impl Wire2Api> for *mut S - where - *mut S: Wire2Api - { - fn wire2api(self) -> Option { - if self.is_null() { - None - } else { - Some(self.wire2api()) - } - } - } - - impl Wire2Api for *mut wire_uint_8_list { - fn wire2api(self) -> String { - let vec: Vec = self.wire2api(); - String::from_utf8_lossy(&vec).into_owned() - } - } - +impl Wire2Api for *mut wire_uint_8_list { + fn wire2api(self) -> String { + let vec: Vec = self.wire2api(); + String::from_utf8_lossy(&vec).into_owned() + } +} impl Wire2Api> for *mut wire_StringList { - fn wire2api(self) -> Vec { - - let vec = unsafe { - let wrap = support::box_from_leak_ptr(self); - support::vec_from_leak_ptr(wrap.ptr, wrap.len) - }; - vec.into_iter().map(Wire2Api::wire2api).collect() - } - } - + fn wire2api(self) -> Vec { + let vec = unsafe { + let wrap = support::box_from_leak_ptr(self); + support::vec_from_leak_ptr(wrap.ptr, wrap.len) + }; + vec.into_iter().map(Wire2Api::wire2api).collect() + } +} impl Wire2Api for bool { - fn wire2api(self) -> bool { - self - } - } - + fn wire2api(self) -> bool { + self + } +} impl Wire2Api for *mut u32 { - fn wire2api(self) -> u32 { - unsafe { *support::box_from_leak_ptr(self) } - } - } - + fn wire2api(self) -> u32 { + unsafe { *support::box_from_leak_ptr(self) } + } +} impl Wire2Api for *mut wire_VeilidConfig { - fn wire2api(self) -> VeilidConfig { - let wrap = unsafe { support::box_from_leak_ptr(self) }; (*wrap).wire2api().into() - } - } - - - - - + fn wire2api(self) -> VeilidConfig { + let wrap = unsafe { support::box_from_leak_ptr(self) }; + (*wrap).wire2api().into() + } +} impl Wire2Api for u32 { - fn wire2api(self) -> u32 { - self - } - } - + fn wire2api(self) -> u32 { + self + } +} impl Wire2Api for u8 { - fn wire2api(self) -> u8 { - self - } - } - + fn wire2api(self) -> u8 { + self + } +} impl Wire2Api> for *mut wire_uint_8_list { - fn wire2api(self) -> Vec { - unsafe { - let wrap = support::box_from_leak_ptr(self); - support::vec_from_leak_ptr(wrap.ptr, wrap.len) - } - } + fn wire2api(self) -> Vec { + unsafe { + let wrap = support::box_from_leak_ptr(self); + support::vec_from_leak_ptr(wrap.ptr, wrap.len) } - + } +} impl Wire2Api for wire_VeilidConfig { - fn wire2api(self) -> VeilidConfig { - VeilidConfig{program_name: self.program_name.wire2api(),veilid_namespace: self.veilid_namespace.wire2api(),capabilities__protocol_udp: self.capabilities__protocol_udp.wire2api(),capabilities__protocol_connect_tcp: self.capabilities__protocol_connect_tcp.wire2api(),capabilities__protocol_accept_tcp: self.capabilities__protocol_accept_tcp.wire2api(),capabilities__protocol_connect_ws: self.capabilities__protocol_connect_ws.wire2api(),capabilities__protocol_accept_ws: self.capabilities__protocol_accept_ws.wire2api(),capabilities__protocol_connect_wss: self.capabilities__protocol_connect_wss.wire2api(),capabilities__protocol_accept_wss: self.capabilities__protocol_accept_wss.wire2api(),protected_store__allow_insecure_fallback: self.protected_store__allow_insecure_fallback.wire2api(),protected_store__always_use_insecure_storage: self.protected_store__always_use_insecure_storage.wire2api(),protected_store__insecure_fallback_directory: self.protected_store__insecure_fallback_directory.wire2api(),protected_store__delete: self.protected_store__delete.wire2api(),table_store__directory: self.table_store__directory.wire2api(),table_store__delete: self.table_store__delete.wire2api(),block_store__directory: self.block_store__directory.wire2api(),block_store__delete: self.block_store__delete.wire2api(),network__max_connections: self.network__max_connections.wire2api(),network__connection_initial_timeout_ms: self.network__connection_initial_timeout_ms.wire2api(),network__node_id: self.network__node_id.wire2api(),network__node_id_secret: self.network__node_id_secret.wire2api(),network__bootstrap: self.network__bootstrap.wire2api(),network__upnp: self.network__upnp.wire2api(),network__natpmp: self.network__natpmp.wire2api(),network__enable_local_peer_scope: self.network__enable_local_peer_scope.wire2api(),network__restricted_nat_retries: self.network__restricted_nat_retries.wire2api(),network__rpc__concurrency: self.network__rpc__concurrency.wire2api(),network__rpc__queue_size: self.network__rpc__queue_size.wire2api(),network__rpc__max_timestamp_behind_ms: self.network__rpc__max_timestamp_behind_ms.wire2api(),network__rpc__max_timestamp_ahead_ms: self.network__rpc__max_timestamp_ahead_ms.wire2api(),network__rpc__timeout_ms: self.network__rpc__timeout_ms.wire2api(),network__rpc__max_route_hop_count: self.network__rpc__max_route_hop_count.wire2api(),network__dht__resolve_node_timeout_ms: self.network__dht__resolve_node_timeout_ms.wire2api(),network__dht__resolve_node_count: self.network__dht__resolve_node_count.wire2api(),network__dht__resolve_node_fanout: self.network__dht__resolve_node_fanout.wire2api(),network__dht__max_find_node_count: self.network__dht__max_find_node_count.wire2api(),network__dht__get_value_timeout_ms: self.network__dht__get_value_timeout_ms.wire2api(),network__dht__get_value_count: self.network__dht__get_value_count.wire2api(),network__dht__get_value_fanout: self.network__dht__get_value_fanout.wire2api(),network__dht__set_value_timeout_ms: self.network__dht__set_value_timeout_ms.wire2api(),network__dht__set_value_count: self.network__dht__set_value_count.wire2api(),network__dht__set_value_fanout: self.network__dht__set_value_fanout.wire2api(),network__dht__min_peer_count: self.network__dht__min_peer_count.wire2api(),network__dht__min_peer_refresh_time_ms: self.network__dht__min_peer_refresh_time_ms.wire2api(),network__dht__validate_dial_info_receipt_time_ms: self.network__dht__validate_dial_info_receipt_time_ms.wire2api(),network__protocol__udp__enabled: self.network__protocol__udp__enabled.wire2api(),network__protocol__udp__socket_pool_size: self.network__protocol__udp__socket_pool_size.wire2api(),network__protocol__udp__listen_address: self.network__protocol__udp__listen_address.wire2api(),network__protocol__udp__public_address: self.network__protocol__udp__public_address.wire2api(),network__protocol__tcp__connect: self.network__protocol__tcp__connect.wire2api(),network__protocol__tcp__listen: self.network__protocol__tcp__listen.wire2api(),network__protocol__tcp__max_connections: self.network__protocol__tcp__max_connections.wire2api(),network__protocol__tcp__listen_address: self.network__protocol__tcp__listen_address.wire2api(),network__protocol__tcp__public_address: self.network__protocol__tcp__public_address.wire2api(),network__protocol__ws__connect: self.network__protocol__ws__connect.wire2api(),network__protocol__ws__listen: self.network__protocol__ws__listen.wire2api(),network__protocol__ws__max_connections: self.network__protocol__ws__max_connections.wire2api(),network__protocol__ws__listen_address: self.network__protocol__ws__listen_address.wire2api(),network__protocol__ws__path: self.network__protocol__ws__path.wire2api(),network__protocol__ws__url: self.network__protocol__ws__url.wire2api(),network__protocol__wss__connect: self.network__protocol__wss__connect.wire2api(),network__protocol__wss__max_connections: self.network__protocol__wss__max_connections.wire2api(),network__leases__max_server_signal_leases: self.network__leases__max_server_signal_leases.wire2api(),network__leases__max_server_relay_leases: self.network__leases__max_server_relay_leases.wire2api(),network__leases__max_client_signal_leases: self.network__leases__max_client_signal_leases.wire2api(),network__leases__max_client_relay_leases: self.network__leases__max_client_relay_leases.wire2api()} - } + fn wire2api(self) -> VeilidConfig { + VeilidConfig { + program_name: self.program_name.wire2api(), + veilid_namespace: self.veilid_namespace.wire2api(), + capabilities__protocol_udp: self.capabilities__protocol_udp.wire2api(), + capabilities__protocol_connect_tcp: self.capabilities__protocol_connect_tcp.wire2api(), + capabilities__protocol_accept_tcp: self.capabilities__protocol_accept_tcp.wire2api(), + capabilities__protocol_connect_ws: self.capabilities__protocol_connect_ws.wire2api(), + capabilities__protocol_accept_ws: self.capabilities__protocol_accept_ws.wire2api(), + capabilities__protocol_connect_wss: self.capabilities__protocol_connect_wss.wire2api(), + capabilities__protocol_accept_wss: self.capabilities__protocol_accept_wss.wire2api(), + protected_store__allow_insecure_fallback: self + .protected_store__allow_insecure_fallback + .wire2api(), + protected_store__always_use_insecure_storage: self + .protected_store__always_use_insecure_storage + .wire2api(), + protected_store__insecure_fallback_directory: self + .protected_store__insecure_fallback_directory + .wire2api(), + protected_store__delete: self.protected_store__delete.wire2api(), + table_store__directory: self.table_store__directory.wire2api(), + table_store__delete: self.table_store__delete.wire2api(), + block_store__directory: self.block_store__directory.wire2api(), + block_store__delete: self.block_store__delete.wire2api(), + network__max_connections: self.network__max_connections.wire2api(), + network__connection_initial_timeout_ms: self + .network__connection_initial_timeout_ms + .wire2api(), + network__node_id: self.network__node_id.wire2api(), + network__node_id_secret: self.network__node_id_secret.wire2api(), + network__bootstrap: self.network__bootstrap.wire2api(), + network__upnp: self.network__upnp.wire2api(), + network__natpmp: self.network__natpmp.wire2api(), + network__enable_local_peer_scope: self.network__enable_local_peer_scope.wire2api(), + network__restricted_nat_retries: self.network__restricted_nat_retries.wire2api(), + network__rpc__concurrency: self.network__rpc__concurrency.wire2api(), + network__rpc__queue_size: self.network__rpc__queue_size.wire2api(), + network__rpc__max_timestamp_behind_ms: self + .network__rpc__max_timestamp_behind_ms + .wire2api(), + network__rpc__max_timestamp_ahead_ms: self + .network__rpc__max_timestamp_ahead_ms + .wire2api(), + network__rpc__timeout_ms: self.network__rpc__timeout_ms.wire2api(), + network__rpc__max_route_hop_count: self.network__rpc__max_route_hop_count.wire2api(), + network__dht__resolve_node_timeout_ms: self + .network__dht__resolve_node_timeout_ms + .wire2api(), + network__dht__resolve_node_count: self.network__dht__resolve_node_count.wire2api(), + network__dht__resolve_node_fanout: self.network__dht__resolve_node_fanout.wire2api(), + network__dht__max_find_node_count: self.network__dht__max_find_node_count.wire2api(), + network__dht__get_value_timeout_ms: self.network__dht__get_value_timeout_ms.wire2api(), + network__dht__get_value_count: self.network__dht__get_value_count.wire2api(), + network__dht__get_value_fanout: self.network__dht__get_value_fanout.wire2api(), + network__dht__set_value_timeout_ms: self.network__dht__set_value_timeout_ms.wire2api(), + network__dht__set_value_count: self.network__dht__set_value_count.wire2api(), + network__dht__set_value_fanout: self.network__dht__set_value_fanout.wire2api(), + network__dht__min_peer_count: self.network__dht__min_peer_count.wire2api(), + network__dht__min_peer_refresh_time_ms: self + .network__dht__min_peer_refresh_time_ms + .wire2api(), + network__dht__validate_dial_info_receipt_time_ms: self + .network__dht__validate_dial_info_receipt_time_ms + .wire2api(), + network__protocol__udp__enabled: self.network__protocol__udp__enabled.wire2api(), + network__protocol__udp__socket_pool_size: self + .network__protocol__udp__socket_pool_size + .wire2api(), + network__protocol__udp__listen_address: self + .network__protocol__udp__listen_address + .wire2api(), + network__protocol__udp__public_address: self + .network__protocol__udp__public_address + .wire2api(), + network__protocol__tcp__connect: self.network__protocol__tcp__connect.wire2api(), + network__protocol__tcp__listen: self.network__protocol__tcp__listen.wire2api(), + network__protocol__tcp__max_connections: self + .network__protocol__tcp__max_connections + .wire2api(), + network__protocol__tcp__listen_address: self + .network__protocol__tcp__listen_address + .wire2api(), + network__protocol__tcp__public_address: self + .network__protocol__tcp__public_address + .wire2api(), + network__protocol__ws__connect: self.network__protocol__ws__connect.wire2api(), + network__protocol__ws__listen: self.network__protocol__ws__listen.wire2api(), + network__protocol__ws__max_connections: self + .network__protocol__ws__max_connections + .wire2api(), + network__protocol__ws__listen_address: self + .network__protocol__ws__listen_address + .wire2api(), + network__protocol__ws__path: self.network__protocol__ws__path.wire2api(), + network__protocol__ws__url: self.network__protocol__ws__url.wire2api(), + network__protocol__wss__connect: self.network__protocol__wss__connect.wire2api(), + network__protocol__wss__max_connections: self + .network__protocol__wss__max_connections + .wire2api(), + network__leases__max_server_signal_leases: self + .network__leases__max_server_signal_leases + .wire2api(), + network__leases__max_server_relay_leases: self + .network__leases__max_server_relay_leases + .wire2api(), + network__leases__max_client_signal_leases: self + .network__leases__max_client_signal_leases + .wire2api(), + network__leases__max_client_relay_leases: self + .network__leases__max_client_relay_leases + .wire2api(), } - - - // Section: impl NewWithNullPtr - - pub trait NewWithNullPtr { - fn new_with_null_ptr() -> Self; - } - - impl NewWithNullPtr for *mut T { - fn new_with_null_ptr() -> Self { - std::ptr::null_mut() - } - } - - - - - - - - - - - - - - - - - + } +} +// Section: impl NewWithNullPtr +pub trait NewWithNullPtr { + fn new_with_null_ptr() -> Self; +} +impl NewWithNullPtr for *mut T { + fn new_with_null_ptr() -> Self { + std::ptr::null_mut() + } +} impl NewWithNullPtr for wire_VeilidConfig { - fn new_with_null_ptr() -> Self { - Self { program_name: core::ptr::null_mut(), -veilid_namespace: core::ptr::null_mut(), -capabilities__protocol_udp: Default::default(), -capabilities__protocol_connect_tcp: Default::default(), -capabilities__protocol_accept_tcp: Default::default(), -capabilities__protocol_connect_ws: Default::default(), -capabilities__protocol_accept_ws: Default::default(), -capabilities__protocol_connect_wss: Default::default(), -capabilities__protocol_accept_wss: Default::default(), -protected_store__allow_insecure_fallback: Default::default(), -protected_store__always_use_insecure_storage: Default::default(), -protected_store__insecure_fallback_directory: core::ptr::null_mut(), -protected_store__delete: Default::default(), -table_store__directory: core::ptr::null_mut(), -table_store__delete: Default::default(), -block_store__directory: core::ptr::null_mut(), -block_store__delete: Default::default(), -network__max_connections: Default::default(), -network__connection_initial_timeout_ms: Default::default(), -network__node_id: core::ptr::null_mut(), -network__node_id_secret: core::ptr::null_mut(), -network__bootstrap: core::ptr::null_mut(), -network__upnp: Default::default(), -network__natpmp: Default::default(), -network__enable_local_peer_scope: Default::default(), -network__restricted_nat_retries: Default::default(), -network__rpc__concurrency: Default::default(), -network__rpc__queue_size: Default::default(), -network__rpc__max_timestamp_behind_ms: core::ptr::null_mut(), -network__rpc__max_timestamp_ahead_ms: core::ptr::null_mut(), -network__rpc__timeout_ms: Default::default(), -network__rpc__max_route_hop_count: Default::default(), -network__dht__resolve_node_timeout_ms: core::ptr::null_mut(), -network__dht__resolve_node_count: Default::default(), -network__dht__resolve_node_fanout: Default::default(), -network__dht__max_find_node_count: Default::default(), -network__dht__get_value_timeout_ms: core::ptr::null_mut(), -network__dht__get_value_count: Default::default(), -network__dht__get_value_fanout: Default::default(), -network__dht__set_value_timeout_ms: core::ptr::null_mut(), -network__dht__set_value_count: Default::default(), -network__dht__set_value_fanout: Default::default(), -network__dht__min_peer_count: Default::default(), -network__dht__min_peer_refresh_time_ms: Default::default(), -network__dht__validate_dial_info_receipt_time_ms: Default::default(), -network__protocol__udp__enabled: Default::default(), -network__protocol__udp__socket_pool_size: Default::default(), -network__protocol__udp__listen_address: core::ptr::null_mut(), -network__protocol__udp__public_address: core::ptr::null_mut(), -network__protocol__tcp__connect: Default::default(), -network__protocol__tcp__listen: Default::default(), -network__protocol__tcp__max_connections: Default::default(), -network__protocol__tcp__listen_address: core::ptr::null_mut(), -network__protocol__tcp__public_address: core::ptr::null_mut(), -network__protocol__ws__connect: Default::default(), -network__protocol__ws__listen: Default::default(), -network__protocol__ws__max_connections: Default::default(), -network__protocol__ws__listen_address: core::ptr::null_mut(), -network__protocol__ws__path: core::ptr::null_mut(), -network__protocol__ws__url: core::ptr::null_mut(), -network__protocol__wss__connect: Default::default(), -network__protocol__wss__max_connections: Default::default(), -network__leases__max_server_signal_leases: Default::default(), -network__leases__max_server_relay_leases: Default::default(), -network__leases__max_client_signal_leases: Default::default(), -network__leases__max_client_relay_leases: Default::default(), } - } - } + fn new_with_null_ptr() -> Self { + Self { + program_name: core::ptr::null_mut(), + veilid_namespace: core::ptr::null_mut(), + capabilities__protocol_udp: Default::default(), + capabilities__protocol_connect_tcp: Default::default(), + capabilities__protocol_accept_tcp: Default::default(), + capabilities__protocol_connect_ws: Default::default(), + capabilities__protocol_accept_ws: Default::default(), + capabilities__protocol_connect_wss: Default::default(), + capabilities__protocol_accept_wss: Default::default(), + protected_store__allow_insecure_fallback: Default::default(), + protected_store__always_use_insecure_storage: Default::default(), + protected_store__insecure_fallback_directory: core::ptr::null_mut(), + protected_store__delete: Default::default(), + table_store__directory: core::ptr::null_mut(), + table_store__delete: Default::default(), + block_store__directory: core::ptr::null_mut(), + block_store__delete: Default::default(), + network__max_connections: Default::default(), + network__connection_initial_timeout_ms: Default::default(), + network__node_id: core::ptr::null_mut(), + network__node_id_secret: core::ptr::null_mut(), + network__bootstrap: core::ptr::null_mut(), + network__upnp: Default::default(), + network__natpmp: Default::default(), + network__enable_local_peer_scope: Default::default(), + network__restricted_nat_retries: Default::default(), + network__rpc__concurrency: Default::default(), + network__rpc__queue_size: Default::default(), + network__rpc__max_timestamp_behind_ms: core::ptr::null_mut(), + network__rpc__max_timestamp_ahead_ms: core::ptr::null_mut(), + network__rpc__timeout_ms: Default::default(), + network__rpc__max_route_hop_count: Default::default(), + network__dht__resolve_node_timeout_ms: core::ptr::null_mut(), + network__dht__resolve_node_count: Default::default(), + network__dht__resolve_node_fanout: Default::default(), + network__dht__max_find_node_count: Default::default(), + network__dht__get_value_timeout_ms: core::ptr::null_mut(), + network__dht__get_value_count: Default::default(), + network__dht__get_value_fanout: Default::default(), + network__dht__set_value_timeout_ms: core::ptr::null_mut(), + network__dht__set_value_count: Default::default(), + network__dht__set_value_fanout: Default::default(), + network__dht__min_peer_count: Default::default(), + network__dht__min_peer_refresh_time_ms: Default::default(), + network__dht__validate_dial_info_receipt_time_ms: Default::default(), + network__protocol__udp__enabled: Default::default(), + network__protocol__udp__socket_pool_size: Default::default(), + network__protocol__udp__listen_address: core::ptr::null_mut(), + network__protocol__udp__public_address: core::ptr::null_mut(), + network__protocol__tcp__connect: Default::default(), + network__protocol__tcp__listen: Default::default(), + network__protocol__tcp__max_connections: Default::default(), + network__protocol__tcp__listen_address: core::ptr::null_mut(), + network__protocol__tcp__public_address: core::ptr::null_mut(), + network__protocol__ws__connect: Default::default(), + network__protocol__ws__listen: Default::default(), + network__protocol__ws__max_connections: Default::default(), + network__protocol__ws__listen_address: core::ptr::null_mut(), + network__protocol__ws__path: core::ptr::null_mut(), + network__protocol__ws__url: core::ptr::null_mut(), + network__protocol__wss__connect: Default::default(), + network__protocol__wss__max_connections: Default::default(), + network__leases__max_server_signal_leases: Default::default(), + network__leases__max_server_relay_leases: Default::default(), + network__leases__max_client_signal_leases: Default::default(), + network__leases__max_client_relay_leases: Default::default(), + } + } +} - // Section: impl IntoDart - +// Section: impl IntoDart impl support::IntoDart for AttachmentState { - fn into_dart(self) -> support::DartCObject { - match self { - Self::Detached => 0, -Self::Attaching => 1, -Self::AttachedWeak => 2, -Self::AttachedGood => 3, -Self::AttachedStrong => 4, -Self::FullyAttached => 5, -Self::OverAttached => 6, -Self::Detaching => 7, - }.into_dart() - } - } - - - - - - - - + fn into_dart(self) -> support::DartCObject { + match self { + Self::Detached => 0, + Self::Attaching => 1, + Self::AttachedWeak => 2, + Self::AttachedGood => 3, + Self::AttachedStrong => 4, + Self::FullyAttached => 5, + Self::OverAttached => 6, + Self::Detaching => 7, + } + .into_dart() + } +} impl support::IntoDart for VeilidState { - fn into_dart(self) -> support::DartCObject { - vec![ - self.attachment.into_dart() - ].into_dart() - } - } - impl support::IntoDartExceptPrimitive for VeilidState {} - + fn into_dart(self) -> support::DartCObject { + vec![self.attachment.into_dart()].into_dart() + } +} +impl support::IntoDartExceptPrimitive for VeilidState {} impl support::IntoDart for VeilidUpdate { - fn into_dart(self) -> support::DartCObject { - match self { - Self::Attachment(field0) => vec![0.into_dart(),field0.into_dart()], - }.into_dart() - } - } + fn into_dart(self) -> support::DartCObject { + match self { + Self::Attachment(field0) => vec![0.into_dart(), field0.into_dart()], + } + .into_dart() + } +} impl support::IntoDart for VeilidVersion { - fn into_dart(self) -> support::DartCObject { - vec![ - self.major.into_dart(), -self.minor.into_dart(), -self.patch.into_dart() - ].into_dart() - } - } - impl support::IntoDartExceptPrimitive for VeilidVersion {} - + fn into_dart(self) -> support::DartCObject { + vec![ + self.major.into_dart(), + self.minor.into_dart(), + self.patch.into_dart(), + ] + .into_dart() + } +} +impl support::IntoDartExceptPrimitive for VeilidVersion {} - // Section: executor - support::lazy_static! { - pub static ref FLUTTER_RUST_BRIDGE_HANDLER: support::DefaultHandler = Default::default(); - } - +// Section: executor +support::lazy_static! { + pub static ref FLUTTER_RUST_BRIDGE_HANDLER: support::DefaultHandler = Default::default(); +} - // Section: sync execution mode utility - - #[no_mangle] - pub extern "C" fn free_WireSyncReturnStruct(val: support::WireSyncReturnStruct) { - unsafe { let _ = support::vec_from_leak_ptr(val.ptr, val.len); } - } - +// Section: sync execution mode utility - \ No newline at end of file +#[no_mangle] +pub extern "C" fn free_WireSyncReturnStruct(val: support::WireSyncReturnStruct) { + unsafe { + let _ = support::vec_from_leak_ptr(val.ptr, val.len); + } +} + + // ----------- DUMMY CODE FOR BINDGEN ---------- + + // copied from: allo-isolate + pub type DartPort = i64; + pub type DartPostCObjectFnType = unsafe extern "C" fn(port_id: DartPort, message: *mut std::ffi::c_void) -> bool; + #[no_mangle] pub unsafe extern "C" fn store_dart_post_cobject(ptr: DartPostCObjectFnType) { panic!("dummy code") } + + // copied from: frb_rust::support.rs + #[repr(C)] + pub struct WireSyncReturnStruct { + pub ptr: *mut u8, + pub len: i32, + pub success: bool, + } + + // --------------------------------------------- + \ No newline at end of file diff --git a/veilid-flutter/rust/src/lib.rs b/veilid-flutter/rust/src/lib.rs index dfdd872c..6d1c5eee 100644 --- a/veilid-flutter/rust/src/lib.rs +++ b/veilid-flutter/rust/src/lib.rs @@ -1,2 +1,37 @@ mod api; mod bridge_generated; + +use cfg_if::*; + +xxx make this work + +#[cfg(all(target_os = "android", feature = "android_tests"))] +use jni::{objects::JClass, objects::JObject, JNIEnv}; + +#[cfg(all(target_os = "android", feature = "android_tests"))] +#[no_mangle] +#[allow(non_snake_case)] +pub extern "system" fn Java_com_veilid_veilidcore_veilidcore_1android_1tests_MainActivity_run_1tests( + env: JNIEnv, + _class: JClass, + ctx: JObject, +) { + crate::intf::utils::android::veilid_core_setup_android(env, ctx, "veilid_core", Level::Trace); +} + +#[cfg(target_os = "ios")] +#[no_mangle] +pub extern "C" fn run_veilid_core_tests(app_name: c_str) { + let log_path: std::path::PathBuf = [ + std::env::var("HOME").unwrap().as_str(), + "Documents", + "veilid-core.log", + ] + .iter() + .collect(); + crate::intf::utils::setup::veilid_core_setup( + "veilid-core", + Some(Level::Trace), + Some((Level::Trace, log_path.as_path())), + ); +}