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 @@ -51,7 +51,15 @@ 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") + println!( + "cargo:rerun-if-changed=../../shared/protos/identity_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/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.")) + } + } }