diff --git a/src/http/axum_implementation/server.rs b/src/http/axum_implementation/server.rs index f2a7371b..a12d6033 100644 --- a/src/http/axum_implementation/server.rs +++ b/src/http/axum_implementation/server.rs @@ -11,7 +11,7 @@ use log::info; use warp::hyper; use super::routes::router; -use crate::http::tracker_interface::TrackerInterfaceTrait; +use crate::http::tracker_interface::HttpServerLauncher; use crate::tracker::Tracker; #[derive(Debug)] @@ -77,7 +77,7 @@ impl Server { } #[async_trait] -impl TrackerInterfaceTrait for Server { +impl HttpServerLauncher for Server { fn new() -> Self { Self {} } diff --git a/src/http/tracker_interface.rs b/src/http/tracker_interface.rs index 033d5a75..a8bb057d 100644 --- a/src/http/tracker_interface.rs +++ b/src/http/tracker_interface.rs @@ -7,9 +7,9 @@ use futures::future::BoxFuture; use crate::signals::shutdown_signal; use crate::tracker::Tracker; -/// Trait to be implemented by a http interface for the tracker. +/// Trait to be implemented by a http server launcher for the tracker. #[allow(clippy::module_name_repetitions)] -pub trait TrackerInterfaceTrait: Sync + Send { +pub trait HttpServerLauncher: Sync + Send { fn new() -> Self; fn start_with_graceful_shutdown( @@ -28,54 +28,54 @@ pub enum Error { } #[allow(clippy::module_name_repetitions)] -pub type StoppedHttpServer = TrackerInterface>; +pub type StoppedHttpServer = HttpServer>; #[allow(clippy::module_name_repetitions)] -pub type RunningHttpServer = TrackerInterface>; +pub type RunningHttpServer = HttpServer>; -pub struct TrackerInterface { +pub struct HttpServer { cfg: torrust_tracker_configuration::HttpTracker, state: S, } -pub struct Stopped { - interface: I, +pub struct Stopped { + launcher: I, } -pub struct Running { +pub struct Running { bind_addr: SocketAddr, task_killer: tokio::sync::oneshot::Sender, task: tokio::task::JoinHandle, } -impl TrackerInterface> { - pub fn new(cfg: torrust_tracker_configuration::HttpTracker, interface: I) -> Self { +impl HttpServer> { + pub fn new(cfg: torrust_tracker_configuration::HttpTracker, launcher: I) -> Self { Self { cfg, - state: Stopped { interface }, + state: Stopped { launcher }, } } - pub async fn start(self, tracker: Arc) -> Result>, Error> { + pub async fn start(self, tracker: Arc) -> Result>, Error> { let (shutdown_sender, shutdown_receiver) = tokio::sync::oneshot::channel::(); let (addr_sender, addr_receiver) = tokio::sync::oneshot::channel::(); let configuration = self.cfg.clone(); - let interface = self.state.interface; + let launcher = self.state.launcher; let task = tokio::spawn(async move { let (bind_addr, server) = - interface.start_with_graceful_shutdown(configuration, tracker, shutdown_signal(shutdown_receiver)); + launcher.start_with_graceful_shutdown(configuration, tracker, shutdown_signal(shutdown_receiver)); addr_sender.send(bind_addr).unwrap(); server.await; - interface + launcher }); let bind_address = addr_receiver.await.expect("Could not receive bind_address."); - Ok(TrackerInterface { + Ok(HttpServer { cfg: self.cfg, state: Running { bind_addr: bind_address, @@ -86,15 +86,15 @@ impl TrackerInterface> { } } -impl TrackerInterface> { - pub async fn stop(self) -> Result>, Error> { +impl HttpServer> { + pub async fn stop(self) -> Result>, Error> { self.state.task_killer.send(0).unwrap(); - let interface = self.state.task.await.map_err(|e| Error::Error(e.to_string()))?; + let launcher = self.state.task.await.map_err(|e| Error::Error(e.to_string()))?; - Ok(TrackerInterface { + Ok(HttpServer { cfg: self.cfg, - state: Stopped { interface }, + state: Stopped { launcher }, }) } } diff --git a/src/http/warp_implementation/server.rs b/src/http/warp_implementation/server.rs index 6b0665fc..8d01559f 100644 --- a/src/http/warp_implementation/server.rs +++ b/src/http/warp_implementation/server.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use futures::future::BoxFuture; use super::routes; -use crate::http::tracker_interface::TrackerInterfaceTrait; +use crate::http::tracker_interface::HttpServerLauncher; use crate::tracker; use crate::tracker::Tracker; @@ -50,7 +50,7 @@ impl Server { } } -impl TrackerInterfaceTrait for Server { +impl HttpServerLauncher for Server { fn new() -> Self { Self {} } diff --git a/tests/http/test_environment.rs b/tests/http/test_environment.rs index f6770b2a..87232f79 100644 --- a/tests/http/test_environment.rs +++ b/tests/http/test_environment.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use torrust_tracker::http::tracker_interface::{RunningHttpServer, StoppedHttpServer, TrackerInterface, TrackerInterfaceTrait}; +use torrust_tracker::http::tracker_interface::{HttpServer, HttpServerLauncher, RunningHttpServer, StoppedHttpServer}; use torrust_tracker::protocol::info_hash::InfoHash; use torrust_tracker::tracker::peer::Peer; use torrust_tracker::tracker::Tracker; @@ -18,11 +18,11 @@ pub struct TestEnvironment { } #[allow(dead_code)] -pub struct Stopped { +pub struct Stopped { http_server: StoppedHttpServer, } -pub struct Running { +pub struct Running { http_server: RunningHttpServer, } @@ -33,7 +33,7 @@ impl TestEnvironment { } } -impl TestEnvironment> { +impl TestEnvironment> { #[allow(dead_code)] pub fn new_stopped() -> Self { let cfg = tracker_configuration(); @@ -59,7 +59,7 @@ impl TestEnvironment> { } } -impl TestEnvironment> { +impl TestEnvironment> { pub async fn new_running() -> Self { let test_env = StoppedTestEnvironment::new_stopped(); @@ -77,19 +77,24 @@ impl TestEnvironment> { } #[allow(clippy::module_name_repetitions)] -pub async fn running_test_environment() -> RunningTestEnvironment { +pub async fn stopped_test_environment() -> StoppedTestEnvironment { + TestEnvironment::new_stopped().await +} + +#[allow(clippy::module_name_repetitions)] +pub async fn running_test_environment() -> RunningTestEnvironment { TestEnvironment::new_running().await } -pub fn stopped_http_server( +pub fn stopped_http_server( cfg: torrust_tracker_configuration::HttpTracker, ) -> StoppedHttpServer { let http_server = I::new(); - TrackerInterface::new(cfg, http_server) + HttpServer::new(cfg, http_server) } -pub async fn running_http_server( +pub async fn running_http_server( cfg: torrust_tracker_configuration::HttpTracker, tracker: Arc, ) -> RunningHttpServer {