Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul core Tracker: remove deprecated core::Tracker #1210

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
//! - UDP trackers: the user can enable multiple UDP tracker on several ports.
//! - HTTP trackers: the user can enable multiple HTTP tracker on several ports.
//! - Tracker REST API: the tracker API can be enabled/disabled.
use std::sync::Arc;

use tokio::task::JoinHandle;
use torrust_tracker_configuration::Configuration;
use tracing::instrument;
Expand Down Expand Up @@ -78,6 +80,7 @@ pub async fn start(config: &Configuration, app_container: &AppContainer) -> Vec<
} else {
jobs.push(
udp_tracker::start_job(
Arc::new(config.core.clone()),
udp_tracker_config,
app_container.tracker.clone(),
app_container.announce_handler.clone(),
Expand All @@ -100,6 +103,7 @@ pub async fn start(config: &Configuration, app_container: &AppContainer) -> Vec<
for http_tracker_config in http_trackers {
if let Some(job) = http_tracker::start_job(
http_tracker_config,
Arc::new(config.core.clone()),
app_container.tracker.clone(),
app_container.announce_handler.clone(),
app_container.scrape_handler.clone(),
Expand Down
7 changes: 6 additions & 1 deletion src/bootstrap/jobs/http_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::sync::Arc;

use axum_server::tls_rustls::RustlsConfig;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::HttpTracker;
use torrust_tracker_configuration::{Core, HttpTracker};
use tracing::instrument;

use super::make_rust_tls;
Expand Down Expand Up @@ -49,6 +49,7 @@ use crate::servers::registar::ServiceRegistrationForm;
))]
pub async fn start_job(
config: &HttpTracker,
core_config: Arc<Core>,
tracker: Arc<core::Tracker>,
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
Expand All @@ -69,6 +70,7 @@ pub async fn start_job(
start_v1(
socket,
tls,
core_config.clone(),
tracker.clone(),
announce_handler.clone(),
scrape_handler.clone(),
Expand Down Expand Up @@ -97,6 +99,7 @@ pub async fn start_job(
async fn start_v1(
socket: SocketAddr,
tls: Option<RustlsConfig>,
config: Arc<Core>,
tracker: Arc<core::Tracker>,
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
Expand All @@ -107,6 +110,7 @@ async fn start_v1(
) -> JoinHandle<()> {
let server = HttpServer::new(Launcher::new(socket, tls))
.start(
config,
tracker,
announce_handler,
scrape_handler,
Expand Down Expand Up @@ -156,6 +160,7 @@ mod tests {

start_job(
config,
Arc::new(cfg.core.clone()),
app_container.tracker,
app_container.announce_handler,
app_container.scrape_handler,
Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/jobs/udp_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::sync::Arc;

use tokio::sync::RwLock;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::UdpTracker;
use torrust_tracker_configuration::{Core, UdpTracker};
use tracing::instrument;

use crate::core::announce_handler::AnnounceHandler;
Expand Down Expand Up @@ -46,6 +46,7 @@ use crate::servers::udp::UDP_TRACKER_LOG_TARGET;
form
))]
pub async fn start_job(
core_config: Arc<Core>,
config: &UdpTracker,
tracker: Arc<core::Tracker>,
announce_handler: Arc<AnnounceHandler>,
Expand All @@ -60,6 +61,7 @@ pub async fn start_job(

let server = Server::new(Spawner::new(bind_to))
.start(
core_config,
tracker,
announce_handler,
scrape_handler,
Expand Down
31 changes: 4 additions & 27 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,11 @@ pub mod whitelist;

pub mod peer_tests;

use std::net::IpAddr;
use std::sync::Arc;

use torrent::repository::in_memory::InMemoryTorrentRepository;
use torrent::repository::persisted::DatabasePersistentTorrentRepository;
use torrust_tracker_configuration::{AnnouncePolicy, Core};
use torrust_tracker_configuration::Core;

/// The domain layer tracker service.
///
Expand All @@ -469,7 +468,7 @@ use torrust_tracker_configuration::{AnnouncePolicy, Core};
/// > the network layer.
pub struct Tracker {
/// The tracker configuration.
config: Core,
_core_config: Core,

/// The in-memory torrents repository.
_in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
Expand All @@ -485,38 +484,16 @@ impl Tracker {
///
/// Will return a `databases::error::Error` if unable to connect to database. The `Tracker` is responsible for the persistence.
pub fn new(
config: &Core,
core_config: &Core,
in_memory_torrent_repository: &Arc<InMemoryTorrentRepository>,
db_torrent_repository: &Arc<DatabasePersistentTorrentRepository>,
) -> Result<Tracker, databases::error::Error> {
Ok(Tracker {
config: config.clone(),
_core_config: core_config.clone(),
_in_memory_torrent_repository: in_memory_torrent_repository.clone(),
_db_torrent_repository: db_torrent_repository.clone(),
})
}

/// Returns `true` if the tracker requires authentication.
#[must_use]
pub fn requires_authentication(&self) -> bool {
self.config.private
}

/// Returns `true` is the tracker is in whitelisted mode.
#[must_use]
pub fn is_behind_reverse_proxy(&self) -> bool {
self.config.net.on_reverse_proxy
}

#[must_use]
pub fn get_announce_policy(&self) -> AnnouncePolicy {
self.config.announce_policy
}

#[must_use]
pub fn get_maybe_external_ip(&self) -> Option<IpAddr> {
self.config.net.external_ip
}
}

#[cfg(test)]
Expand Down
6 changes: 6 additions & 0 deletions src/servers/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use axum_server::Handle;
use derive_more::Constructor;
use futures::future::BoxFuture;
use tokio::sync::oneshot::{Receiver, Sender};
use torrust_tracker_configuration::Core;
use tracing::instrument;

use super::v1::routes::router;
Expand Down Expand Up @@ -59,6 +60,7 @@ impl Launcher {
))]
fn start(
&self,
config: Arc<Core>,
tracker: Arc<Tracker>,
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
Expand All @@ -85,6 +87,7 @@ impl Launcher {
tracing::info!(target: HTTP_TRACKER_LOG_TARGET, "Starting on: {protocol}://{}", address);

let app = router(
config,
tracker,
announce_handler,
scrape_handler,
Expand Down Expand Up @@ -188,6 +191,7 @@ impl HttpServer<Stopped> {
#[allow(clippy::too_many_arguments)]
pub async fn start(
self,
core_config: Arc<Core>,
tracker: Arc<Tracker>,
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
Expand All @@ -203,6 +207,7 @@ impl HttpServer<Stopped> {

let task = tokio::spawn(async move {
let server = launcher.start(
core_config,
tracker,
announce_handler,
scrape_handler,
Expand Down Expand Up @@ -309,6 +314,7 @@ mod tests {
let stopped = HttpServer::new(Launcher::new(bind_to, tls));
let started = stopped
.start(
Arc::new(cfg.core.clone()),
app_container.tracker,
app_container.announce_handler,
app_container.scrape_handler,
Expand Down
Loading
Loading