diff --git a/.buildkite/tunnelbroker_client.yml b/.buildkite/tunnelbroker_client.yml deleted file mode 100644 index 413d66856..000000000 --- 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 index cfaa8c5d4..06e8a5965 100644 --- a/.buildkite/tunnelbroker_unittests.yml +++ b/.buildkite/tunnelbroker_unittests.yml @@ -1,16 +1,12 @@ env: PATH: '$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:$PATH' steps: - label: ':nix: Tunnelbroker Unittests' command: - '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: - 'mac=true' diff --git a/services/tunnelbroker/Dockerfile b/services/tunnelbroker/Dockerfile index 9e3bdc73d..d4d86c7d9 100644 --- a/services/tunnelbroker/Dockerfile +++ b/services/tunnelbroker/Dockerfile @@ -1,48 +1,39 @@ FROM commapp/services-base:1.3.2 ENV PATH=/root/.cargo/bin:$PATH ARG COMM_TEST_SERVICES ARG COMM_SERVICES_SANDBOX ENV COMM_TEST_SERVICES=${COMM_TEST_SERVICES} ENV COMM_SERVICES_SANDBOX=${COMM_SERVICES_SANDBOX} # Install Curl RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y curl # Install Rust RUN curl https://sh.rustup.rs -sSf | sh -s -- -y # Copying of the installation scripts 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/ COPY shared/ shared/ # Copying of the Tunnelbroker code 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 index f328e4d9d..bab6b29ca 100644 --- a/services/tunnelbroker/build.rs +++ b/services/tunnelbroker/build.rs @@ -1 +1,12 @@ -fn main() {} +fn main() { + tonic_build::configure() + .build_server(true) + .build_client(false) + .compile( + &["../../shared/protos/tunnelbroker.proto"], + &["../../shared/protos/"], + ) + .expect("Failed to compile protobuf file"); + + println!("cargo:rerun-if-changed=../../shared/protos/tunnelbroker.proto"); +} diff --git a/services/tunnelbroker/src/cxx_bridge.rs b/services/tunnelbroker/old/cxx_bridge.rs similarity index 100% rename from services/tunnelbroker/src/cxx_bridge.rs rename to services/tunnelbroker/old/cxx_bridge.rs diff --git a/services/tunnelbroker/src/libcpp/Tunnelbroker.cpp b/services/tunnelbroker/old/libcpp/Tunnelbroker.cpp similarity index 100% rename from services/tunnelbroker/src/libcpp/Tunnelbroker.cpp rename to services/tunnelbroker/old/libcpp/Tunnelbroker.cpp diff --git a/services/tunnelbroker/src/libcpp/Tunnelbroker.h b/services/tunnelbroker/old/libcpp/Tunnelbroker.h similarity index 100% rename from services/tunnelbroker/src/libcpp/Tunnelbroker.h rename to services/tunnelbroker/old/libcpp/Tunnelbroker.h diff --git a/services/tunnelbroker/src/libcpp/src/Amqp/AmqpManager.cpp b/services/tunnelbroker/old/libcpp/src/Amqp/AmqpManager.cpp similarity index 100% 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/Amqp/AmqpManager.h b/services/tunnelbroker/old/libcpp/src/Amqp/AmqpManager.h similarity index 100% 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/Constants.h b/services/tunnelbroker/old/libcpp/src/Constants.h similarity index 100% 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.cpp b/services/tunnelbroker/old/libcpp/src/Database/DatabaseManager.cpp similarity index 100% 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/DatabaseManager.h b/services/tunnelbroker/old/libcpp/src/Database/DatabaseManager.h similarity index 100% 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/DeviceSessionItem.cpp b/services/tunnelbroker/old/libcpp/src/Database/DeviceSessionItem.cpp similarity index 100% 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/DeviceSessionItem.h b/services/tunnelbroker/old/libcpp/src/Database/DeviceSessionItem.h similarity index 100% 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/MessageItem.cpp b/services/tunnelbroker/old/libcpp/src/Database/MessageItem.cpp similarity index 100% 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/MessageItem.h b/services/tunnelbroker/old/libcpp/src/Database/MessageItem.h similarity index 100% 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/PublicKeyItem.cpp b/services/tunnelbroker/old/libcpp/src/Database/PublicKeyItem.cpp similarity index 100% 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/PublicKeyItem.h b/services/tunnelbroker/old/libcpp/src/Database/PublicKeyItem.h similarity index 100% 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/SessionSignItem.cpp b/services/tunnelbroker/old/libcpp/src/Database/SessionSignItem.cpp similarity index 100% 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/Database/SessionSignItem.h b/services/tunnelbroker/old/libcpp/src/Database/SessionSignItem.h similarity index 100% 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/DeliveryBroker/DeliveryBroker.cpp b/services/tunnelbroker/old/libcpp/src/DeliveryBroker/DeliveryBroker.cpp similarity index 100% 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/DeliveryBroker.h b/services/tunnelbroker/old/libcpp/src/DeliveryBroker/DeliveryBroker.h similarity index 100% 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/DeliveryBrokerEntites.h b/services/tunnelbroker/old/libcpp/src/DeliveryBroker/DeliveryBrokerEntites.h similarity index 100% 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.cpp b/services/tunnelbroker/old/libcpp/src/Tools/AwsTools.cpp similarity index 100% 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/AwsTools.h b/services/tunnelbroker/old/libcpp/src/Tools/AwsTools.h similarity index 100% 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/ConfigManager.cpp b/services/tunnelbroker/old/libcpp/src/Tools/ConfigManager.cpp similarity index 100% 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/ConfigManager.h b/services/tunnelbroker/old/libcpp/src/Tools/ConfigManager.h similarity index 100% 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/Tools.cpp b/services/tunnelbroker/old/libcpp/src/Tools/Tools.cpp similarity index 100% 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/src/Tools/Tools.h b/services/tunnelbroker/old/libcpp/src/Tools/Tools.h similarity index 100% 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/test/AmqpManagerTest.cpp b/services/tunnelbroker/old/libcpp/test/AmqpManagerTest.cpp similarity index 100% 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 similarity index 100% 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 similarity index 100% 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 similarity index 100% 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 similarity index 100% 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 similarity index 100% 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 similarity index 100% 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 similarity index 100% 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 similarity index 100% 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 similarity index 100% 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 similarity index 100% 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 similarity index 100% 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 similarity index 100% rename from services/tunnelbroker/src/server/tools.rs rename to services/tunnelbroker/old/server/tools.rs diff --git a/services/tunnelbroker/src/comm_server/mod.rs b/services/tunnelbroker/src/comm_server/mod.rs new file mode 100644 index 000000000..3f6201a70 --- /dev/null +++ b/services/tunnelbroker/src/comm_server/mod.rs @@ -0,0 +1,37 @@ +mod proto { + tonic::include_proto!("tunnelbroker"); +} + +use proto::tunnelbroker_service_server::{ + TunnelbrokerService, TunnelbrokerServiceServer, +}; +use tonic::transport::Server; + +use crate::constants; + +#[derive(Debug, Default)] +struct TunnelbrokerGRPC {} + +#[tonic::async_trait] +impl TunnelbrokerService for TunnelbrokerGRPC { + async fn send_message_to_device( + &self, + _request: tonic::Request, + ) -> Result, tonic::Status> { + unimplemented!() + } +} + +pub async fn run_grpc_server() -> Result<(), tonic::transport::Error> { + let addr = format!("[::1]:{}", constants::GRPC_SERVER_PORT) + .parse() + .expect("Unable to parse gRPC 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(TunnelbrokerServiceServer::new(TunnelbrokerGRPC::default())) + .serve(addr) + .await +} diff --git a/services/tunnelbroker/src/main.rs b/services/tunnelbroker/src/main.rs index b914ab240..1a6cb436f 100644 --- a/services/tunnelbroker/src/main.rs +++ b/services/tunnelbroker/src/main.rs @@ -1,13 +1,24 @@ +pub mod comm_server; pub mod constants; pub mod websockets; -use std::io; +use std::io::{self, Error, ErrorKind}; use tracing; #[tokio::main] async fn main() -> Result<(), io::Error> { let subscriber = tracing_subscriber::FmtSubscriber::new(); tracing::subscriber::set_global_default(subscriber) .expect("Unable to configure tracing"); - websockets::create_server().await + let comm_server = comm_server::run_grpc_server(); + let websocket_server = websockets::create_server(); + + tokio::select! { + Ok(_) = comm_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.")) + } + } }