Skip to content

Commit c121bf2

Browse files
committed
refactor: rename UDP server types
1 parent 336e0e6 commit c121bf2

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

src/bootstrap/jobs/udp_tracker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tracing::debug;
1414

1515
use crate::core;
1616
use crate::servers::registar::ServiceRegistrationForm;
17-
use crate::servers::udp::server::{Launcher, UdpServer};
17+
use crate::servers::udp::server::{Spawner, UdpServer};
1818
use crate::servers::udp::UDP_TRACKER_LOG_TARGET;
1919

2020
/// It starts a new UDP server with the provided configuration.
@@ -30,7 +30,7 @@ use crate::servers::udp::UDP_TRACKER_LOG_TARGET;
3030
pub async fn start_job(config: &UdpTracker, tracker: Arc<core::Tracker>, form: ServiceRegistrationForm) -> JoinHandle<()> {
3131
let bind_to = config.bind_address;
3232

33-
let server = UdpServer::new(Launcher::new(bind_to))
33+
let server = UdpServer::new(Spawner::new(bind_to))
3434
.start(tracker, form)
3535
.await
3636
.expect("it should be able to start the udp tracker");

src/servers/udp/server/mod.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub struct UdpServer<S> {
9696
/// A stopped UDP server state.
9797
9898
pub struct Stopped {
99-
launcher: Launcher,
99+
launcher: Spawner,
100100
}
101101

102102
/// A running UDP server state.
@@ -105,13 +105,13 @@ pub struct Running {
105105
/// The address where the server is bound.
106106
pub binding: SocketAddr,
107107
pub halt_task: tokio::sync::oneshot::Sender<Halted>,
108-
pub task: JoinHandle<Launcher>,
108+
pub task: JoinHandle<Spawner>,
109109
}
110110

111111
impl UdpServer<Stopped> {
112112
/// Creates a new `UdpServer` instance in `stopped`state.
113113
#[must_use]
114-
pub fn new(launcher: Launcher) -> Self {
114+
pub fn new(launcher: Spawner) -> Self {
115115
Self {
116116
state: Stopped { launcher },
117117
}
@@ -140,7 +140,7 @@ impl UdpServer<Stopped> {
140140
let binding = rx_start.await.expect("it should be able to start the service").address;
141141
let local_addr = format!("udp://{binding}");
142142

143-
form.send(ServiceRegistration::new(binding, Udp::check))
143+
form.send(ServiceRegistration::new(binding, Launcher::check))
144144
.expect("it should be able to send service registration");
145145

146146
let running_udp_server: UdpServer<Running> = UdpServer {
@@ -186,12 +186,12 @@ impl UdpServer<Running> {
186186
}
187187

188188
#[derive(Constructor, Copy, Clone, Debug)]
189-
pub struct Launcher {
189+
pub struct Spawner {
190190
bind_to: SocketAddr,
191191
}
192192

193-
impl Launcher {
194-
/// It starts the UDP server instance.
193+
impl Spawner {
194+
/// It spawns a new tasks to run the UDP server instance.
195195
///
196196
/// # Panics
197197
///
@@ -201,10 +201,10 @@ impl Launcher {
201201
tracker: Arc<Tracker>,
202202
tx_start: oneshot::Sender<Started>,
203203
rx_halt: oneshot::Receiver<Halted>,
204-
) -> JoinHandle<Launcher> {
205-
let launcher = Launcher::new(self.bind_to);
204+
) -> JoinHandle<Spawner> {
205+
let launcher = Spawner::new(self.bind_to);
206206
tokio::spawn(async move {
207-
Udp::run_with_graceful_shutdown(tracker, launcher.bind_to, tx_start, rx_halt).await;
207+
Launcher::run_with_graceful_shutdown(tracker, launcher.bind_to, tx_start, rx_halt).await;
208208
launcher
209209
})
210210
}
@@ -388,9 +388,9 @@ impl Stream for Receiver {
388388

389389
/// A UDP server instance launcher.
390390
#[derive(Constructor)]
391-
pub struct Udp;
391+
pub struct Launcher;
392392

393-
impl Udp {
393+
impl Launcher {
394394
/// It starts the UDP server instance with graceful shutdown.
395395
///
396396
/// # Panics
@@ -502,7 +502,8 @@ impl Udp {
502502
*/
503503

504504
let abort_handle =
505-
tokio::task::spawn(Udp::process_request(req, tracker.clone(), receiver.bound_socket.clone())).abort_handle();
505+
tokio::task::spawn(Launcher::process_request(req, tracker.clone(), receiver.bound_socket.clone()))
506+
.abort_handle();
506507

507508
if abort_handle.is_finished() {
508509
continue;
@@ -589,7 +590,7 @@ mod tests {
589590

590591
use crate::bootstrap::app::initialize_with_configuration;
591592
use crate::servers::registar::Registar;
592-
use crate::servers::udp::server::{Launcher, UdpServer};
593+
use crate::servers::udp::server::{Spawner, UdpServer};
593594

594595
#[tokio::test]
595596
async fn it_should_be_able_to_start_and_stop() {
@@ -600,7 +601,7 @@ mod tests {
600601
let bind_to = config.bind_address;
601602
let register = &Registar::default();
602603

603-
let stopped = UdpServer::new(Launcher::new(bind_to));
604+
let stopped = UdpServer::new(Spawner::new(bind_to));
604605

605606
let started = stopped
606607
.start(tracker, register.give_form())
@@ -622,7 +623,7 @@ mod tests {
622623
let bind_to = config.bind_address;
623624
let register = &Registar::default();
624625

625-
let stopped = UdpServer::new(Launcher::new(bind_to));
626+
let stopped = UdpServer::new(Spawner::new(bind_to));
626627

627628
let started = stopped
628629
.start(tracker, register.give_form())

tests/servers/udp/environment.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::sync::Arc;
44
use torrust_tracker::bootstrap::app::initialize_with_configuration;
55
use torrust_tracker::core::Tracker;
66
use torrust_tracker::servers::registar::Registar;
7-
use torrust_tracker::servers::udp::server::{Launcher, Running, Stopped, UdpServer};
7+
use torrust_tracker::servers::udp::server::{Running, Spawner, Stopped, UdpServer};
88
use torrust_tracker::shared::bit_torrent::tracker::udp::client::DEFAULT_TIMEOUT;
99
use torrust_tracker_configuration::{Configuration, UdpTracker};
1010
use torrust_tracker_primitives::info_hash::InfoHash;
@@ -36,7 +36,7 @@ impl Environment<Stopped> {
3636

3737
let bind_to = config.bind_address;
3838

39-
let server = UdpServer::new(Launcher::new(bind_to));
39+
let server = UdpServer::new(Spawner::new(bind_to));
4040

4141
Self {
4242
config,

0 commit comments

Comments
 (0)