@@ -7,13 +7,13 @@ use axum_server::Handle;
77use bittorrent_http_tracker_core:: container:: HttpTrackerCoreContainer ;
88use derive_more:: Constructor ;
99use futures:: future:: BoxFuture ;
10- use reqwest:: Url ;
1110use tokio:: sync:: oneshot:: { Receiver , Sender } ;
1211use torrust_axum_server:: custom_axum_server:: { self , TimeoutAcceptor } ;
1312use torrust_axum_server:: signals:: graceful_shutdown;
1413use torrust_server_lib:: logging:: STARTED_ON ;
1514use torrust_server_lib:: registar:: { ServiceHealthCheckJob , ServiceRegistration , ServiceRegistrationForm } ;
1615use torrust_server_lib:: signals:: { Halted , Started } ;
16+ use torrust_tracker_primitives:: service_binding:: { Protocol , ServiceBinding } ;
1717use tracing:: instrument;
1818
1919use super :: v1:: routes:: router;
@@ -63,9 +63,8 @@ impl Launcher {
6363 ) ) ;
6464
6565 let tls = self . tls . clone ( ) ;
66- let protocol = if tls. is_some ( ) { "https" } else { "http" } ;
67- let listen_url =
68- Url :: parse ( & format ! ( "{protocol}://{address}" ) ) . expect ( "Could not parse internal service url for HTTP tracker." ) ;
66+ let protocol = if tls. is_some ( ) { Protocol :: HTTPS } else { Protocol :: HTTP } ;
67+ let service_binding = ServiceBinding :: new ( protocol. clone ( ) , address) . expect ( "Service binding creation failed" ) ;
6968
7069 tracing:: info!( target: HTTP_TRACKER_LOG_TARGET , "Starting on: {protocol}://{address}" ) ;
7170
@@ -93,7 +92,10 @@ impl Launcher {
9392 tracing:: info!( target: HTTP_TRACKER_LOG_TARGET , "{STARTED_ON}: {protocol}://{}" , address) ;
9493
9594 tx_start
96- . send ( Started { listen_url, address } )
95+ . send ( Started {
96+ service_binding,
97+ address,
98+ } )
9799 . expect ( "the HTTP(s) Tracker service should not be dropped" ) ;
98100
99101 running
@@ -182,10 +184,10 @@ impl HttpServer<Stopped> {
182184
183185 let started = rx_start. await . expect ( "it should be able to start the service" ) ;
184186
185- let listen_url = started. listen_url ;
187+ let listen_url = started. service_binding ;
186188 let binding = started. address ;
187189
188- form. send ( ServiceRegistration :: new ( listen_url, binding , check_fn) )
190+ form. send ( ServiceRegistration :: new ( listen_url, check_fn) )
189191 . expect ( "it should be able to send service registration" ) ;
190192
191193 Ok ( HttpServer {
@@ -226,8 +228,8 @@ impl HttpServer<Running> {
226228/// This function will return an error if unable to connect.
227229/// Or if the request returns an error.
228230#[ must_use]
229- pub fn check_fn ( listen_url : & Url , binding : & SocketAddr ) -> ServiceHealthCheckJob {
230- let url = format ! ( "http://{binding }/health_check" ) ; // DevSkim: ignore DS137138
231+ pub fn check_fn ( service_binding : & ServiceBinding ) -> ServiceHealthCheckJob {
232+ let url = format ! ( "http://{}/health_check" , service_binding . bind_address ( ) ) ; // DevSkim: ignore DS137138
231233
232234 let info = format ! ( "checking http tracker health check at: {url}" ) ;
233235
@@ -238,7 +240,7 @@ pub fn check_fn(listen_url: &Url, binding: &SocketAddr) -> ServiceHealthCheckJob
238240 }
239241 } ) ;
240242
241- ServiceHealthCheckJob :: new ( listen_url . clone ( ) , * binding , info, TYPE_STRING . to_string ( ) , job)
243+ ServiceHealthCheckJob :: new ( service_binding . clone ( ) , info, TYPE_STRING . to_string ( ) , job)
242244}
243245
244246#[ cfg( test) ]
0 commit comments