diff --git a/.gitignore b/.gitignore index c4b19ec8a..5836fe390 100644 --- a/.gitignore +++ b/.gitignore @@ -1,36 +1,37 @@ .DS_Store node_modules landing/node_modules landing/dist lib/node_modules native/cpp/CommonCpp/CryptoTools/opaque-ke-cxx/target web/node_modules web/dist keyserver/dist keyserver/node_modules keyserver/secrets keyserver/facts keyserver/*.env keyserver/*.env.* services/identity/target services/tunnelbroker/rust-notifications/target .eslintcache .vscode !.vscode/extensions.json # CMake native/cpp/**/build services/*/build services/build services/lib/src/build # Nix result* +services/backup/rust_lib/target/ diff --git a/services/backup/rust_lib/Cargo.lock b/services/backup/rust_lib/Cargo.lock index 531e9b84e..96128e46c 100644 --- a/services/backup/rust_lib/Cargo.lock +++ b/services/backup/rust_lib/Cargo.lock @@ -1,173 +1,261 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + [[package]] name = "cc" version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" [[package]] name = "codespan-reporting" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" dependencies = [ "termcolor", "unicode-width", ] [[package]] name = "cxx" version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "873c2e83af70859af2aaecd1f5d862f3790b747b1f4f50fb45a931d000ac0422" dependencies = [ "cc", "cxxbridge-flags", "cxxbridge-macro", "link-cplusplus", ] [[package]] name = "cxx-build" version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b49edea7163bbc7a39e3d829b4b0b66a9d30486973152842b7413f2c7b5632bf" dependencies = [ "cc", "codespan-reporting", "once_cell", "proc-macro2", "quote", "scratch", "syn", ] [[package]] name = "cxxbridge-flags" version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46b787c15af80277db5c88c6ac6c502ae545e622f010e06f95e540d34931acf" [[package]] name = "cxxbridge-macro" version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ba3f3a7efa46626878fb5d324fabca4d19d2956b6ae97ce43044ef4515f5abc" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "futures-core" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2acedae88d38235936c3922476b10fced7b2b68136f5e3c03c2d5be348a1115" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.132" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" + [[package]] name = "link-cplusplus" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8cae2cd7ba2f3f63938b9c724475dfb7b9861b545a90324476324ed21dbc8c8" dependencies = [ "cc", ] +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "once_cell" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + [[package]] name = "proc-macro2" version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] [[package]] name = "rust_lib" version = "0.1.0" dependencies = [ "cxx", "cxx-build", + "lazy_static", + "libc", + "tokio", + "tokio-stream", ] [[package]] name = "scratch" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" [[package]] name = "syn" version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "termcolor" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] +[[package]] +name = "tokio" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +dependencies = [ + "autocfg", + "num_cpus", + "once_cell", + "pin-project-lite", + "tokio-macros", +] + +[[package]] +name = "tokio-macros" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-stream" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df54d54117d6fdc4e4fea40fe1e4e566b3505700e148a6827e59b34b0d2600d9" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "unicode-ident" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "unicode-width" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ "winapi", ] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/services/backup/rust_lib/Cargo.toml b/services/backup/rust_lib/Cargo.toml index a18805f0d..ad08d10fa 100644 --- a/services/backup/rust_lib/Cargo.toml +++ b/services/backup/rust_lib/Cargo.toml @@ -1,20 +1,24 @@ [package] name = "rust_lib" version = "0.1.0" edition = "2021" [dependencies] cxx = "1.0" +tokio = { version = "1.20", features = ["macros", "rt-multi-thread"] } +tokio-stream = "0.1" +lazy_static = "1.4" +libc = "0.2" [build-dependencies] cxx-build = "1.0" [lib] crate-type = ["staticlib"] [profile.release] panic = "abort" [profile.dev] debug = true panic = "abort" diff --git a/services/backup/rust_lib/src/constants.rs b/services/backup/rust_lib/src/constants.rs new file mode 100644 index 000000000..e658d56c5 --- /dev/null +++ b/services/backup/rust_lib/src/constants.rs @@ -0,0 +1 @@ +pub const MPSC_CHANNEL_BUFFER_CAPACITY: usize = 1; diff --git a/services/backup/rust_lib/src/lib.rs b/services/backup/rust_lib/src/lib.rs index 33c1cad16..da9d3b81f 100644 --- a/services/backup/rust_lib/src/lib.rs +++ b/services/backup/rust_lib/src/lib.rs @@ -1,10 +1,52 @@ #[cxx::bridge] mod ffi { extern "Rust" { - fn test_function() -> i32; + fn rust_is_initialized_cxx() -> bool; + fn rust_initialize_cxx() -> (); + unsafe fn rust_process_cxx(_: *const c_char) -> (); + fn rust_terminate_cxx() -> (); } } -pub fn test_function() -> i32 { - 0 +use lazy_static::lazy_static; +use libc; +use libc::c_char; +use std::sync::{Arc, Mutex}; +use tokio::runtime::Runtime; +use tokio::sync::mpsc; +use tokio::task::JoinHandle; + +pub struct Client { + tx: Option>, + handle: Option>, +} + +lazy_static! { + pub static ref CLIENT: Arc> = Arc::new(Mutex::new(Client { + tx: None, + handle: None + })); + pub static ref RUNTIME: Runtime = Runtime::new().unwrap(); +} + +pub fn rust_is_initialized_cxx() -> bool { + if CLIENT.lock().expect("access client").tx.is_none() { + return false; + } + if CLIENT.lock().expect("access client").handle.is_none() { + return false; + } + return true; +} + +pub fn rust_initialize_cxx() -> () { + unimplemented!(); +} + +pub fn rust_process_cxx(_: *const c_char) -> () { + unimplemented!(); +} + +pub fn rust_terminate_cxx() -> () { + unimplemented!(); }