Skip to content
6 changes: 3 additions & 3 deletions packages/axum-http-tracker-server/src/v1/handlers/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ mod tests {
use bittorrent_tracker_core::authentication::key::repository::in_memory::InMemoryKeyRepository;
use bittorrent_tracker_core::authentication::service::AuthenticationService;
use bittorrent_tracker_core::databases::setup::initialize_database;
use bittorrent_tracker_core::statistics::persisted::downloads::DatabaseDownloadsMetricRepository;
use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
use bittorrent_tracker_core::torrent::repository::persisted::DatabasePersistentTorrentRepository;
use bittorrent_tracker_core::whitelist::authorization::WhitelistAuthorization;
use bittorrent_tracker_core::whitelist::repository::in_memory::InMemoryWhitelist;
use torrust_tracker_configuration::Configuration;
Expand Down Expand Up @@ -156,12 +156,12 @@ mod tests {
let in_memory_key_repository = Arc::new(InMemoryKeyRepository::default());
let authentication_service = Arc::new(AuthenticationService::new(&config.core, &in_memory_key_repository));
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
let db_torrent_repository = Arc::new(DatabasePersistentTorrentRepository::new(&database));
let db_downloads_metric_repository = Arc::new(DatabaseDownloadsMetricRepository::new(&database));
let announce_handler = Arc::new(AnnounceHandler::new(
&config.core,
&whitelist_authorization,
&in_memory_torrent_repository,
&db_torrent_repository,
&db_downloads_metric_repository,
));

// HTTP core stats
Expand Down
6 changes: 3 additions & 3 deletions packages/http-tracker-core/benches/helpers/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use bittorrent_tracker_core::announce_handler::AnnounceHandler;
use bittorrent_tracker_core::authentication::key::repository::in_memory::InMemoryKeyRepository;
use bittorrent_tracker_core::authentication::service::AuthenticationService;
use bittorrent_tracker_core::databases::setup::initialize_database;
use bittorrent_tracker_core::statistics::persisted::downloads::DatabaseDownloadsMetricRepository;
use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
use bittorrent_tracker_core::torrent::repository::persisted::DatabasePersistentTorrentRepository;
use bittorrent_tracker_core::whitelist::authorization::WhitelistAuthorization;
use bittorrent_tracker_core::whitelist::repository::in_memory::InMemoryWhitelist;
use futures::future::BoxFuture;
Expand Down Expand Up @@ -45,7 +45,7 @@ pub fn initialize_core_tracker_services_with_config(config: &Configuration) -> (
let core_config = Arc::new(config.core.clone());
let database = initialize_database(&config.core);
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
let db_torrent_repository = Arc::new(DatabasePersistentTorrentRepository::new(&database));
let db_downloads_metric_repository = Arc::new(DatabaseDownloadsMetricRepository::new(&database));
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(WhitelistAuthorization::new(&config.core, &in_memory_whitelist.clone()));
let in_memory_key_repository = Arc::new(InMemoryKeyRepository::default());
Expand All @@ -55,7 +55,7 @@ pub fn initialize_core_tracker_services_with_config(config: &Configuration) -> (
&config.core,
&whitelist_authorization,
&in_memory_torrent_repository,
&db_torrent_repository,
&db_downloads_metric_repository,
));

// HTTP core stats
Expand Down
6 changes: 3 additions & 3 deletions packages/http-tracker-core/src/services/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ mod tests {
use bittorrent_tracker_core::authentication::key::repository::in_memory::InMemoryKeyRepository;
use bittorrent_tracker_core::authentication::service::AuthenticationService;
use bittorrent_tracker_core::databases::setup::initialize_database;
use bittorrent_tracker_core::statistics::persisted::downloads::DatabaseDownloadsMetricRepository;
use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
use bittorrent_tracker_core::torrent::repository::persisted::DatabasePersistentTorrentRepository;
use bittorrent_tracker_core::whitelist::authorization::WhitelistAuthorization;
use bittorrent_tracker_core::whitelist::repository::in_memory::InMemoryWhitelist;
use torrust_tracker_configuration::{Configuration, Core};
Expand All @@ -239,7 +239,7 @@ mod tests {
let core_config = Arc::new(config.core.clone());
let database = initialize_database(&config.core);
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
let db_torrent_repository = Arc::new(DatabasePersistentTorrentRepository::new(&database));
let db_downloads_metric_repository = Arc::new(DatabaseDownloadsMetricRepository::new(&database));
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(WhitelistAuthorization::new(&config.core, &in_memory_whitelist.clone()));
let in_memory_key_repository = Arc::new(InMemoryKeyRepository::default());
Expand All @@ -249,7 +249,7 @@ mod tests {
&config.core,
&whitelist_authorization,
&in_memory_torrent_repository,
&db_torrent_repository,
&db_downloads_metric_repository,
));

// HTTP core stats
Expand Down
6 changes: 3 additions & 3 deletions packages/http-tracker-core/src/services/scrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ mod tests {
use bittorrent_tracker_core::authentication::service::AuthenticationService;
use bittorrent_tracker_core::databases::setup::initialize_database;
use bittorrent_tracker_core::scrape_handler::ScrapeHandler;
use bittorrent_tracker_core::statistics::persisted::downloads::DatabaseDownloadsMetricRepository;
use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
use bittorrent_tracker_core::torrent::repository::persisted::DatabasePersistentTorrentRepository;
use bittorrent_tracker_core::whitelist::authorization::WhitelistAuthorization;
use bittorrent_tracker_core::whitelist::repository::in_memory::InMemoryWhitelist;
use futures::future::BoxFuture;
Expand All @@ -200,15 +200,15 @@ mod tests {
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(WhitelistAuthorization::new(&config.core, &in_memory_whitelist.clone()));
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
let db_torrent_repository = Arc::new(DatabasePersistentTorrentRepository::new(&database));
let db_downloads_metric_repository = Arc::new(DatabaseDownloadsMetricRepository::new(&database));
let in_memory_key_repository = Arc::new(InMemoryKeyRepository::default());
let authentication_service = Arc::new(AuthenticationService::new(&config.core, &in_memory_key_repository));

let announce_handler = Arc::new(AnnounceHandler::new(
&config.core,
&whitelist_authorization,
&in_memory_torrent_repository,
&db_torrent_repository,
&db_downloads_metric_repository,
));

let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository));
Expand Down
4 changes: 2 additions & 2 deletions packages/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ use bittorrent_primitives::info_hash::InfoHash;
/// Duration since the Unix Epoch.
pub type DurationSinceUnixEpoch = Duration;

pub type PersistentTorrent = u32;
pub type PersistentTorrents = BTreeMap<InfoHash, PersistentTorrent>;
pub type NumberOfDownloads = u32;
pub type NumberOfDownloadsBTreeMap = BTreeMap<InfoHash, NumberOfDownloads>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use dashmap::DashMap;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};

use super::Repository;
use crate::entry::peer_list::PeerList;
Expand All @@ -22,7 +22,7 @@ where
EntryMutexStd: EntrySync,
EntrySingle: Entry,
{
fn upsert_peer(&self, info_hash: &InfoHash, peer: &peer::Peer, _opt_persistent_torrent: Option<PersistentTorrent>) -> bool {
fn upsert_peer(&self, info_hash: &InfoHash, peer: &peer::Peer, _opt_persistent_torrent: Option<NumberOfDownloads>) -> bool {
// todo: load persistent torrent data if provided

if let Some(entry) = self.torrents.get(info_hash) {
Expand Down Expand Up @@ -77,7 +77,7 @@ where
}
}

fn import_persistent(&self, persistent_torrents: &PersistentTorrents) {
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) {
for (info_hash, completed) in persistent_torrents {
if self.torrents.contains_key(info_hash) {
continue;
Expand Down
10 changes: 5 additions & 5 deletions packages/torrent-repository-benchmarking/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};

pub mod dash_map_mutex_std;
pub mod rw_lock_std;
Expand All @@ -19,11 +19,11 @@ pub trait Repository<T>: Debug + Default + Sized + 'static {
fn get(&self, key: &InfoHash) -> Option<T>;
fn get_metrics(&self) -> AggregateSwarmMetadata;
fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, T)>;
fn import_persistent(&self, persistent_torrents: &PersistentTorrents);
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap);
fn remove(&self, key: &InfoHash) -> Option<T>;
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch);
fn remove_peerless_torrents(&self, policy: &TrackerPolicy);
fn upsert_peer(&self, info_hash: &InfoHash, peer: &peer::Peer, opt_persistent_torrent: Option<PersistentTorrent>) -> bool;
fn upsert_peer(&self, info_hash: &InfoHash, peer: &peer::Peer, opt_persistent_torrent: Option<NumberOfDownloads>) -> bool;
fn get_swarm_metadata(&self, info_hash: &InfoHash) -> Option<SwarmMetadata>;
}

Expand All @@ -32,15 +32,15 @@ pub trait RepositoryAsync<T>: Debug + Default + Sized + 'static {
fn get(&self, key: &InfoHash) -> impl std::future::Future<Output = Option<T>> + Send;
fn get_metrics(&self) -> impl std::future::Future<Output = AggregateSwarmMetadata> + Send;
fn get_paginated(&self, pagination: Option<&Pagination>) -> impl std::future::Future<Output = Vec<(InfoHash, T)>> + Send;
fn import_persistent(&self, persistent_torrents: &PersistentTorrents) -> impl std::future::Future<Output = ()> + Send;
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) -> impl std::future::Future<Output = ()> + Send;
fn remove(&self, key: &InfoHash) -> impl std::future::Future<Output = Option<T>> + Send;
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch) -> impl std::future::Future<Output = ()> + Send;
fn remove_peerless_torrents(&self, policy: &TrackerPolicy) -> impl std::future::Future<Output = ()> + Send;
fn upsert_peer(
&self,
info_hash: &InfoHash,
peer: &peer::Peer,
opt_persistent_torrent: Option<PersistentTorrent>,
opt_persistent_torrent: Option<NumberOfDownloads>,
) -> impl std::future::Future<Output = bool> + Send;
fn get_swarm_metadata(&self, info_hash: &InfoHash) -> impl std::future::Future<Output = Option<SwarmMetadata>> + Send;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};

