From 02c0d065ef7470bc1429f69e790bbf325676fef0 Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 10 Jan 2022 22:36:54 -0500 Subject: [PATCH 1/3] updates and aarch64-unknown-linux-gnu build in earthly --- .cargo/config.toml | 7 ++ Cargo.lock | 95 ++++++++------- Earthfile | 29 +++-- external/keyring-manager | 2 +- veilid-cli/Cargo.toml | 6 +- veilid-cli/src/main.rs | 15 +-- veilid-core/Cargo.toml | 4 +- .../utils/network_interfaces/netlink.rs | 2 +- veilid-server/Cargo.toml | 6 +- veilid-server/src/unix.rs | 108 ++++++++++-------- 10 files changed, 149 insertions(+), 125 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..6bda8e4a --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,7 @@ +[target.aarch64-unknown-linux-gnu] +# ar = "aarch64-linux-gnu-ar" +linker = "aarch64-linux-gnu-gcc" + +[target.aarch64-linux-android] +#ar = "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar" +linker = "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-clang" \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index b19ac206..9977b279 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,15 +116,6 @@ dependencies = [ "log", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" version = "1.0.52" @@ -686,13 +677,24 @@ version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ - "ansi_term", + "bitflags", + "textwrap 0.11.0", + "unicode-width", +] + +[[package]] +name = "clap" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1957aa4a5fb388f0a0a73ce7556c5b42025b874e5cdc2c670775e346e97adec0" +dependencies = [ "atty", "bitflags", - "strsim 0.8.0", - "textwrap", - "unicode-width", - "vec_map", + "indexmap", + "os_str_bytes", + "strsim", + "termcolor", + "textwrap 0.14.2", ] [[package]] @@ -830,7 +832,7 @@ checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" dependencies = [ "atty", "cast", - "clap", + "clap 2.34.0", "criterion-plot", "csv", "itertools", @@ -1103,7 +1105,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim 0.10.0", + "strsim", "syn", ] @@ -1144,15 +1146,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "directories" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e69600ff1703123957937708eb27f7a564e48885c537782722ed0ba3189ce1d7" -dependencies = [ - "dirs-sys", -] - [[package]] name = "directories" version = "4.0.1" @@ -1836,11 +1829,11 @@ dependencies = [ "android_logger", "backtrace", "byteorder", - "cfg-if 0.1.10", - "clap", + "cfg-if 1.0.0", + "clap 3.0.6", "core-foundation 0.9.2", "core-foundation-sys 0.8.3", - "directories 4.0.1", + "directories", "fs4", "jni", "keychain-services", @@ -1848,14 +1841,13 @@ dependencies = [ "log", "ndk", "ndk-glue", - "owning_ref", "rpassword", "secret-service", "security-framework", "security-framework-sys", "serde 1.0.133", "serde_cbor", - "serial_test 0.4.0", + "serial_test 0.5.1", "simplelog", "snailquote", "tempfile", @@ -2444,6 +2436,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "os_str_bytes" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +dependencies = [ + "memchr", +] + [[package]] name = "owning_ref" version = "0.4.1" @@ -3422,12 +3423,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.10.0" @@ -3522,6 +3517,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" + [[package]] name = "thiserror" version = "1.0.30" @@ -3760,12 +3761,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "veilid-cli" version = "0.1.0" @@ -3777,14 +3772,14 @@ dependencies = [ "capnp", "capnp-rpc", "capnpc", - "cfg-if 0.1.10", - "clap", + "cfg-if 1.0.0", + "clap 3.0.6", "config 0.10.1", "crossbeam-channel", "cursive", "cursive-flexi-logger-view", "cursive_buffered_backend", - "directories 3.0.2", + "directories", "flexi_logger", "futures", "log", @@ -3813,7 +3808,7 @@ dependencies = [ "bugsalot", "capnp", "capnpc", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "chacha20poly1305", "chrono", "config 0.11.0", @@ -3821,7 +3816,7 @@ dependencies = [ "curve25519-dalek-ng", "data-encoding", "digest", - "directories 3.0.2", + "directories", "ed25519-dalek", "futures-util", "generic-array", @@ -3884,12 +3879,12 @@ dependencies = [ "capnp", "capnp-rpc", "capnpc", - "cfg-if 0.1.10", - "clap", + "cfg-if 1.0.0", + "clap 3.0.6", "config 0.11.0", "ctrlc", "daemonize", - "directories 3.0.2", + "directories", "failure", "futures", "lazy_static", diff --git a/Earthfile b/Earthfile index 65727888..a36089f6 100644 --- a/Earthfile +++ b/Earthfile @@ -12,13 +12,19 @@ deps-base: RUN apt-get install -y software-properties-common RUN add-apt-repository -y ppa:deadsnakes/ppa RUN apt-get -y update - RUN apt-get install -y iproute2 curl build-essential cmake libssl-dev openssl file git pkg-config python3.8 python3.8-distutils python3.8-dev libdbus-1-dev libdbus-glib-1-dev libgirepository1.0-dev libcairo2-dev + RUN apt-get install -y iproute2 curl build-essential cmake libssl-dev openssl file git pkg-config python3.8 python3.8-distutils python3.8-dev libdbus-1-dev libdbus-glib-1-dev libgirepository1.0-dev libcairo2-dev RUN apt-get remove -y python3.5 RUN curl https://bootstrap.pypa.io/get-pip.py | python3.8 +# Install Cap'n Proto +deps-capnp: + FROM +deps-base + COPY scripts/earthly/install_capnproto.sh / + RUN /bin/bash /install_capnproto.sh; rm /install_capnproto.sh + # Install Rust deps-rust: - FROM +deps-base + FROM +deps-capnp ENV RUSTUP_HOME=/usr/local/rustup ENV CARGO_HOME=/usr/local/cargo ENV PATH=/usr/local/cargo/bin:$PATH @@ -37,21 +43,20 @@ deps-rust: # WASM RUN rustup target add wasm32-unknown-unknown -# Install Cap'n Proto -deps-capnp: +# Install cross-platform tooling +deps-cross: FROM +deps-rust - COPY scripts/earthly/install_capnproto.sh / - RUN /bin/bash /install_capnproto.sh; rm /install_capnproto.sh + RUN apt-get install -y gcc-aarch64-linux-gnu + # Install stub secrets daemon for keyring tests deps-secretsd: - FROM +deps-capnp + FROM +deps-cross COPY scripts/earthly/secretsd /secretsd RUN pip install -r /secretsd/requirements.txt RUN pip install keyring RUN cp /secretsd/dbus/org.freedesktop.secrets.service /usr/share/dbus-1/services/org.freedesktop.secrets.service - # Clean up the apt cache to save space deps: FROM +deps-secretsd @@ -78,6 +83,10 @@ build-linux-arm64: SAVE ARTIFACT ./target/aarch64-unknown-linux-gnu AS LOCAL ./target/artifacts/aarch64-unknown-linux-gnu # Unit tests -unit-test: +unit-tests-linux-amd64: FROM +code - RUN cargo test --release + RUN cargo test --target x86_64-unknown-linux-gnu --release + +unit-tests-linux-arm64: + FROM +code + RUN cargo test --target aarch64-unknown-linux-gnu --release diff --git a/external/keyring-manager b/external/keyring-manager index 3713e105..935ca957 160000 --- a/external/keyring-manager +++ b/external/keyring-manager @@ -1 +1 @@ -Subproject commit 3713e10599c6078e058aab785ef46594420dc11b +Subproject commit 935ca957d7e223ef560a0b20b656730a325e0ba7 diff --git a/veilid-cli/Cargo.toml b/veilid-cli/Cargo.toml index 3bc60607..c0dbaed0 100644 --- a/veilid-cli/Cargo.toml +++ b/veilid-cli/Cargo.toml @@ -20,14 +20,14 @@ cursive_buffered_backend = { path = "../external/cursive_buffered_backend" } # cursive_tree_view = "0.6.0" # cursive_table_view = "0.12.0" # cursive-tabs = "0.5.0" -clap = "^2.33.2" -directories = "^3" +clap = "^3" +directories = "^4" log = "^0.4" futures = "^0.3" serde = "^1.0.122" serde_derive = "^1.0.122" parking_lot = "^0.11" -cfg-if = "^0.1" +cfg-if = "^1" capnp = "^0.14" capnp-rpc = "^0.14" config = { version = "0.10.1", features = ["yaml"] } diff --git a/veilid-cli/src/main.rs b/veilid-cli/src/main.rs index 41874b7e..27792912 100644 --- a/veilid-cli/src/main.rs +++ b/veilid-cli/src/main.rs @@ -3,7 +3,7 @@ use anyhow::*; use async_std::prelude::*; -use clap::{App, Arg}; +use clap::{App, Arg, ColorChoice}; use flexi_logger::*; use log::*; use std::ffi::OsStr; @@ -22,31 +22,32 @@ pub mod veilid_client_capnp { fn parse_command_line(default_config_path: &OsStr) -> Result { let matches = App::new("veilid-cli") .version("0.1") + .color(ColorChoice::Auto) .about("Veilid Console Client") .arg( - Arg::with_name("address") + Arg::new("address") .required(false) .help("Address to connect to"), ) .arg( - Arg::with_name("debug") + Arg::new("debug") .long("debug") .help("Turn on debug logging"), ) .arg( - Arg::with_name("wait-for-debug") + Arg::new("wait-for-debug") .long("wait-for-debug") .help("Wait for debugger to attach"), ) .arg( - Arg::with_name("trace") + Arg::new("trace") .long("trace") .conflicts_with("debug") .help("Turn on trace logging"), ) .arg( - Arg::with_name("config-file") - .short("c") + Arg::new("config-file") + .short('c') .takes_value(true) .value_name("FILE") .default_value_os(default_config_path) diff --git a/veilid-core/Cargo.toml b/veilid-core/Cargo.toml index 1cd06d85..8cad1983 100644 --- a/veilid-core/Cargo.toml +++ b/veilid-core/Cargo.toml @@ -18,7 +18,7 @@ capnp = { version = "^0", default_features = false } rust-fsm = "^0" static_assertions = "^1" log = "^0" -cfg-if = "^0" +cfg-if = "^1" anyhow = "^1" thiserror = "^1" @@ -31,7 +31,7 @@ serde-big-array = "^0" futures-util = { version = "^0", default_features = false, features = ["alloc"] } parking_lot = "^0" lazy_static = "^1" -directories = "^3" +directories = "^4" once_cell = "^1" ed25519-dalek = { version = "^1", default_features = false, features = ["alloc", "u64_backend"] } diff --git a/veilid-core/src/intf/native/utils/network_interfaces/netlink.rs b/veilid-core/src/intf/native/utils/network_interfaces/netlink.rs index a98b8644..7f698934 100644 --- a/veilid-core/src/intf/native/utils/network_interfaces/netlink.rs +++ b/veilid-core/src/intf/native/utils/network_interfaces/netlink.rs @@ -21,7 +21,7 @@ use tools::*; fn get_interface_name(index: u32) -> Result { let mut ifnamebuf = [0u8; (IF_NAMESIZE + 1)]; cfg_if! { - if #[cfg(all(target_os = "android", any(target_arch = "arm", target_arch = "aarch64")))] { + if #[cfg(all(any(target_os = "android", target_os="linux"), any(target_arch = "arm", target_arch = "aarch64")))] { if unsafe { if_indextoname(index, ifnamebuf.as_mut_ptr()) }.is_null() { return Err("if_indextoname returned null".to_owned()); } diff --git a/veilid-server/Cargo.toml b/veilid-server/Cargo.toml index 5924994f..15006e54 100644 --- a/veilid-server/Cargo.toml +++ b/veilid-server/Cargo.toml @@ -13,17 +13,17 @@ path = "src/main.rs" [dependencies] log = "^0" simplelog = { version = "^0", features = ["test"] } -clap = "^2" +clap = "^3" async-std = { version = "^1", features = ["unstable"] } async-tungstenite = { version = "^0", features = ["async-std-runtime", "async-tls"] } veilid-core = { path = "../veilid-core" } -directories = "^3" +directories = "^4" capnp = "^0" parking_lot = "^0" capnp-rpc = "^0" config = { version = "^0", features = ["yaml"] } failure = "^0" -cfg-if = "^0" +cfg-if = "^1" serde = "^1" serde_derive = "^1" serde_yaml = "^0" diff --git a/veilid-server/src/unix.rs b/veilid-server/src/unix.rs index fb4718d5..85f59193 100644 --- a/veilid-server/src/unix.rs +++ b/veilid-server/src/unix.rs @@ -17,73 +17,82 @@ use std::time::{Duration, Instant}; use veilid_core::xx::SingleShotEventual; fn parse_command_line(default_config_path: &OsStr) -> Result { + let matches = App::new("veilid-server") .version("0.1") .about("Veilid Server") + .color(clap::ColorChoice::Auto) .arg( - Arg::with_name("daemon") + Arg::new("daemon") .long("daemon") - .short("d") + .short('d') .help("Run in daemon mode in the background"), ) .arg( - Arg::with_name("subnode_index") - .long("subnode_index") - .takes_value(true) - .help("Run as an extra daemon on the same machine for testing purposes, specify a number greater than zero to offset the listening ports"), - ) - .arg( - Arg::with_name("debug") - .long("debug") - .help("Turn on debug logging on the terminal"), - ) - .arg( - Arg::with_name("trace") - .long("trace") - .conflicts_with("debug") - .help("Turn on trace logging on the terminal"), - ) - .arg( - Arg::with_name("generate-id") - .long("generate-id") - .help("Only generate a new node id and print it"), - ) - .arg( - Arg::with_name("config-file") - .short("c") + Arg::new("config-file") + .short('c') .long("config-file") .takes_value(true) .value_name("FILE") .default_value_os(default_config_path) .help("Specify a configuration file to use"), - ) - .arg( - Arg::with_name("dump-config") - .long("dump-config") - .help("Instead of running the server, print the configuration it would use to the console"), - ) - .arg( - Arg::with_name("bootstrap") - .long("bootstrap") - .takes_value(true) - .value_name("BOOTSTRAP_LIST") - .help("Specify a list of bootstrap servers to use"), - ) - .arg( - Arg::with_name("attach") + ).arg( + Arg::new("attach") .long("attach") .takes_value(true) .value_name("BOOL") .possible_values(&["false", "true"]) .help("Automatically attach the server to the Veilid network"), ) - ; - #[cfg(debug_assertions)] - let matches = matches.arg( - Arg::with_name("wait-for-debug") - .long("wait-for-debug") - .help("Wait for debugger to attach"), - ); + // Dev options + .arg( + Arg::new("debug") + .long("debug") + .help("Turn on debug logging on the terminal"), + ) + .arg( + Arg::new("trace") + .long("trace") + .conflicts_with("debug") + .help("Turn on trace logging on the terminal"), + ) + .arg( + Arg::new("subnode_index") + .long("subnode_index") + .takes_value(true) + .help("Run as an extra daemon on the same machine for testing purposes, specify a number greater than zero to offset the listening ports"), + ) + .arg( + Arg::new("generate-dht-key") + .long("generate-dht-key") + .help("Only generate a new dht key and print it"), + ) + + .arg( + Arg::new("dump-config") + .long("dump-config") + .help("Instead of running the server, print the configuration it would use to the console"), + ) + .arg( + Arg::new("bootstrap") + .long("bootstrap") + .takes_value(true) + .value_name("BOOTSTRAP_LIST") + .help("Specify a list of bootstrap servers to use"), + ) + .arg( + Arg::new("local") + .long("local") + .help("Enable local peer scope") + ); + + #[cfg(debug_assertions)] + let matches = matches.arg( + Arg::new("wait-for-debug") + .long("wait-for-debug") + .help("Wait for debugger to attach"), + ); + Ok(matches.get_matches()) } @@ -163,6 +172,9 @@ pub async fn main() -> Result<(), String> { if matches.is_present("attach") { settingsrw.auto_attach = !matches!(matches.value_of("attach"), Some("true")); } + if matches.is_present("local") { + settingsrw.core.network.enable_local_peer_scope = true; + } if matches.occurrences_of("bootstrap") != 0 { let bootstrap = match matches.value_of("bootstrap") { Some(x) => { From d979f7f5047575cef042dc66eeb67c0f6ae03533 Mon Sep 17 00:00:00 2001 From: John Smith Date: Tue, 11 Jan 2022 21:48:37 -0500 Subject: [PATCH 2/3] make android unit tests and earthly build work --- .cargo/config.toml | 10 ++++-- Earthfile | 33 ++++++++++++++++--- .../src/intf/native/protected_store.rs | 8 ++++- .../native/utils/android/get_directories.rs | 6 ++-- .../src/intf/native/utils/android/mod.rs | 9 +++++ 5 files changed, 54 insertions(+), 12 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 6bda8e4a..af7d22a8 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,7 +1,11 @@ [target.aarch64-unknown-linux-gnu] -# ar = "aarch64-linux-gnu-ar" linker = "aarch64-linux-gnu-gcc" [target.aarch64-linux-android] -#ar = "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar" -linker = "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-clang" \ No newline at end of file +linker = "/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang" +[target.armv7-linux-androideabi] +linker = "/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi30-clang" +[target.x86_64-linux-android] +linker = "/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android30-clang" +[target.i686-linux-android] +linker = "/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android30-clang" \ No newline at end of file diff --git a/Earthfile b/Earthfile index a36089f6..990ca6ce 100644 --- a/Earthfile +++ b/Earthfile @@ -43,15 +43,23 @@ deps-rust: # WASM RUN rustup target add wasm32-unknown-unknown -# Install cross-platform tooling +# Install Linux cross-platform tooling deps-cross: FROM +deps-rust - RUN apt-get install -y gcc-aarch64-linux-gnu - + RUN apt-get install -y gcc-aarch64-linux-gnu curl unzip +# Install android tooling +deps-android: + FROM +deps-cross + RUN apt-get install -y openjdk-9-jdk-headless + RUN mkdir /Android; mkdir /Android/Sdk + RUN curl -o /Android/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip + RUN cd /Android; unzip /Android/cmdline-tools.zip + RUN yes | /Android/cmdline-tools/bin/sdkmanager --sdk_root=/Android/Sdk build-tools\;30.0.3 ndk\;22.0.7026061 cmake\;3.18.1 platform-tools platforms\;android-30 + # Install stub secrets daemon for keyring tests deps-secretsd: - FROM +deps-cross + FROM +deps-android COPY scripts/earthly/secretsd /secretsd RUN pip install -r /secretsd/requirements.txt RUN pip install keyring @@ -64,7 +72,8 @@ deps: code: FROM +deps - COPY . . + COPY --dir .cargo external files scripts veilid-cli veilid-core veilid-server veilid-wasm Cargo.lock Cargo.toml /veilid + WORKDIR /veilid # Clippy only clippy: @@ -82,6 +91,20 @@ build-linux-arm64: RUN cargo build --target aarch64-unknown-linux-gnu --release SAVE ARTIFACT ./target/aarch64-unknown-linux-gnu AS LOCAL ./target/artifacts/aarch64-unknown-linux-gnu +build-android: + FROM +code + WORKDIR /veilid/veilid-core + ENV PATH=$PATH:/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/ + RUN cargo build --target aarch64-linux-android --release + RUN cargo build --target armv7-linux-androideabi --release + RUN cargo build --target i686-linux-android --release + RUN cargo build --target x86_64-linux-android --release + WORKDIR /veilid + SAVE ARTIFACT ./target/aarch64-linux-android AS LOCAL ./target/artifacts/aarch64-linux-android + SAVE ARTIFACT ./target/armv7-linux-androideabi AS LOCAL ./target/artifacts/armv7-linux-androideabi + SAVE ARTIFACT ./target/i686-linux-android AS LOCAL ./target/artifacts/i686-linux-android + SAVE ARTIFACT ./target/x86_64-linux-android AS LOCAL ./target/artifacts/x86_64-linux-android + # Unit tests unit-tests-linux-amd64: FROM +code diff --git a/veilid-core/src/intf/native/protected_store.rs b/veilid-core/src/intf/native/protected_store.rs index 8d70ff3a..d37e2057 100644 --- a/veilid-core/src/intf/native/protected_store.rs +++ b/veilid-core/src/intf/native/protected_store.rs @@ -33,7 +33,13 @@ impl ProtectedStore { let c = self.config.get(); let mut inner = self.inner.lock(); if !c.protected_store.always_use_insecure_storage { - inner.keyring_manager = KeyringManager::new_secure(&c.program_name).ok(); + cfg_if! { + if #[cfg(target_os = "android")] { + inner.keyring_manager = KeyringManager::new_secure(&c.program_name, intf::native::utils::android::get_android_globals()).ok(); + } else { + inner.keyring_manager = KeyringManager::new_secure(&c.program_name).ok(); + } + } } if (c.protected_store.always_use_insecure_storage || c.protected_store.allow_insecure_fallback) diff --git a/veilid-core/src/intf/native/utils/android/get_directories.rs b/veilid-core/src/intf/native/utils/android/get_directories.rs index ebc28032..5bd07e5c 100644 --- a/veilid-core/src/intf/native/utils/android/get_directories.rs +++ b/veilid-core/src/intf/native/utils/android/get_directories.rs @@ -6,7 +6,7 @@ pub fn get_files_dir() -> String { let ag = aglock.as_ref().unwrap(); let env = ag.vm.attach_current_thread().unwrap(); - with_null_local_frame(env, 64, || { + with_null_local_frame(*env, 64, || { // context.getFilesDir().getAbsolutePath() let file = env .call_method(ag.ctx.as_obj(), "getFilesDir", "()Ljava/io/File;", &[]) @@ -30,7 +30,7 @@ pub fn get_cache_dir() -> String { let ag = aglock.as_ref().unwrap(); let env = ag.vm.attach_current_thread().unwrap(); - with_null_local_frame(env, 64, || { + with_null_local_frame(*env, 64, || { // context.getCacheDir().getAbsolutePath() let file = env .call_method(ag.ctx.as_obj(), "getCacheDir", "()Ljava/io/File;", &[]) @@ -44,7 +44,7 @@ pub fn get_cache_dir() -> String { .unwrap(); let jstrval = env.get_string(JString::from(path)).unwrap(); - String::from(jstrval.to_string_lossy()) + Ok(String::from(jstrval.to_string_lossy())) }) .unwrap() } diff --git a/veilid-core/src/intf/native/utils/android/mod.rs b/veilid-core/src/intf/native/utils/android/mod.rs index b8552130..96c929da 100644 --- a/veilid-core/src/intf/native/utils/android/mod.rs +++ b/veilid-core/src/intf/native/utils/android/mod.rs @@ -68,6 +68,15 @@ pub fn veilid_core_setup_android<'a>( }); } +pub fn get_android_globals() -> (JavaVM, GlobalRef) { + let globals_locked = ANDROID_GLOBALS.lock(); + let globals = globals_locked.as_ref().unwrap(); + let env = globals.vm.attach_current_thread().unwrap(); + let vm = env.get_java_vm().unwrap(); + let ctx = globals.ctx.clone(); + (vm, ctx) +} + pub fn with_null_local_frame<'b, T, F>(env: JNIEnv<'b>, s: i32, f: F) -> JniResult where F: FnOnce() -> JniResult, From 746a687d9ca4b5af91b3456f9a3fd6cdb833a514 Mon Sep 17 00:00:00 2001 From: John Smith Date: Fri, 14 Jan 2022 19:13:34 -0500 Subject: [PATCH 3/3] fix mod --- veilid-core/src/intf/native/utils/network_interfaces/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/veilid-core/src/intf/native/utils/network_interfaces/mod.rs b/veilid-core/src/intf/native/utils/network_interfaces/mod.rs index 29dc2256..5b02c738 100644 --- a/veilid-core/src/intf/native/utils/network_interfaces/mod.rs +++ b/veilid-core/src/intf/native/utils/network_interfaces/mod.rs @@ -1,6 +1,7 @@ use crate::xx::*; use crate::*; use core::fmt; +mod tools; cfg_if::cfg_if! { if #[cfg(any(target_os = "linux", target_os = "android"))] {