From ea0032f42bb4afb22841a7d822830d1b4a73d6a1 Mon Sep 17 00:00:00 2001 From: JuArce <52429267+JuArce@users.noreply.github.com> Date: Fri, 9 Jan 2026 16:44:49 -0300 Subject: [PATCH 1/3] expose non tls port --- aggregation_mode/gateway/src/config.rs | 2 ++ aggregation_mode/gateway/src/http.rs | 45 ++++++++++++++------------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/aggregation_mode/gateway/src/config.rs b/aggregation_mode/gateway/src/config.rs index e8899d435..3c7978f12 100644 --- a/aggregation_mode/gateway/src/config.rs +++ b/aggregation_mode/gateway/src/config.rs @@ -14,6 +14,8 @@ pub struct Config { pub tls_cert_path: String, #[cfg(feature = "tls")] pub tls_key_path: String, + #[cfg(feature = "tls")] + pub tls_port: u16, } impl Config { diff --git a/aggregation_mode/gateway/src/http.rs b/aggregation_mode/gateway/src/http.rs index 3d1753075..b779a9eca 100644 --- a/aggregation_mode/gateway/src/http.rs +++ b/aggregation_mode/gateway/src/http.rs @@ -86,7 +86,7 @@ impl GatewayServer { pub async fn start(&self) { // Note: GatewayServer is thread safe so we can just clone it (no need to add mutexes) - let port = self.config.port; + let http_port = self.config.port; let state = self.clone(); // Note: This creates a new Prometheus server different from the one created in GatewayServer::new. The created @@ -96,18 +96,6 @@ impl GatewayServer { .build() .unwrap(); - #[cfg(feature = "tls")] - let protocol = "https"; - #[cfg(not(feature = "tls"))] - let protocol = "http"; - - tracing::info!( - "Starting server at {}://{}:{}", - protocol, - self.config.ip, - self.config.port - ); - let server = HttpServer::new(move || { App::new() .app_data(Data::new(state.clone())) @@ -121,21 +109,36 @@ impl GatewayServer { }); #[cfg(feature = "tls")] - let server = { + { + let tls_port = self.config.tls_port; + tracing::info!("Starting HTTP server at http://{}:{}", self.config.ip, http_port); + tracing::info!("Starting HTTPS server at https://{}:{}", self.config.ip, tls_port); + let tls_config = Self::load_tls_config(&self.config.tls_cert_path, &self.config.tls_key_path) .expect("Failed to load TLS configuration"); + server - .bind_rustls_0_23((self.config.ip.as_str(), port), tls_config) - .expect("To bind socket correctly with TLS") - }; + .bind((self.config.ip.as_str(), http_port)) + .expect("To bind HTTP socket correctly") + .bind_rustls_0_23((self.config.ip.as_str(), tls_port), tls_config) + .expect("To bind HTTPS socket correctly with TLS") + .run() + .await + .expect("Server to never end"); + } #[cfg(not(feature = "tls"))] - let server = server - .bind((self.config.ip.as_str(), port)) - .expect("To bind socket correctly"); + { + tracing::info!("Starting HTTP server at http://{}:{}", self.config.ip, http_port); - server.run().await.expect("Server to never end"); + server + .bind((self.config.ip.as_str(), http_port)) + .expect("To bind HTTP socket correctly") + .run() + .await + .expect("Server to never end"); + } } // Returns an OK response (code 200), no matters what receives in the request From 34b1103184ae761fc8001dcba546ba80a4f7a6dc Mon Sep 17 00:00:00 2001 From: JuArce <52429267+JuArce@users.noreply.github.com> Date: Fri, 9 Jan 2026 17:01:29 -0300 Subject: [PATCH 2/3] cargo fmt --- aggregation_mode/gateway/src/http.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/aggregation_mode/gateway/src/http.rs b/aggregation_mode/gateway/src/http.rs index b779a9eca..b5da7b38a 100644 --- a/aggregation_mode/gateway/src/http.rs +++ b/aggregation_mode/gateway/src/http.rs @@ -111,8 +111,16 @@ impl GatewayServer { #[cfg(feature = "tls")] { let tls_port = self.config.tls_port; - tracing::info!("Starting HTTP server at http://{}:{}", self.config.ip, http_port); - tracing::info!("Starting HTTPS server at https://{}:{}", self.config.ip, tls_port); + tracing::info!( + "Starting HTTP server at http://{}:{}", + self.config.ip, + http_port + ); + tracing::info!( + "Starting HTTPS server at https://{}:{}", + self.config.ip, + tls_port + ); let tls_config = Self::load_tls_config(&self.config.tls_cert_path, &self.config.tls_key_path) @@ -130,7 +138,11 @@ impl GatewayServer { #[cfg(not(feature = "tls"))] { - tracing::info!("Starting HTTP server at http://{}:{}", self.config.ip, http_port); + tracing::info!( + "Starting HTTP server at http://{}:{}", + self.config.ip, + http_port + ); server .bind((self.config.ip.as_str(), http_port)) From 1bba4853eeb336e72e64a68c90bb8cedb9f765e9 Mon Sep 17 00:00:00 2001 From: JuArce <52429267+JuArce@users.noreply.github.com> Date: Fri, 9 Jan 2026 17:49:35 -0300 Subject: [PATCH 3/3] remove duplicated code --- aggregation_mode/gateway/src/http.rs | 40 +++++++++------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/aggregation_mode/gateway/src/http.rs b/aggregation_mode/gateway/src/http.rs index b5da7b38a..795b5ac65 100644 --- a/aggregation_mode/gateway/src/http.rs +++ b/aggregation_mode/gateway/src/http.rs @@ -108,14 +108,19 @@ impl GatewayServer { .route("/quotas/{address}", web::get().to(Self::get_quotas)) }); + tracing::info!( + "Starting HTTP server at http://{}:{}", + self.config.ip, + http_port + ); + + let server = server + .bind((self.config.ip.as_str(), http_port)) + .expect("To bind HTTP socket correctly"); + #[cfg(feature = "tls")] - { + let server = { let tls_port = self.config.tls_port; - tracing::info!( - "Starting HTTP server at http://{}:{}", - self.config.ip, - http_port - ); tracing::info!( "Starting HTTPS server at https://{}:{}", self.config.ip, @@ -127,30 +132,11 @@ impl GatewayServer { .expect("Failed to load TLS configuration"); server - .bind((self.config.ip.as_str(), http_port)) - .expect("To bind HTTP socket correctly") .bind_rustls_0_23((self.config.ip.as_str(), tls_port), tls_config) .expect("To bind HTTPS socket correctly with TLS") - .run() - .await - .expect("Server to never end"); - } - - #[cfg(not(feature = "tls"))] - { - tracing::info!( - "Starting HTTP server at http://{}:{}", - self.config.ip, - http_port - ); + }; - server - .bind((self.config.ip.as_str(), http_port)) - .expect("To bind HTTP socket correctly") - .run() - .await - .expect("Server to never end"); - } + server.run().await.expect("Server to never end"); } // Returns an OK response (code 200), no matters what receives in the request