forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.rs
More file actions
65 lines (54 loc) · 1.87 KB
/
setup.rs
File metadata and controls
65 lines (54 loc) · 1.87 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::sync::Arc;
use log::warn;
use tokio::task::JoinHandle;
use crate::config::Configuration;
use crate::http::Version;
use crate::jobs::{http_tracker, torrent_cleanup, tracker_apis, udp_tracker};
use crate::tracker;
/// # Panics
///
/// Will panic if the socket address for API can't be parsed.
pub async fn setup(config: &Configuration, tracker: Arc<tracker::Tracker>) -> Vec<JoinHandle<()>> {
let mut jobs: Vec<JoinHandle<()>> = Vec::new();
// Load peer keys
if tracker.is_private() {
tracker.load_keys().await.expect("Could not retrieve keys from database.");
}
// Load whitelisted torrents
if tracker.is_whitelisted() {
tracker
.load_whitelist()
.await
.expect("Could not load whitelist from database.");
}
// Start the UDP blocks
for udp_tracker_config in &config.udp_trackers {
if !udp_tracker_config.enabled {
continue;
}
if tracker.is_private() {
warn!(
"Could not start UDP tracker on: {} while in {:?}. UDP is not safe for private trackers!",
udp_tracker_config.bind_address, config.mode
);
} else {
jobs.push(udp_tracker::start_job(udp_tracker_config, tracker.clone()));
}
}
// Start the HTTP blocks
for http_tracker_config in &config.http_trackers {
if !http_tracker_config.enabled {
continue;
}
jobs.push(http_tracker::start_job(http_tracker_config, tracker.clone(), Version::Warp).await);
}
// Start HTTP API
if config.http_api.enabled {
jobs.push(tracker_apis::start_job(&config.http_api, tracker.clone()).await);
}
// Remove torrents without peers, every interval
if config.inactive_peer_cleanup_interval > 0 {
jobs.push(torrent_cleanup::start_job(config, &tracker));
}
jobs
}