Skip to content

Commit 4f2b035

Browse files
mickvandijkejosecelano
authored andcommitted
refactor: renamed TrackerInterface struct and relevant trait
1 parent f40e43f commit 4f2b035

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

src/http/axum_implementation/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use log::info;
1111
use warp::hyper;
1212

1313
use super::routes::router;
14-
use crate::http::tracker_interface::TrackerInterfaceTrait;
14+
use crate::http::tracker_interface::HttpServerLauncher;
1515
use crate::tracker::Tracker;
1616

1717
#[derive(Debug)]
@@ -77,7 +77,7 @@ impl Server {
7777
}
7878

7979
#[async_trait]
80-
impl TrackerInterfaceTrait for Server {
80+
impl HttpServerLauncher for Server {
8181
fn new() -> Self {
8282
Self {}
8383
}

src/http/tracker_interface.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use futures::future::BoxFuture;
77
use crate::signals::shutdown_signal;
88
use crate::tracker::Tracker;
99

10-
/// Trait to be implemented by a http interface for the tracker.
10+
/// Trait to be implemented by a http server launcher for the tracker.
1111
#[allow(clippy::module_name_repetitions)]
12-
pub trait TrackerInterfaceTrait: Sync + Send {
12+
pub trait HttpServerLauncher: Sync + Send {
1313
fn new() -> Self;
1414

1515
fn start_with_graceful_shutdown<F>(
@@ -28,54 +28,54 @@ pub enum Error {
2828
}
2929

3030
#[allow(clippy::module_name_repetitions)]
31-
pub type StoppedHttpServer<I> = TrackerInterface<Stopped<I>>;
31+
pub type StoppedHttpServer<I> = HttpServer<Stopped<I>>;
3232
#[allow(clippy::module_name_repetitions)]
33-
pub type RunningHttpServer<I> = TrackerInterface<Running<I>>;
33+
pub type RunningHttpServer<I> = HttpServer<Running<I>>;
3434

35-
pub struct TrackerInterface<S> {
35+
pub struct HttpServer<S> {
3636
cfg: torrust_tracker_configuration::HttpTracker,
3737
state: S,
3838
}
3939

40-
pub struct Stopped<I: TrackerInterfaceTrait> {
41-
interface: I,
40+
pub struct Stopped<I: HttpServerLauncher> {
41+
launcher: I,
4242
}
4343

44-
pub struct Running<I: TrackerInterfaceTrait> {
44+
pub struct Running<I: HttpServerLauncher> {
4545
bind_addr: SocketAddr,
4646
task_killer: tokio::sync::oneshot::Sender<u8>,
4747
task: tokio::task::JoinHandle<I>,
4848
}
4949

50-
impl<I: TrackerInterfaceTrait + 'static> TrackerInterface<Stopped<I>> {
51-
pub fn new(cfg: torrust_tracker_configuration::HttpTracker, interface: I) -> Self {
50+
impl<I: HttpServerLauncher + 'static> HttpServer<Stopped<I>> {
51+
pub fn new(cfg: torrust_tracker_configuration::HttpTracker, launcher: I) -> Self {
5252
Self {
5353
cfg,
54-
state: Stopped { interface },
54+
state: Stopped { launcher },
5555
}
5656
}
5757

58-
pub async fn start(self, tracker: Arc<Tracker>) -> Result<TrackerInterface<Running<I>>, Error> {
58+
pub async fn start(self, tracker: Arc<Tracker>) -> Result<HttpServer<Running<I>>, Error> {
5959
let (shutdown_sender, shutdown_receiver) = tokio::sync::oneshot::channel::<u8>();
6060
let (addr_sender, addr_receiver) = tokio::sync::oneshot::channel::<SocketAddr>();
6161

6262
let configuration = self.cfg.clone();
63-
let interface = self.state.interface;
63+
let launcher = self.state.launcher;
6464

6565
let task = tokio::spawn(async move {
6666
let (bind_addr, server) =
67-
interface.start_with_graceful_shutdown(configuration, tracker, shutdown_signal(shutdown_receiver));
67+
launcher.start_with_graceful_shutdown(configuration, tracker, shutdown_signal(shutdown_receiver));
6868

6969
addr_sender.send(bind_addr).unwrap();
7070

7171
server.await;
7272

73-
interface
73+
launcher
7474
});
7575

7676
let bind_address = addr_receiver.await.expect("Could not receive bind_address.");
7777

78-
Ok(TrackerInterface {
78+
Ok(HttpServer {
7979
cfg: self.cfg,
8080
state: Running {
8181
bind_addr: bind_address,
@@ -86,15 +86,15 @@ impl<I: TrackerInterfaceTrait + 'static> TrackerInterface<Stopped<I>> {
8686
}
8787
}
8888

89-
impl<I: TrackerInterfaceTrait> TrackerInterface<Running<I>> {
90-
pub async fn stop(self) -> Result<TrackerInterface<Stopped<I>>, Error> {
89+
impl<I: HttpServerLauncher> HttpServer<Running<I>> {
90+
pub async fn stop(self) -> Result<HttpServer<Stopped<I>>, Error> {
9191
self.state.task_killer.send(0).unwrap();
9292

93-
let interface = self.state.task.await.map_err(|e| Error::Error(e.to_string()))?;
93+
let launcher = self.state.task.await.map_err(|e| Error::Error(e.to_string()))?;
9494

95-
Ok(TrackerInterface {
95+
Ok(HttpServer {
9696
cfg: self.cfg,
97-
state: Stopped { interface },
97+
state: Stopped { launcher },
9898
})
9999
}
100100
}

src/http/warp_implementation/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::Arc;
66
use futures::future::BoxFuture;
77

88
use super::routes;
9-
use crate::http::tracker_interface::TrackerInterfaceTrait;
9+
use crate::http::tracker_interface::HttpServerLauncher;
1010
use crate::tracker;
1111
use crate::tracker::Tracker;
1212

@@ -50,7 +50,7 @@ impl Server {
5050
}
5151
}
5252

53-
impl TrackerInterfaceTrait for Server {
53+
impl HttpServerLauncher for Server {
5454
fn new() -> Self {
5555
Self {}
5656
}

tests/http/test_environment.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use torrust_tracker::http::tracker_interface::{RunningHttpServer, StoppedHttpServer, TrackerInterface, TrackerInterfaceTrait};
3+
use torrust_tracker::http::tracker_interface::{HttpServer, HttpServerLauncher, RunningHttpServer, StoppedHttpServer};
44
use torrust_tracker::protocol::info_hash::InfoHash;
55
use torrust_tracker::tracker::peer::Peer;
66
use torrust_tracker::tracker::Tracker;
@@ -18,11 +18,11 @@ pub struct TestEnvironment<S> {
1818
}
1919

2020
#[allow(dead_code)]
21-
pub struct Stopped<I: TrackerInterfaceTrait> {
21+
pub struct Stopped<I: HttpServerLauncher> {
2222
http_server: StoppedHttpServer<I>,
2323
}
2424

25-
pub struct Running<I: TrackerInterfaceTrait> {
25+
pub struct Running<I: HttpServerLauncher> {
2626
http_server: RunningHttpServer<I>,
2727
}
2828

@@ -33,7 +33,7 @@ impl<S> TestEnvironment<S> {
3333
}
3434
}
3535

36-
impl<I: TrackerInterfaceTrait + 'static> TestEnvironment<Stopped<I>> {
36+
impl<I: HttpServerLauncher + 'static> TestEnvironment<Stopped<I>> {
3737
#[allow(dead_code)]
3838
pub fn new_stopped() -> Self {
3939
let cfg = tracker_configuration();
@@ -59,7 +59,7 @@ impl<I: TrackerInterfaceTrait + 'static> TestEnvironment<Stopped<I>> {
5959
}
6060
}
6161

62-
impl<I: TrackerInterfaceTrait + 'static> TestEnvironment<Running<I>> {
62+
impl<I: HttpServerLauncher + 'static> TestEnvironment<Running<I>> {
6363
pub async fn new_running() -> Self {
6464
let test_env = StoppedTestEnvironment::new_stopped();
6565

@@ -77,19 +77,24 @@ impl<I: TrackerInterfaceTrait + 'static> TestEnvironment<Running<I>> {
7777
}
7878

7979
#[allow(clippy::module_name_repetitions)]
80-
pub async fn running_test_environment<I: TrackerInterfaceTrait + 'static>() -> RunningTestEnvironment<I> {
80+
pub async fn stopped_test_environment<I: HttpServerLauncher + 'static>() -> StoppedTestEnvironment<I> {
81+
TestEnvironment::new_stopped().await
82+
}
83+
84+
#[allow(clippy::module_name_repetitions)]
85+
pub async fn running_test_environment<I: HttpServerLauncher + 'static>() -> RunningTestEnvironment<I> {
8186
TestEnvironment::new_running().await
8287
}
8388

84-
pub fn stopped_http_server<I: TrackerInterfaceTrait + 'static>(
89+
pub fn stopped_http_server<I: HttpServerLauncher + 'static>(
8590
cfg: torrust_tracker_configuration::HttpTracker,
8691
) -> StoppedHttpServer<I> {
8792
let http_server = I::new();
8893

89-
TrackerInterface::new(cfg, http_server)
94+
HttpServer::new(cfg, http_server)
9095
}
9196

92-
pub async fn running_http_server<I: TrackerInterfaceTrait + 'static>(
97+
pub async fn running_http_server<I: HttpServerLauncher + 'static>(
9398
cfg: torrust_tracker_configuration::HttpTracker,
9499
tracker: Arc<Tracker>,
95100
) -> RunningHttpServer<I> {

0 commit comments

Comments
 (0)