diff --git a/.buildkite/tunnelbroker_client.yml b/.buildkite/tunnelbroker_client.yml deleted file mode 100644 --- a/.buildkite/tunnelbroker_client.yml +++ /dev/null @@ -1,10 +0,0 @@ -env: - PATH: '$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:$PATH' -steps: - - label: ':nix: Tunnelbroker Client (Shared)' - command: - - 'cd shared/tunnelbroker-client' - - 'rm -rf target' - - 'nix develop --accept-flake-config -c cargo test' - agents: - - 'mac=true' diff --git a/.buildkite/tunnelbroker_unittests.yml b/.buildkite/tunnelbroker_unittests.yml --- a/.buildkite/tunnelbroker_unittests.yml +++ b/.buildkite/tunnelbroker_unittests.yml @@ -6,10 +6,6 @@ - 'cd services/tunnelbroker' - 'rm -rf target' - 'nix develop --accept-flake-config -c bash -c "cargo build && cargo test"' - - 'cd src/libcpp/test' - - 'rm -rf build' - - 'nix develop --accept-flake-config -c bash -c "cmake -B build . && make -C build -j"' - - 'build/runTests --gtest_filter="-AmqpManager*:DatabaseManager*"' retry: automatic: true agents: diff --git a/services/tunnelbroker/Dockerfile b/services/tunnelbroker/Dockerfile --- a/services/tunnelbroker/Dockerfile +++ b/services/tunnelbroker/Dockerfile @@ -18,10 +18,6 @@ WORKDIR /transferred/services/tunnelbroker/docker COPY services/tunnelbroker/docker . -# Install SDKs -RUN ./install_amqp_cpp.sh -RUN ./install_libuv.sh - # Copying of the shared code WORKDIR /transferred COPY services/lib/src/ services/lib/src/ @@ -31,18 +27,13 @@ WORKDIR /transferred/services/tunnelbroker COPY services/tunnelbroker/ . -# Build C++ library gTests by CMake -WORKDIR /transferred/services/tunnelbroker/src/libcpp/test -RUN cmake -B build . && make -C build -j$(nproc) - # Build Rust by Cargo WORKDIR /transferred/services/tunnelbroker RUN cargo build --release CMD if [ "$COMM_TEST_SERVICES" -eq 1 ];\ then\ - src/libcpp/test/build/bin/runTests --gtest_filter='-AmqpManager*:DatabaseManager*'\ - && cargo test;\ + cargo test;\ else\ cargo run;\ fi diff --git a/services/tunnelbroker/build.rs b/services/tunnelbroker/build.rs --- a/services/tunnelbroker/build.rs +++ b/services/tunnelbroker/build.rs @@ -1,57 +1,10 @@ -use cxx_build::CFG; -use glob::glob; -use std::fs; -use std::path::Path; - -fn get_cpp_sources(path: &str) -> Vec { - let mut sources = vec![]; - let files = glob(String::from(path.to_owned() + "/**/*.cpp").as_str()) - .expect("Error gathering .cpp file paths"); - for entry in files { - sources.push(entry.unwrap().display().to_string()); - } - sources -} - -fn add_import_path(import_path: &str) { - let shared_headers_import_path = - fs::canonicalize(import_path).expect("Error getting full import path"); - CFG.exported_header_dirs.push(&shared_headers_import_path); -} - fn main() { - add_import_path("../lib/src"); - add_import_path("src/libcpp/src"); - add_import_path("src/libcpp/src/Amqp"); - add_import_path("src/libcpp/src/Database"); - add_import_path("src/libcpp/src/DeliveryBroker"); - add_import_path("src/libcpp/src/Tools"); - - cxx_build::bridge("src/cxx_bridge.rs") - .files(get_cpp_sources("../lib/src")) - .files(get_cpp_sources("src/libcpp/src")) - .file(Path::new("src/libcpp/Tunnelbroker.cpp")) - .flag_if_supported("-std=c++17") - .flag_if_supported("-w") - .compile("tunnelbroker"); - - println!("cargo:rustc-link-lib=boost_program_options"); - println!("cargo:rustc-link-lib=boost_system"); - println!("cargo:rustc-link-lib=folly"); - println!("cargo:rustc-link-lib=double-conversion"); - println!("cargo:rustc-link-lib=gflags"); - println!("cargo:rustc-link-lib=amqpcpp"); - println!("cargo:rustc-link-lib=glog"); - println!("cargo:rustc-link-lib=ssl"); - println!("cargo:rustc-link-lib=uv"); - println!("cargo:rustc-link-lib=aws-cpp-sdk-core"); - println!("cargo:rustc-link-lib=aws-cpp-sdk-dynamodb"); - - println!("cargo:rerun-if-changed=src/main.rs"); - println!("cargo:rerun-if-changed=src/libcpp/Tunnelbroker.h"); - println!("cargo:rerun-if-changed=src/libcpp/Tunnelbroker.cpp"); - - println!("cargo:rerun-if-changed=../../shared/protos/tunnelbroker.proto"); - tonic_build::compile_protos("../../shared/protos/tunnelbroker.proto") + tonic_build::configure() + .build_server(true) + .build_client(false) + .compile( + &["../../shared/protos/identity_tunnelbroker.proto"], + &["../../shared/protos/"], + ) .expect("Failed to compile protobuf file"); } diff --git a/services/tunnelbroker/src/cxx_bridge.rs b/services/tunnelbroker/old/cxx_bridge.rs rename from services/tunnelbroker/src/cxx_bridge.rs rename to services/tunnelbroker/old/cxx_bridge.rs diff --git a/services/tunnelbroker/src/libcpp/Tunnelbroker.h b/services/tunnelbroker/old/libcpp/Tunnelbroker.h rename from services/tunnelbroker/src/libcpp/Tunnelbroker.h rename to services/tunnelbroker/old/libcpp/Tunnelbroker.h diff --git a/services/tunnelbroker/src/libcpp/Tunnelbroker.cpp b/services/tunnelbroker/old/libcpp/Tunnelbroker.cpp rename from services/tunnelbroker/src/libcpp/Tunnelbroker.cpp rename to services/tunnelbroker/old/libcpp/Tunnelbroker.cpp diff --git a/services/tunnelbroker/src/libcpp/src/Amqp/AmqpManager.h b/services/tunnelbroker/old/libcpp/src/Amqp/AmqpManager.h rename from services/tunnelbroker/src/libcpp/src/Amqp/AmqpManager.h rename to services/tunnelbroker/old/libcpp/src/Amqp/AmqpManager.h diff --git a/services/tunnelbroker/src/libcpp/src/Amqp/AmqpManager.cpp b/services/tunnelbroker/old/libcpp/src/Amqp/AmqpManager.cpp rename from services/tunnelbroker/src/libcpp/src/Amqp/AmqpManager.cpp rename to services/tunnelbroker/old/libcpp/src/Amqp/AmqpManager.cpp diff --git a/services/tunnelbroker/src/libcpp/src/Constants.h b/services/tunnelbroker/old/libcpp/src/Constants.h rename from services/tunnelbroker/src/libcpp/src/Constants.h rename to services/tunnelbroker/old/libcpp/src/Constants.h diff --git a/services/tunnelbroker/src/libcpp/src/Database/DatabaseManager.h b/services/tunnelbroker/old/libcpp/src/Database/DatabaseManager.h rename from services/tunnelbroker/src/libcpp/src/Database/DatabaseManager.h rename to services/tunnelbroker/old/libcpp/src/Database/DatabaseManager.h diff --git a/services/tunnelbroker/src/libcpp/src/Database/DatabaseManager.cpp b/services/tunnelbroker/old/libcpp/src/Database/DatabaseManager.cpp rename from services/tunnelbroker/src/libcpp/src/Database/DatabaseManager.cpp rename to services/tunnelbroker/old/libcpp/src/Database/DatabaseManager.cpp diff --git a/services/tunnelbroker/src/libcpp/src/Database/DeviceSessionItem.h b/services/tunnelbroker/old/libcpp/src/Database/DeviceSessionItem.h rename from services/tunnelbroker/src/libcpp/src/Database/DeviceSessionItem.h rename to services/tunnelbroker/old/libcpp/src/Database/DeviceSessionItem.h diff --git a/services/tunnelbroker/src/libcpp/src/Database/DeviceSessionItem.cpp b/services/tunnelbroker/old/libcpp/src/Database/DeviceSessionItem.cpp rename from services/tunnelbroker/src/libcpp/src/Database/DeviceSessionItem.cpp rename to services/tunnelbroker/old/libcpp/src/Database/DeviceSessionItem.cpp diff --git a/services/tunnelbroker/src/libcpp/src/Database/MessageItem.h b/services/tunnelbroker/old/libcpp/src/Database/MessageItem.h rename from services/tunnelbroker/src/libcpp/src/Database/MessageItem.h rename to services/tunnelbroker/old/libcpp/src/Database/MessageItem.h diff --git a/services/tunnelbroker/src/libcpp/src/Database/MessageItem.cpp b/services/tunnelbroker/old/libcpp/src/Database/MessageItem.cpp rename from services/tunnelbroker/src/libcpp/src/Database/MessageItem.cpp rename to services/tunnelbroker/old/libcpp/src/Database/MessageItem.cpp diff --git a/services/tunnelbroker/src/libcpp/src/Database/PublicKeyItem.h b/services/tunnelbroker/old/libcpp/src/Database/PublicKeyItem.h rename from services/tunnelbroker/src/libcpp/src/Database/PublicKeyItem.h rename to services/tunnelbroker/old/libcpp/src/Database/PublicKeyItem.h diff --git a/services/tunnelbroker/src/libcpp/src/Database/PublicKeyItem.cpp b/services/tunnelbroker/old/libcpp/src/Database/PublicKeyItem.cpp rename from services/tunnelbroker/src/libcpp/src/Database/PublicKeyItem.cpp rename to services/tunnelbroker/old/libcpp/src/Database/PublicKeyItem.cpp diff --git a/services/tunnelbroker/src/libcpp/src/Database/SessionSignItem.h b/services/tunnelbroker/old/libcpp/src/Database/SessionSignItem.h rename from services/tunnelbroker/src/libcpp/src/Database/SessionSignItem.h rename to services/tunnelbroker/old/libcpp/src/Database/SessionSignItem.h diff --git a/services/tunnelbroker/src/libcpp/src/Database/SessionSignItem.cpp b/services/tunnelbroker/old/libcpp/src/Database/SessionSignItem.cpp rename from services/tunnelbroker/src/libcpp/src/Database/SessionSignItem.cpp rename to services/tunnelbroker/old/libcpp/src/Database/SessionSignItem.cpp diff --git a/services/tunnelbroker/src/libcpp/src/DeliveryBroker/DeliveryBroker.h b/services/tunnelbroker/old/libcpp/src/DeliveryBroker/DeliveryBroker.h rename from services/tunnelbroker/src/libcpp/src/DeliveryBroker/DeliveryBroker.h rename to services/tunnelbroker/old/libcpp/src/DeliveryBroker/DeliveryBroker.h diff --git a/services/tunnelbroker/src/libcpp/src/DeliveryBroker/DeliveryBroker.cpp b/services/tunnelbroker/old/libcpp/src/DeliveryBroker/DeliveryBroker.cpp rename from services/tunnelbroker/src/libcpp/src/DeliveryBroker/DeliveryBroker.cpp rename to services/tunnelbroker/old/libcpp/src/DeliveryBroker/DeliveryBroker.cpp diff --git a/services/tunnelbroker/src/libcpp/src/DeliveryBroker/DeliveryBrokerEntites.h b/services/tunnelbroker/old/libcpp/src/DeliveryBroker/DeliveryBrokerEntites.h rename from services/tunnelbroker/src/libcpp/src/DeliveryBroker/DeliveryBrokerEntites.h rename to services/tunnelbroker/old/libcpp/src/DeliveryBroker/DeliveryBrokerEntites.h diff --git a/services/tunnelbroker/src/libcpp/src/Tools/AwsTools.h b/services/tunnelbroker/old/libcpp/src/Tools/AwsTools.h rename from services/tunnelbroker/src/libcpp/src/Tools/AwsTools.h rename to services/tunnelbroker/old/libcpp/src/Tools/AwsTools.h diff --git a/services/tunnelbroker/src/libcpp/src/Tools/AwsTools.cpp b/services/tunnelbroker/old/libcpp/src/Tools/AwsTools.cpp rename from services/tunnelbroker/src/libcpp/src/Tools/AwsTools.cpp rename to services/tunnelbroker/old/libcpp/src/Tools/AwsTools.cpp diff --git a/services/tunnelbroker/src/libcpp/src/Tools/ConfigManager.h b/services/tunnelbroker/old/libcpp/src/Tools/ConfigManager.h rename from services/tunnelbroker/src/libcpp/src/Tools/ConfigManager.h rename to services/tunnelbroker/old/libcpp/src/Tools/ConfigManager.h diff --git a/services/tunnelbroker/src/libcpp/src/Tools/ConfigManager.cpp b/services/tunnelbroker/old/libcpp/src/Tools/ConfigManager.cpp rename from services/tunnelbroker/src/libcpp/src/Tools/ConfigManager.cpp rename to services/tunnelbroker/old/libcpp/src/Tools/ConfigManager.cpp diff --git a/services/tunnelbroker/src/libcpp/src/Tools/Tools.h b/services/tunnelbroker/old/libcpp/src/Tools/Tools.h rename from services/tunnelbroker/src/libcpp/src/Tools/Tools.h rename to services/tunnelbroker/old/libcpp/src/Tools/Tools.h diff --git a/services/tunnelbroker/src/libcpp/src/Tools/Tools.cpp b/services/tunnelbroker/old/libcpp/src/Tools/Tools.cpp rename from services/tunnelbroker/src/libcpp/src/Tools/Tools.cpp rename to services/tunnelbroker/old/libcpp/src/Tools/Tools.cpp diff --git a/services/tunnelbroker/src/libcpp/test/AmqpManagerTest.cpp b/services/tunnelbroker/old/libcpp/test/AmqpManagerTest.cpp rename from services/tunnelbroker/src/libcpp/test/AmqpManagerTest.cpp rename to services/tunnelbroker/old/libcpp/test/AmqpManagerTest.cpp diff --git a/services/tunnelbroker/src/libcpp/test/CMakeLists.txt b/services/tunnelbroker/old/libcpp/test/CMakeLists.txt rename from services/tunnelbroker/src/libcpp/test/CMakeLists.txt rename to services/tunnelbroker/old/libcpp/test/CMakeLists.txt diff --git a/services/tunnelbroker/src/libcpp/test/DatabaseManagerTest.cpp b/services/tunnelbroker/old/libcpp/test/DatabaseManagerTest.cpp rename from services/tunnelbroker/src/libcpp/test/DatabaseManagerTest.cpp rename to services/tunnelbroker/old/libcpp/test/DatabaseManagerTest.cpp diff --git a/services/tunnelbroker/src/libcpp/test/DeliveryBrokerTest.cpp b/services/tunnelbroker/old/libcpp/test/DeliveryBrokerTest.cpp rename from services/tunnelbroker/src/libcpp/test/DeliveryBrokerTest.cpp rename to services/tunnelbroker/old/libcpp/test/DeliveryBrokerTest.cpp diff --git a/services/tunnelbroker/src/libcpp/test/ToolsTest.cpp b/services/tunnelbroker/old/libcpp/test/ToolsTest.cpp rename from services/tunnelbroker/src/libcpp/test/ToolsTest.cpp rename to services/tunnelbroker/old/libcpp/test/ToolsTest.cpp diff --git a/services/tunnelbroker/src/libcpp/test/TunnelBrokerTest.cpp b/services/tunnelbroker/old/libcpp/test/TunnelBrokerTest.cpp rename from services/tunnelbroker/src/libcpp/test/TunnelBrokerTest.cpp rename to services/tunnelbroker/old/libcpp/test/TunnelBrokerTest.cpp diff --git a/services/tunnelbroker/src/libcpp/test/main.cpp b/services/tunnelbroker/old/libcpp/test/main.cpp rename from services/tunnelbroker/src/libcpp/test/main.cpp rename to services/tunnelbroker/old/libcpp/test/main.cpp diff --git a/services/tunnelbroker/src/notifications/apns.rs b/services/tunnelbroker/old/notifications/apns.rs rename from services/tunnelbroker/src/notifications/apns.rs rename to services/tunnelbroker/old/notifications/apns.rs diff --git a/services/tunnelbroker/src/notifications/config.rs b/services/tunnelbroker/old/notifications/config.rs rename from services/tunnelbroker/src/notifications/config.rs rename to services/tunnelbroker/old/notifications/config.rs diff --git a/services/tunnelbroker/src/notifications/fcm.rs b/services/tunnelbroker/old/notifications/fcm.rs rename from services/tunnelbroker/src/notifications/fcm.rs rename to services/tunnelbroker/old/notifications/fcm.rs diff --git a/services/tunnelbroker/src/notifications/mod.rs b/services/tunnelbroker/old/notifications/mod.rs rename from services/tunnelbroker/src/notifications/mod.rs rename to services/tunnelbroker/old/notifications/mod.rs diff --git a/services/tunnelbroker/src/server/mod.rs b/services/tunnelbroker/old/server/mod.rs rename from services/tunnelbroker/src/server/mod.rs rename to services/tunnelbroker/old/server/mod.rs diff --git a/services/tunnelbroker/src/server/tools.rs b/services/tunnelbroker/old/server/tools.rs rename from services/tunnelbroker/src/server/tools.rs rename to services/tunnelbroker/old/server/tools.rs diff --git a/services/tunnelbroker/src/identity_server/mod.rs b/services/tunnelbroker/src/identity_server/mod.rs new file mode 100644 --- /dev/null +++ b/services/tunnelbroker/src/identity_server/mod.rs @@ -0,0 +1,39 @@ +mod proto { + tonic::include_proto!("identity.tunnelbroker"); +} + +use proto::identity_tunnelbroker_service_server::{ + IdentityTunnelbrokerService, IdentityTunnelbrokerServiceServer, +}; +use tonic::transport::Server; + +use crate::constants; + +#[derive(Debug, Default)] +struct IdentityService {} + +#[tonic::async_trait] +impl IdentityTunnelbrokerService for IdentityService { + async fn refresh_device_keys( + &self, + _request: tonic::Request, + ) -> Result, tonic::Status> { + unimplemented!() + } +} + +pub async fn run_identity_server() -> Result<(), tonic::transport::Error> { + let addr = format!("[::1]:{}", constants::GRPC_SERVER_PORT) + .parse() + .expect("Unable to parse identity address"); + + tracing::info!("Websocket server listening on {}", &addr); + Server::builder() + .http2_keepalive_interval(Some(constants::GRPC_KEEP_ALIVE_PING_INTERVAL)) + .http2_keepalive_timeout(Some(constants::GRPC_KEEP_ALIVE_PING_TIMEOUT)) + .add_service(IdentityTunnelbrokerServiceServer::new( + IdentityService::default(), + )) + .serve(addr) + .await +} diff --git a/services/tunnelbroker/src/main.rs b/services/tunnelbroker/src/main.rs --- a/services/tunnelbroker/src/main.rs +++ b/services/tunnelbroker/src/main.rs @@ -1,9 +1,7 @@ pub mod constants; -pub mod cxx_bridge; -pub mod notifications; -pub mod server; +pub mod identity_server; pub mod websockets; -use std::io; +use std::io::{self, Error, ErrorKind}; use tracing; #[tokio::main] @@ -12,6 +10,15 @@ tracing::subscriber::set_global_default(subscriber) .expect("Unable to configure tracing"); - cxx_bridge::ffi::initialize(); - websockets::create_server().await + let identity_server = identity_server::run_identity_server(); + let websocket_server = websockets::create_server(); + + tokio::select! { + Ok(_) = identity_server => { Ok(()) }, + Ok(_) = websocket_server => { Ok(()) }, + else => { + tracing::error!("A grpc or websocket server crashed."); + Err(Error::new(ErrorKind::Other, "A grpc or websocket server crashed.")) + } + } }