diff --git a/services/tunnelbroker/src/comm_server/mod.rs b/services/tunnelbroker/src/grpc/mod.rs similarity index 93% rename from services/tunnelbroker/src/comm_server/mod.rs rename to services/tunnelbroker/src/grpc/mod.rs index 3f6201a70..435a4a4f0 100644 --- a/services/tunnelbroker/src/comm_server/mod.rs +++ b/services/tunnelbroker/src/grpc/mod.rs @@ -1,37 +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> { +pub async fn run_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 1a6cb436f..f12543c8e 100644 --- a/services/tunnelbroker/src/main.rs +++ b/services/tunnelbroker/src/main.rs @@ -1,24 +1,24 @@ -pub mod comm_server; pub mod constants; +pub mod grpc; pub mod websockets; 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"); - let comm_server = comm_server::run_grpc_server(); - let websocket_server = websockets::create_server(); + let grpc_server = grpc::run_server(); + let websocket_server = websockets::run_server(); tokio::select! { - Ok(_) = comm_server => { Ok(()) }, + Ok(_) = grpc_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.")) } } } diff --git a/services/tunnelbroker/src/websockets/mod.rs b/services/tunnelbroker/src/websockets/mod.rs index 9fd60135b..c8b4948b0 100644 --- a/services/tunnelbroker/src/websockets/mod.rs +++ b/services/tunnelbroker/src/websockets/mod.rs @@ -1,22 +1,22 @@ use std::{env, io::Error}; use tokio::net::{TcpListener, TcpStream}; use tracing::info; -pub async fn create_server() -> Result<(), Error> { +pub async fn run_server() -> Result<(), Error> { let addr = env::var("COMM_TUNNELBROKER_WEBSOCKET_ADDR") .unwrap_or_else(|_| "127.0.0.1:51001".to_string()); let listener = TcpListener::bind(&addr).await.expect("Failed to bind"); info!("Listening on: {}", addr); while let Ok((stream, _)) = listener.accept().await { tokio::spawn(accept_connection(stream)); } Ok(()) } async fn accept_connection(_stream: TcpStream) { unimplemented!() }