use super::Repository;
use crate::entry::peer_list::PeerList;
Expand Down Expand Up @@ -45,7 +45,7 @@ impl Repository<EntrySingle> for TorrentsRwLockStd
where
EntrySingle: Entry,
{
fn upsert_peer(&self, info_hash: &InfoHash, peer: &peer::Peer, _opt_persistent_torrent: Option<PersistentTorrent>) -> bool {
fn upsert_peer(&self, info_hash: &InfoHash, peer: &peer::Peer, _opt_persistent_torrent: Option<NumberOfDownloads>) -> bool {
// todo: load persistent torrent data if provided

let mut db = self.get_torrents_mut();
Expand Down Expand Up @@ -92,7 +92,7 @@ where
}
}

fn import_persistent(&self, persistent_torrents: &PersistentTorrents) {
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) {
let mut torrents = self.get_torrents_mut();

for (info_hash, downloaded) in persistent_torrents {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};

use super::Repository;
use crate::entry::peer_list::PeerList;
Expand Down Expand Up @@ -32,7 +32,7 @@ where
EntryMutexStd: EntrySync,
EntrySingle: Entry,
{
fn upsert_peer(&self, info_hash: &InfoHash, peer: &peer::Peer, _opt_persistent_torrent: Option<PersistentTorrent>) -> bool {
fn upsert_peer(&self, info_hash: &InfoHash, peer: &peer::Peer, _opt_persistent_torrent: Option<NumberOfDownloads>) -> bool {
// todo: load persistent torrent data if provided

let maybe_entry = self.get_torrents().get(info_hash).cloned();
Expand Down Expand Up @@ -87,7 +87,7 @@ where
}
}

fn import_persistent(&self, persistent_torrents: &PersistentTorrents) {
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) {
let mut torrents = self.get_torrents_mut();

for (info_hash, completed) in persistent_torrents {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use futures::{Future, FutureExt};
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};

use super::RepositoryAsync;
use crate::entry::peer_list::PeerList;
Expand Down Expand Up @@ -40,7 +40,7 @@ where
&self,
info_hash: &InfoHash,
peer: &peer::Peer,
_opt_persistent_torrent: Option<PersistentTorrent>,
_opt_persistent_torrent: Option<NumberOfDownloads>,
) -> bool {
// todo: load persistent torrent data if provided

Expand Down Expand Up @@ -101,7 +101,7 @@ where
metrics
}

async fn import_persistent(&self, persistent_torrents: &PersistentTorrents) {
async fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) {
let mut db = self.get_torrents_mut();

for (info_hash, completed) in persistent_torrents {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};

use super::RepositoryAsync;
use crate::entry::peer_list::PeerList;
Expand Down Expand Up @@ -50,7 +50,7 @@ where
&self,
info_hash: &InfoHash,
peer: &peer::Peer,
_opt_persistent_torrent: Option<PersistentTorrent>,
_opt_persistent_torrent: Option<NumberOfDownloads>,
) -> bool {
// todo: load persistent torrent data if provided

Expand Down Expand Up @@ -98,7 +98,7 @@ where
metrics
}

async fn import_persistent(&self, persistent_torrents: &PersistentTorrents) {
async fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) {
let mut torrents = self.get_torrents_mut().await;

for (info_hash, completed) in persistent_torrents {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};

use super::RepositoryAsync;
use crate::entry::peer_list::PeerList;
Expand Down Expand Up @@ -38,7 +38,7 @@ where
&self,
info_hash: &InfoHash,
peer: &peer::Peer,
_opt_persistent_torrent: Option<PersistentTorrent>,
_opt_persistent_torrent: Option<NumberOfDownloads>,
) -> bool {
// todo: load persistent torrent data if provided

Expand Down Expand Up @@ -92,7 +92,7 @@ where
metrics
}

async fn import_persistent(&self, persistent_torrents: &PersistentTorrents) {
async fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) {
let mut torrents = self.get_torrents_mut().await;

for (info_hash, completed) in persistent_torrents {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};

use super::RepositoryAsync;
use crate::entry::peer_list::PeerList;
Expand Down Expand Up @@ -38,7 +38,7 @@ where
&self,
info_hash: &InfoHash,
peer: &peer::Peer,
_opt_persistent_torrent: Option<PersistentTorrent>,
_opt_persistent_torrent: Option<NumberOfDownloads>,
) -> bool {
// todo: load persistent torrent data if provided

Expand Down Expand Up @@ -95,7 +95,7 @@ where
metrics
}

async fn import_persistent(&self, persistent_torrents: &PersistentTorrents) {
async fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) {
let mut db = self.get_torrents_mut().await;

for (info_hash, completed) in persistent_torrents {
Expand Down
Loading