Skip to content

Commit 00f6855

Browse files
committed
Merge #1210: Overhaul core Tracker: remove deprecated core::Tracker
85a2a29 refactor: [#1209] inline core Tracker methods (Jose Celano) Pull request description: Overhaul core Tracker: remove deprecated `core::Tracker` ACKs for top commit: josecelano: ACK 85a2a29 Tree-SHA512: e5d78b3ebfb2b92d09b5c6cc677c7b657ab85deadf2ae8b2cee744b709a7e11df8f27a51106e6c0c99d848dc7283a067e75dbf7f155d4ecd5d8174225cbc1875
2 parents 5f65e16 + 85a2a29 commit 00f6855

File tree

18 files changed

+255
-89
lines changed

18 files changed

+255
-89
lines changed

src/app.rs

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
//! - UDP trackers: the user can enable multiple UDP tracker on several ports.
2222
//! - HTTP trackers: the user can enable multiple HTTP tracker on several ports.
2323
//! - Tracker REST API: the tracker API can be enabled/disabled.
24+
use std::sync::Arc;
25+
2426
use tokio::task::JoinHandle;
2527
use torrust_tracker_configuration::Configuration;
2628
use tracing::instrument;
@@ -78,6 +80,7 @@ pub async fn start(config: &Configuration, app_container: &AppContainer) -> Vec<
7880
} else {
7981
jobs.push(
8082
udp_tracker::start_job(
83+
Arc::new(config.core.clone()),
8184
udp_tracker_config,
8285
app_container.tracker.clone(),
8386
app_container.announce_handler.clone(),
@@ -100,6 +103,7 @@ pub async fn start(config: &Configuration, app_container: &AppContainer) -> Vec<
100103
for http_tracker_config in http_trackers {
101104
if let Some(job) = http_tracker::start_job(
102105
http_tracker_config,
106+
Arc::new(config.core.clone()),
103107
app_container.tracker.clone(),
104108
app_container.announce_handler.clone(),
105109
app_container.scrape_handler.clone(),

src/bootstrap/jobs/http_tracker.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::sync::Arc;
1515

1616
use axum_server::tls_rustls::RustlsConfig;
1717
use tokio::task::JoinHandle;
18-
use torrust_tracker_configuration::HttpTracker;
18+
use torrust_tracker_configuration::{Core, HttpTracker};
1919
use tracing::instrument;
2020

2121
use super::make_rust_tls;
@@ -49,6 +49,7 @@ use crate::servers::registar::ServiceRegistrationForm;
4949
))]
5050
pub async fn start_job(
5151
config: &HttpTracker,
52+
core_config: Arc<Core>,
5253
tracker: Arc<core::Tracker>,
5354
announce_handler: Arc<AnnounceHandler>,
5455
scrape_handler: Arc<ScrapeHandler>,
@@ -69,6 +70,7 @@ pub async fn start_job(
6970
start_v1(
7071
socket,
7172
tls,
73+
core_config.clone(),
7274
tracker.clone(),
7375
announce_handler.clone(),
7476
scrape_handler.clone(),
@@ -97,6 +99,7 @@ pub async fn start_job(
9799
async fn start_v1(
98100
socket: SocketAddr,
99101
tls: Option<RustlsConfig>,
102+
config: Arc<Core>,
100103
tracker: Arc<core::Tracker>,
101104
announce_handler: Arc<AnnounceHandler>,
102105
scrape_handler: Arc<ScrapeHandler>,
@@ -107,6 +110,7 @@ async fn start_v1(
107110
) -> JoinHandle<()> {
108111
let server = HttpServer::new(Launcher::new(socket, tls))
109112
.start(
113+
config,
110114
tracker,
111115
announce_handler,
112116
scrape_handler,
@@ -156,6 +160,7 @@ mod tests {
156160

157161
start_job(
158162
config,
163+
Arc::new(cfg.core.clone()),
159164
app_container.tracker,
160165
app_container.announce_handler,
161166
app_container.scrape_handler,

src/bootstrap/jobs/udp_tracker.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::sync::Arc;
1010

1111
use tokio::sync::RwLock;
1212
use tokio::task::JoinHandle;
13-
use torrust_tracker_configuration::UdpTracker;
13+
use torrust_tracker_configuration::{Core, UdpTracker};
1414
use tracing::instrument;
1515

1616
use crate::core::announce_handler::AnnounceHandler;
@@ -46,6 +46,7 @@ use crate::servers::udp::UDP_TRACKER_LOG_TARGET;
4646
form
4747
))]
4848
pub async fn start_job(
49+
core_config: Arc<Core>,
4950
config: &UdpTracker,
5051
tracker: Arc<core::Tracker>,
5152
announce_handler: Arc<AnnounceHandler>,
@@ -60,6 +61,7 @@ pub async fn start_job(
6061

6162
let server = Server::new(Spawner::new(bind_to))
6263
.start(
64+
core_config,
6365
tracker,
6466
announce_handler,
6567
scrape_handler,

src/core/mod.rs

+4-27
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,11 @@ pub mod whitelist;
451451

452452
pub mod peer_tests;
453453

454-
use std::net::IpAddr;
455454
use std::sync::Arc;
456455

457456
use torrent::repository::in_memory::InMemoryTorrentRepository;
458457
use torrent::repository::persisted::DatabasePersistentTorrentRepository;
459-
use torrust_tracker_configuration::{AnnouncePolicy, Core};
458+
use torrust_tracker_configuration::Core;
460459

461460
/// The domain layer tracker service.
462461
///
@@ -469,7 +468,7 @@ use torrust_tracker_configuration::{AnnouncePolicy, Core};
469468
/// > the network layer.
470469
pub struct Tracker {
471470
/// The tracker configuration.
472-
config: Core,
471+
_core_config: Core,
473472

474473
/// The in-memory torrents repository.
475474
_in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
@@ -485,38 +484,16 @@ impl Tracker {
485484
///
486485
/// Will return a `databases::error::Error` if unable to connect to database. The `Tracker` is responsible for the persistence.
487486
pub fn new(
488-
config: &Core,
487+
core_config: &Core,
489488
in_memory_torrent_repository: &Arc<InMemoryTorrentRepository>,
490489
db_torrent_repository: &Arc<DatabasePersistentTorrentRepository>,
491490
) -> Result<Tracker, databases::error::Error> {
492491
Ok(Tracker {
493-
config: config.clone(),
492+
_core_config: core_config.clone(),
494493
_in_memory_torrent_repository: in_memory_torrent_repository.clone(),
495494
_db_torrent_repository: db_torrent_repository.clone(),
496495
})
497496
}
498-
499-
/// Returns `true` if the tracker requires authentication.
500-
#[must_use]
501-
pub fn requires_authentication(&self) -> bool {
502-
self.config.private
503-
}
504-
505-
/// Returns `true` is the tracker is in whitelisted mode.
506-
#[must_use]
507-
pub fn is_behind_reverse_proxy(&self) -> bool {
508-
self.config.net.on_reverse_proxy
509-
}
510-
511-
#[must_use]
512-
pub fn get_announce_policy(&self) -> AnnouncePolicy {
513-
self.config.announce_policy
514-
}
515-
516-
#[must_use]
517-
pub fn get_maybe_external_ip(&self) -> Option<IpAddr> {
518-
self.config.net.external_ip
519-
}
520497
}
521498

522499
#[cfg(test)]

src/servers/http/server.rs

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use axum_server::Handle;
77
use derive_more::Constructor;
88
use futures::future::BoxFuture;
99
use tokio::sync::oneshot::{Receiver, Sender};
10+
use torrust_tracker_configuration::Core;
1011
use tracing::instrument;
1112

1213
use super::v1::routes::router;
@@ -59,6 +60,7 @@ impl Launcher {
5960
))]
6061
fn start(
6162
&self,
63+
config: Arc<Core>,
6264
tracker: Arc<Tracker>,
6365
announce_handler: Arc<AnnounceHandler>,
6466
scrape_handler: Arc<ScrapeHandler>,
@@ -85,6 +87,7 @@ impl Launcher {
8587
tracing::info!(target: HTTP_TRACKER_LOG_TARGET, "Starting on: {protocol}://{}", address);
8688

8789
let app = router(
90+
config,
8891
tracker,
8992
announce_handler,
9093
scrape_handler,
@@ -188,6 +191,7 @@ impl HttpServer<Stopped> {
188191
#[allow(clippy::too_many_arguments)]
189192
pub async fn start(
190193
self,
194+
core_config: Arc<Core>,
191195
tracker: Arc<Tracker>,
192196
announce_handler: Arc<AnnounceHandler>,
193197
scrape_handler: Arc<ScrapeHandler>,
@@ -203,6 +207,7 @@ impl HttpServer<Stopped> {
203207

204208
let task = tokio::spawn(async move {
205209
let server = launcher.start(
210+
core_config,
206211
tracker,
207212
announce_handler,
208213
scrape_handler,
@@ -309,6 +314,7 @@ mod tests {
309314
let stopped = HttpServer::new(Launcher::new(bind_to, tls));
310315
let started = stopped
311316
.start(
317+
Arc::new(cfg.core.clone()),
312318
app_container.tracker,
313319
app_container.announce_handler,
314320
app_container.scrape_handler,

0 commit comments

Comments
 (0)