forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathudp_tracker.rs
More file actions
37 lines (33 loc) · 1.23 KB
/
udp_tracker.rs
File metadata and controls
37 lines (33 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! UDP tracker job starter.
//!
//! The [`udp_tracker::start_job`](crate::bootstrap::jobs::udp_tracker::start_job)
//! function starts a new UDP tracker server.
//!
//! > **NOTICE**: that the application can launch more than one UDP tracker
//! on different ports. Refer to the [configuration documentation](https://docs.rs/torrust-tracker-configuration)
//! for the configuration options.
use std::sync::Arc;
use log::{error, info, warn};
use tokio::task::JoinHandle;
use torrust_tracker_configuration::UdpTracker;
use crate::core;
use crate::servers::udp::server::Udp;
/// It starts a new UDP server with the provided configuration.
///
/// It spawns a new asynchronous task for the new UDP server.
#[must_use]
pub fn start_job(config: &UdpTracker, tracker: Arc<core::Tracker>) -> JoinHandle<()> {
let bind_addr = config.bind_address.clone();
tokio::spawn(async move {
match Udp::new(&bind_addr).await {
Ok(udp_server) => {
info!("Starting UDP server on: udp://{}", bind_addr);
udp_server.start(tracker).await;
}
Err(e) => {
warn!("Could not start UDP tracker on: udp://{}", bind_addr);
error!("{}", e);
}
}
})
}