diff --git a/packages/torrent-repository/src/entry.rs b/packages/torrent-repository/src/entry.rs index ca4ca5a5..4dc2fbb5 100644 --- a/packages/torrent-repository/src/entry.rs +++ b/packages/torrent-repository/src/entry.rs @@ -8,6 +8,8 @@ use torrust_tracker_primitives::peer::ReadInfo as _; use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch}; +use crate::{EntryMutexStd, EntryMutexTokio, EntrySingle}; + /// A data structure containing all the information about a torrent in the tracker. /// /// This is the tracker entry for a given torrent and contains the swarm data, @@ -21,9 +23,6 @@ pub struct Entry { /// The number of peers that have ever completed downloading the torrent associated to this entry pub(crate) completed: u32, } -pub type Single = Entry; -pub type MutexStd = Arc>; -pub type MutexTokio = Arc>; pub trait ReadInfo { /// It returns the swarm metadata (statistics) as a struct: @@ -115,7 +114,7 @@ pub trait UpdateAsync { fn remove_inactive_peers(self, current_cutoff: DurationSinceUnixEpoch) -> impl std::future::Future + Send; } -impl ReadInfo for Single { +impl ReadInfo for EntrySingle { #[allow(clippy::cast_possible_truncation)] fn get_stats(&self) -> SwarmMetadata { let complete: u32 = self.peers.values().filter(|peer| peer.is_seeder()).count() as u32; @@ -149,7 +148,7 @@ impl ReadInfo for Single { } } -impl ReadInfo for MutexStd { +impl ReadInfo for EntryMutexStd { fn get_stats(&self) -> SwarmMetadata { self.lock().expect("it should get a lock").get_stats() } @@ -167,7 +166,7 @@ impl ReadInfo for MutexStd { } } -impl ReadInfoAsync for MutexTokio { +impl ReadInfoAsync for EntryMutexTokio { async fn get_stats(self) -> SwarmMetadata { self.lock().await.get_stats() } @@ -185,7 +184,7 @@ impl ReadInfoAsync for MutexTokio { } } -impl ReadPeers for Single { +impl ReadPeers for EntrySingle { fn get_peers(&self, limit: Option) -> Vec> { match limit { Some(limit) => self.peers.values().take(limit).cloned().collect(), @@ -215,7 +214,7 @@ impl ReadPeers for Single { } } -impl ReadPeers for MutexStd { +impl ReadPeers for EntryMutexStd { fn get_peers(&self, limit: Option) -> Vec> { self.lock().expect("it should get lock").get_peers(limit) } @@ -225,7 +224,7 @@ impl ReadPeers for MutexStd { } } -impl ReadPeersAsync for MutexTokio { +impl ReadPeersAsync for EntryMutexTokio { async fn get_peers(self, limit: Option) -> Vec> { self.lock().await.get_peers(limit) } @@ -235,7 +234,7 @@ impl ReadPeersAsync for MutexTokio { } } -impl Update for Single { +impl Update for EntrySingle { fn insert_or_update_peer(&mut self, peer: &peer::Peer) -> bool { let mut did_torrent_stats_change: bool = false; @@ -270,7 +269,7 @@ impl Update for Single { } } -impl UpdateSync for MutexStd { +impl UpdateSync for EntryMutexStd { fn insert_or_update_peer(&self, peer: &peer::Peer) -> bool { self.lock().expect("it should lock the entry").insert_or_update_peer(peer) } @@ -288,7 +287,7 @@ impl UpdateSync for MutexStd { } } -impl UpdateAsync for MutexTokio { +impl UpdateAsync for EntryMutexTokio { async fn insert_or_update_peer(self, peer: &peer::Peer) -> bool { self.lock().await.insert_or_update_peer(peer) } diff --git a/packages/torrent-repository/src/lib.rs b/packages/torrent-repository/src/lib.rs index 1f5fba5f..9a626dc6 100644 --- a/packages/torrent-repository/src/lib.rs +++ b/packages/torrent-repository/src/lib.rs @@ -1,9 +1,15 @@ +use std::sync::Arc; + pub mod entry; pub mod repository; -pub type TorrentsRwLockStd = repository::RwLockStd; -pub type TorrentsRwLockStdMutexStd = repository::RwLockStd; -pub type TorrentsRwLockStdMutexTokio = repository::RwLockStd; -pub type TorrentsRwLockTokio = repository::RwLockTokio; -pub type TorrentsRwLockTokioMutexStd = repository::RwLockTokio; -pub type TorrentsRwLockTokioMutexTokio = repository::RwLockTokio; +pub type EntrySingle = entry::Entry; +pub type EntryMutexStd = Arc>; +pub type EntryMutexTokio = Arc>; + +pub type TorrentsRwLockStd = repository::RwLockStd; +pub type TorrentsRwLockStdMutexStd = repository::RwLockStd; +pub type TorrentsRwLockStdMutexTokio = repository::RwLockStd; +pub type TorrentsRwLockTokio = repository::RwLockTokio; +pub type TorrentsRwLockTokioMutexStd = repository::RwLockTokio; +pub type TorrentsRwLockTokioMutexTokio = repository::RwLockTokio; diff --git a/packages/torrent-repository/src/repository/rw_lock_std.rs b/packages/torrent-repository/src/repository/rw_lock_std.rs index 8bf7612f..fe14d668 100644 --- a/packages/torrent-repository/src/repository/rw_lock_std.rs +++ b/packages/torrent-repository/src/repository/rw_lock_std.rs @@ -9,20 +9,20 @@ use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics; use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrents}; use super::{Repository, UpdateTorrentSync}; -use crate::entry::{self, ReadInfo, Update}; -use crate::TorrentsRwLockStd; +use crate::entry::{ReadInfo, Update}; +use crate::{EntrySingle, TorrentsRwLockStd}; impl TorrentsRwLockStd { - fn get_torrents<'a>(&'a self) -> std::sync::RwLockReadGuard<'a, std::collections::BTreeMap> + fn get_torrents<'a>(&'a self) -> std::sync::RwLockReadGuard<'a, std::collections::BTreeMap> where - std::collections::BTreeMap: 'a, + std::collections::BTreeMap: 'a, { self.torrents.read().expect("it should get the read lock") } - fn get_torrents_mut<'a>(&'a self) -> std::sync::RwLockWriteGuard<'a, std::collections::BTreeMap> + fn get_torrents_mut<'a>(&'a self) -> std::sync::RwLockWriteGuard<'a, std::collections::BTreeMap> where - std::collections::BTreeMap: 'a, + std::collections::BTreeMap: 'a, { self.torrents.write().expect("it should get the write lock") } @@ -32,7 +32,7 @@ impl UpdateTorrentSync for TorrentsRwLockStd { fn update_torrent_with_peer_and_get_stats(&self, info_hash: &InfoHash, peer: &peer::Peer) -> (bool, SwarmMetadata) { let mut db = self.get_torrents_mut(); - let entry = db.entry(*info_hash).or_insert(entry::Single::default()); + let entry = db.entry(*info_hash).or_insert(EntrySingle::default()); entry.insert_or_update_peer_and_get_stats(peer) } @@ -44,8 +44,8 @@ impl UpdateTorrentSync for Arc { } } -impl Repository for TorrentsRwLockStd { - async fn get(&self, key: &InfoHash) -> Option { +impl Repository for TorrentsRwLockStd { + async fn get(&self, key: &InfoHash) -> Option { let db = self.get_torrents(); db.get(key).cloned() } @@ -64,7 +64,7 @@ impl Repository for TorrentsRwLockStd { metrics } - async fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, entry::Single)> { + async fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, EntrySingle)> { let db = self.get_torrents(); match pagination { @@ -87,7 +87,7 @@ impl Repository for TorrentsRwLockStd { continue; } - let entry = entry::Single { + let entry = EntrySingle { peers: BTreeMap::default(), completed: *completed, }; @@ -96,7 +96,7 @@ impl Repository for TorrentsRwLockStd { } } - async fn remove(&self, key: &InfoHash) -> Option { + async fn remove(&self, key: &InfoHash) -> Option { let mut db = self.get_torrents_mut(); db.remove(key) } diff --git a/packages/torrent-repository/src/repository/rw_lock_std_mutex_std.rs b/packages/torrent-repository/src/repository/rw_lock_std_mutex_std.rs index e2e54833..ba2fb6a8 100644 --- a/packages/torrent-repository/src/repository/rw_lock_std_mutex_std.rs +++ b/packages/torrent-repository/src/repository/rw_lock_std_mutex_std.rs @@ -9,20 +9,20 @@ use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics; use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrents}; use super::{Repository, UpdateTorrentSync}; -use crate::entry::{self, ReadInfo, UpdateSync}; -use crate::TorrentsRwLockStdMutexStd; +use crate::entry::{ReadInfo, UpdateSync}; +use crate::{EntryMutexStd, EntrySingle, TorrentsRwLockStdMutexStd}; impl TorrentsRwLockStdMutexStd { - fn get_torrents<'a>(&'a self) -> std::sync::RwLockReadGuard<'a, std::collections::BTreeMap> + fn get_torrents<'a>(&'a self) -> std::sync::RwLockReadGuard<'a, std::collections::BTreeMap> where - std::collections::BTreeMap: 'a, + std::collections::BTreeMap: 'a, { self.torrents.read().expect("unable to get torrent list") } - fn get_torrents_mut<'a>(&'a self) -> std::sync::RwLockWriteGuard<'a, std::collections::BTreeMap> + fn get_torrents_mut<'a>(&'a self) -> std::sync::RwLockWriteGuard<'a, std::collections::BTreeMap> where - std::collections::BTreeMap: 'a, + std::collections::BTreeMap: 'a, { self.torrents.write().expect("unable to get writable torrent list") } @@ -50,8 +50,8 @@ impl UpdateTorrentSync for Arc { } } -impl Repository for TorrentsRwLockStdMutexStd { - async fn get(&self, key: &InfoHash) -> Option { +impl Repository for TorrentsRwLockStdMutexStd { + async fn get(&self, key: &InfoHash) -> Option { let db = self.get_torrents(); db.get(key).cloned() } @@ -70,7 +70,7 @@ impl Repository for TorrentsRwLockStdMutexStd { metrics } - async fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, entry::MutexStd)> { + async fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, EntryMutexStd)> { let db = self.get_torrents(); match pagination { @@ -93,8 +93,8 @@ impl Repository for TorrentsRwLockStdMutexStd { continue; } - let entry = entry::MutexStd::new( - entry::Single { + let entry = EntryMutexStd::new( + EntrySingle { peers: BTreeMap::default(), completed: *completed, } @@ -105,7 +105,7 @@ impl Repository for TorrentsRwLockStdMutexStd { } } - async fn remove(&self, key: &InfoHash) -> Option { + async fn remove(&self, key: &InfoHash) -> Option { let mut db = self.get_torrents_mut(); db.remove(key) } diff --git a/packages/torrent-repository/src/repository/rw_lock_std_mutex_tokio.rs b/packages/torrent-repository/src/repository/rw_lock_std_mutex_tokio.rs index 7785d2ac..1deca0e3 100644 --- a/packages/torrent-repository/src/repository/rw_lock_std_mutex_tokio.rs +++ b/packages/torrent-repository/src/repository/rw_lock_std_mutex_tokio.rs @@ -13,19 +13,19 @@ use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent use super::{Repository, UpdateTorrentAsync}; use crate::entry::{self, ReadInfo, UpdateAsync}; -use crate::TorrentsRwLockStdMutexTokio; +use crate::{EntryMutexTokio, EntrySingle, TorrentsRwLockStdMutexTokio}; impl TorrentsRwLockStdMutexTokio { - fn get_torrents<'a>(&'a self) -> std::sync::RwLockReadGuard<'a, std::collections::BTreeMap> + fn get_torrents<'a>(&'a self) -> std::sync::RwLockReadGuard<'a, std::collections::BTreeMap> where - std::collections::BTreeMap: 'a, + std::collections::BTreeMap: 'a, { self.torrents.read().expect("unable to get torrent list") } - fn get_torrents_mut<'a>(&'a self) -> std::sync::RwLockWriteGuard<'a, std::collections::BTreeMap> + fn get_torrents_mut<'a>(&'a self) -> std::sync::RwLockWriteGuard<'a, std::collections::BTreeMap> where - std::collections::BTreeMap: 'a, + std::collections::BTreeMap: 'a, { self.torrents.write().expect("unable to get writable torrent list") } @@ -53,13 +53,13 @@ impl UpdateTorrentAsync for Arc { } } -impl Repository for TorrentsRwLockStdMutexTokio { - async fn get(&self, key: &InfoHash) -> Option { +impl Repository for TorrentsRwLockStdMutexTokio { + async fn get(&self, key: &InfoHash) -> Option { let db = self.get_torrents(); db.get(key).cloned() } - async fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, entry::MutexTokio)> { + async fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, EntryMutexTokio)> { let db = self.get_torrents(); match pagination { @@ -98,8 +98,8 @@ impl Repository for TorrentsRwLockStdMutexTokio { continue; } - let entry = entry::MutexTokio::new( - entry::Single { + let entry = EntryMutexTokio::new( + EntrySingle { peers: BTreeMap::default(), completed: *completed, } @@ -110,7 +110,7 @@ impl Repository for TorrentsRwLockStdMutexTokio { } } - async fn remove(&self, key: &InfoHash) -> Option { + async fn remove(&self, key: &InfoHash) -> Option { let mut db = self.get_torrents_mut(); db.remove(key) } diff --git a/packages/torrent-repository/src/repository/rw_lock_tokio.rs b/packages/torrent-repository/src/repository/rw_lock_tokio.rs index 44659439..fdde3d35 100644 --- a/packages/torrent-repository/src/repository/rw_lock_tokio.rs +++ b/packages/torrent-repository/src/repository/rw_lock_tokio.rs @@ -9,22 +9,22 @@ use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics; use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrents}; use super::{Repository, UpdateTorrentAsync}; -use crate::entry::{self, ReadInfo, Update}; -use crate::TorrentsRwLockTokio; +use crate::entry::{ReadInfo, Update}; +use crate::{EntrySingle, TorrentsRwLockTokio}; impl TorrentsRwLockTokio { - async fn get_torrents<'a>(&'a self) -> tokio::sync::RwLockReadGuard<'a, std::collections::BTreeMap> + async fn get_torrents<'a>(&'a self) -> tokio::sync::RwLockReadGuard<'a, std::collections::BTreeMap> where - std::collections::BTreeMap: 'a, + std::collections::BTreeMap: 'a, { self.torrents.read().await } async fn get_torrents_mut<'a>( &'a self, - ) -> tokio::sync::RwLockWriteGuard<'a, std::collections::BTreeMap> + ) -> tokio::sync::RwLockWriteGuard<'a, std::collections::BTreeMap> where - std::collections::BTreeMap: 'a, + std::collections::BTreeMap: 'a, { self.torrents.write().await } @@ -34,7 +34,7 @@ impl UpdateTorrentAsync for TorrentsRwLockTokio { async fn update_torrent_with_peer_and_get_stats(&self, info_hash: &InfoHash, peer: &peer::Peer) -> (bool, SwarmMetadata) { let mut db = self.get_torrents_mut().await; - let entry = db.entry(*info_hash).or_insert(entry::Single::default()); + let entry = db.entry(*info_hash).or_insert(EntrySingle::default()); entry.insert_or_update_peer_and_get_stats(peer) } @@ -46,13 +46,13 @@ impl UpdateTorrentAsync for Arc { } } -impl Repository for TorrentsRwLockTokio { - async fn get(&self, key: &InfoHash) -> Option { +impl Repository for TorrentsRwLockTokio { + async fn get(&self, key: &InfoHash) -> Option { let db = self.get_torrents().await; db.get(key).cloned() } - async fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, entry::Single)> { + async fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, EntrySingle)> { let db = self.get_torrents().await; match pagination { @@ -89,7 +89,7 @@ impl Repository for TorrentsRwLockTokio { continue; } - let entry = entry::Single { + let entry = EntrySingle { peers: BTreeMap::default(), completed: *completed, }; @@ -98,7 +98,7 @@ impl Repository for TorrentsRwLockTokio { } } - async fn remove(&self, key: &InfoHash) -> Option { + async fn remove(&self, key: &InfoHash) -> Option { let mut db = self.get_torrents_mut().await; db.remove(key) } diff --git a/packages/torrent-repository/src/repository/rw_lock_tokio_mutex_std.rs b/packages/torrent-repository/src/repository/rw_lock_tokio_mutex_std.rs index 943f83a5..461d5c40 100644 --- a/packages/torrent-repository/src/repository/rw_lock_tokio_mutex_std.rs +++ b/packages/torrent-repository/src/repository/rw_lock_tokio_mutex_std.rs @@ -9,22 +9,22 @@ use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics; use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrents}; use super::{Repository, UpdateTorrentAsync}; -use crate::entry::{self, ReadInfo, UpdateSync}; -use crate::TorrentsRwLockTokioMutexStd; +use crate::entry::{ReadInfo, UpdateSync}; +use crate::{EntryMutexStd, EntrySingle, TorrentsRwLockTokioMutexStd}; impl TorrentsRwLockTokioMutexStd { - async fn get_torrents<'a>(&'a self) -> tokio::sync::RwLockReadGuard<'a, std::collections::BTreeMap> + async fn get_torrents<'a>(&'a self) -> tokio::sync::RwLockReadGuard<'a, std::collections::BTreeMap> where - std::collections::BTreeMap: 'a, + std::collections::BTreeMap: 'a, { self.torrents.read().await } async fn get_torrents_mut<'a>( &'a self, - ) -> tokio::sync::RwLockWriteGuard<'a, std::collections::BTreeMap> + ) -> tokio::sync::RwLockWriteGuard<'a, std::collections::BTreeMap> where - std::collections::BTreeMap: 'a, + std::collections::BTreeMap: 'a, { self.torrents.write().await } @@ -52,13 +52,13 @@ impl UpdateTorrentAsync for Arc { } } -impl Repository for TorrentsRwLockTokioMutexStd { - async fn get(&self, key: &InfoHash) -> Option { +impl Repository for TorrentsRwLockTokioMutexStd { + async fn get(&self, key: &InfoHash) -> Option { let db = self.get_torrents().await; db.get(key).cloned() } - async fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, entry::MutexStd)> { + async fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, EntryMutexStd)> { let db = self.get_torrents().await; match pagination { @@ -95,8 +95,8 @@ impl Repository for TorrentsRwLockTokioMutexStd { continue; } - let entry = entry::MutexStd::new( - entry::Single { + let entry = EntryMutexStd::new( + EntrySingle { peers: BTreeMap::default(), completed: *completed, } @@ -107,7 +107,7 @@ impl Repository for TorrentsRwLockTokioMutexStd { } } - async fn remove(&self, key: &InfoHash) -> Option { + async fn remove(&self, key: &InfoHash) -> Option { let mut db = self.get_torrents_mut().await; db.remove(key) } diff --git a/packages/torrent-repository/src/repository/rw_lock_tokio_mutex_tokio.rs b/packages/torrent-repository/src/repository/rw_lock_tokio_mutex_tokio.rs index f09da626..663ebe81 100644 --- a/packages/torrent-repository/src/repository/rw_lock_tokio_mutex_tokio.rs +++ b/packages/torrent-repository/src/repository/rw_lock_tokio_mutex_tokio.rs @@ -9,24 +9,22 @@ use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics; use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrents}; use super::{Repository, UpdateTorrentAsync}; -use crate::entry::{self, ReadInfo, ReadInfoAsync, UpdateAsync}; -use crate::TorrentsRwLockTokioMutexTokio; +use crate::entry::{ReadInfo, ReadInfoAsync, UpdateAsync}; +use crate::{EntryMutexTokio, EntrySingle, TorrentsRwLockTokioMutexTokio}; impl TorrentsRwLockTokioMutexTokio { - async fn get_torrents<'a>( - &'a self, - ) -> tokio::sync::RwLockReadGuard<'a, std::collections::BTreeMap> + async fn get_torrents<'a>(&'a self) -> tokio::sync::RwLockReadGuard<'a, std::collections::BTreeMap> where - std::collections::BTreeMap: 'a, + std::collections::BTreeMap: 'a, { self.torrents.read().await } async fn get_torrents_mut<'a>( &'a self, - ) -> tokio::sync::RwLockWriteGuard<'a, std::collections::BTreeMap> + ) -> tokio::sync::RwLockWriteGuard<'a, std::collections::BTreeMap> where - std::collections::BTreeMap: 'a, + std::collections::BTreeMap: 'a, { self.torrents.write().await } @@ -54,13 +52,13 @@ impl UpdateTorrentAsync for Arc { } } -impl Repository for TorrentsRwLockTokioMutexTokio { - async fn get(&self, key: &InfoHash) -> Option { +impl Repository for TorrentsRwLockTokioMutexTokio { + async fn get(&self, key: &InfoHash) -> Option { let db = self.get_torrents().await; db.get(key).cloned() } - async fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, entry::MutexTokio)> { + async fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, EntryMutexTokio)> { let db = self.get_torrents().await; match pagination { @@ -97,8 +95,8 @@ impl Repository for TorrentsRwLockTokioMutexTokio { continue; } - let entry = entry::MutexTokio::new( - entry::Single { + let entry = EntryMutexTokio::new( + EntrySingle { peers: BTreeMap::default(), completed: *completed, } @@ -109,7 +107,7 @@ impl Repository for TorrentsRwLockTokioMutexTokio { } } - async fn remove(&self, key: &InfoHash) -> Option { + async fn remove(&self, key: &InfoHash) -> Option { let mut db = self.get_torrents_mut().await; db.remove(key) } diff --git a/src/core/torrent/mod.rs b/src/core/torrent/mod.rs index 41eb00b3..b90a842a 100644 --- a/src/core/torrent/mod.rs +++ b/src/core/torrent/mod.rs @@ -42,7 +42,8 @@ mod tests { use torrust_tracker_primitives::announce_event::AnnounceEvent; use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfBytes}; - use torrust_tracker_torrent_repository::entry::{self, ReadInfo, ReadPeers, Update}; + use torrust_tracker_torrent_repository::entry::{ReadInfo, ReadPeers, Update}; + use torrust_tracker_torrent_repository::EntrySingle; use crate::core::TORRENT_PEERS_LIMIT; use crate::shared::clock::{self, StoppedTime, Time, TimeNow}; @@ -115,14 +116,14 @@ mod tests { #[test] fn the_default_torrent_entry_should_contain_an_empty_list_of_peers() { - let torrent_entry = entry::Single::default(); + let torrent_entry = EntrySingle::default(); assert_eq!(torrent_entry.get_peers(None).len(), 0); } #[test] fn a_new_peer_can_be_added_to_a_torrent_entry() { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let torrent_peer = TorrentPeerBuilder::default().into(); torrent_entry.insert_or_update_peer(&torrent_peer); // Add the peer @@ -133,7 +134,7 @@ mod tests { #[test] fn a_torrent_entry_should_contain_the_list_of_peers_that_were_added_to_the_torrent() { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let torrent_peer = TorrentPeerBuilder::default().into(); torrent_entry.insert_or_update_peer(&torrent_peer); // Add the peer @@ -143,7 +144,7 @@ mod tests { #[test] fn a_peer_can_be_updated_in_a_torrent_entry() { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let mut torrent_peer = TorrentPeerBuilder::default().into(); torrent_entry.insert_or_update_peer(&torrent_peer); // Add the peer @@ -155,7 +156,7 @@ mod tests { #[test] fn a_peer_should_be_removed_from_a_torrent_entry_when_the_peer_announces_it_has_stopped() { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let mut torrent_peer = TorrentPeerBuilder::default().into(); torrent_entry.insert_or_update_peer(&torrent_peer); // Add the peer @@ -167,7 +168,7 @@ mod tests { #[test] fn torrent_stats_change_when_a_previously_known_peer_announces_it_has_completed_the_torrent() { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let mut torrent_peer = TorrentPeerBuilder::default().into(); torrent_entry.insert_or_update_peer(&torrent_peer); // Add the peer @@ -181,7 +182,7 @@ mod tests { #[test] fn torrent_stats_should_not_change_when_a_peer_announces_it_has_completed_the_torrent_if_it_is_the_first_announce_from_the_peer( ) { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let torrent_peer_announcing_complete_event = TorrentPeerBuilder::default().with_event_completed().into(); // Add a peer that did not exist before in the entry @@ -193,7 +194,7 @@ mod tests { #[test] fn a_torrent_entry_should_return_the_list_of_peers_for_a_given_peer_filtering_out_the_client_that_is_making_the_request() { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let peer_socket_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); let torrent_peer = TorrentPeerBuilder::default().with_peer_address(peer_socket_address).into(); torrent_entry.insert_or_update_peer(&torrent_peer); // Add peer @@ -206,7 +207,7 @@ mod tests { #[test] fn two_peers_with_the_same_ip_but_different_port_should_be_considered_different_peers() { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let peer_ip = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); @@ -240,7 +241,7 @@ mod tests { #[test] fn the_tracker_should_limit_the_list_of_peers_to_74_when_clients_scrape_torrents() { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); // We add one more peer than the scrape limit for peer_number in 1..=74 + 1 { @@ -257,7 +258,7 @@ mod tests { #[test] fn torrent_stats_should_have_the_number_of_seeders_for_a_torrent() { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let torrent_seeder = a_torrent_seeder(); torrent_entry.insert_or_update_peer(&torrent_seeder); // Add seeder @@ -267,7 +268,7 @@ mod tests { #[test] fn torrent_stats_should_have_the_number_of_leechers_for_a_torrent() { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let torrent_leecher = a_torrent_leecher(); torrent_entry.insert_or_update_peer(&torrent_leecher); // Add leecher @@ -278,7 +279,7 @@ mod tests { #[test] fn torrent_stats_should_have_the_number_of_peers_that_having_announced_at_least_two_events_the_latest_one_is_the_completed_event( ) { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let mut torrent_peer = TorrentPeerBuilder::default().into(); torrent_entry.insert_or_update_peer(&torrent_peer); // Add the peer @@ -293,7 +294,7 @@ mod tests { #[test] fn torrent_stats_should_not_include_a_peer_in_the_completed_counter_if_the_peer_has_announced_only_one_event() { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let torrent_peer_announcing_complete_event = TorrentPeerBuilder::default().with_event_completed().into(); // Announce "Completed" torrent download event. @@ -307,7 +308,7 @@ mod tests { #[test] fn a_torrent_entry_should_remove_a_peer_not_updated_after_a_timeout_in_seconds() { - let mut torrent_entry = entry::Single::default(); + let mut torrent_entry = EntrySingle::default(); let timeout = 120u32;