Skip to content

Commit df00533

Browse files
committed
refactor: [torrust#1491] rename main types in torrent-repository pkg
1 parent 9be7c68 commit df00533

File tree

9 files changed

+55
-57
lines changed

9 files changed

+55
-57
lines changed
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
pub mod peer_list;
22
pub mod torrent;
3-
4-
use std::sync::{Arc, Mutex};
5-
6-
pub type TorrentEntry = Arc<Mutex<torrent::Torrent>>;

packages/torrent-repository/src/entry/torrent.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ use super::peer_list::PeerList;
1616
/// that's the list of all the peers trying to download the same torrent.
1717
/// The tracker keeps one entry like this for every torrent.
1818
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
19-
pub struct Torrent {
19+
pub struct TrackedTorrent {
2020
/// A network of peers that are all trying to download the torrent associated to this entry
2121
pub(crate) swarm: PeerList,
2222

2323
/// The number of peers that have ever completed downloading the torrent associated to this entry
2424
pub(crate) downloaded: u32,
2525
}
2626

27-
impl Torrent {
27+
impl TrackedTorrent {
2828
#[allow(clippy::cast_possible_truncation)]
2929
#[must_use]
3030
pub fn get_swarm_metadata(&self) -> SwarmMetadata {

packages/torrent-repository/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
pub mod entry;
22
pub mod repository;
33

4+
use std::sync::{Arc, Mutex};
5+
46
use torrust_tracker_clock::clock;
57

6-
pub type TorrentEntry = entry::TorrentEntry;
7-
pub type Torrent = entry::torrent::Torrent;
8-
pub type Torrents = repository::TorrentsSkipMapMutexStd;
8+
pub type TorrentRepository = repository::TorrentRepository;
9+
pub type TrackedTorrentHandle = Arc<Mutex<TrackedTorrent>>;
10+
pub type TrackedTorrent = entry::torrent::TrackedTorrent;
911

1012
/// Working version, for production.
1113
#[cfg(not(test))]

packages/torrent-repository/src/repository.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMe
66
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
77

88
use crate::entry::peer_list::PeerList;
9-
use crate::entry::torrent::Torrent;
10-
use crate::TorrentEntry;
9+
use crate::entry::torrent::TrackedTorrent;
10+
use crate::TrackedTorrentHandle;
1111

1212
#[derive(Default, Debug)]
13-
pub struct TorrentsSkipMapMutexStd {
14-
pub torrents: SkipMap<InfoHash, TorrentEntry>,
13+
pub struct TorrentRepository {
14+
pub torrents: SkipMap<InfoHash, TrackedTorrentHandle>,
1515
}
1616

17-
impl TorrentsSkipMapMutexStd {
17+
impl TorrentRepository {
1818
/// Upsert a peer into the swarm of a torrent.
1919
///
2020
/// Optionally, it can also preset the number of downloads of the torrent
@@ -53,15 +53,15 @@ impl TorrentsSkipMapMutexStd {
5353
tracing::debug!("Inserting new torrent: {:?}", info_hash);
5454

5555
let new_entry = if let Some(number_of_downloads) = opt_persistent_torrent {
56-
TorrentEntry::new(
57-
Torrent {
56+
TrackedTorrentHandle::new(
57+
TrackedTorrent {
5858
swarm: PeerList::default(),
5959
downloaded: number_of_downloads,
6060
}
6161
.into(),
6262
)
6363
} else {
64-
TorrentEntry::default()
64+
TrackedTorrentHandle::default()
6565
};
6666

6767
let inserted_entry = self.torrents.get_or_insert(*info_hash, new_entry);
@@ -85,7 +85,7 @@ impl TorrentsSkipMapMutexStd {
8585
})
8686
}
8787

88-
pub fn get(&self, key: &InfoHash) -> Option<TorrentEntry> {
88+
pub fn get(&self, key: &InfoHash) -> Option<TrackedTorrentHandle> {
8989
let maybe_entry = self.torrents.get(key);
9090
maybe_entry.map(|entry| entry.value().clone())
9191
}
@@ -107,7 +107,7 @@ impl TorrentsSkipMapMutexStd {
107107
metrics
108108
}
109109

110-
pub fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, TorrentEntry)> {
110+
pub fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, TrackedTorrentHandle)> {
111111
match pagination {
112112
Some(pagination) => self
113113
.torrents
@@ -130,8 +130,8 @@ impl TorrentsSkipMapMutexStd {
130130
continue;
131131
}
132132

133-
let entry = TorrentEntry::new(
134-
Torrent {
133+
let entry = TrackedTorrentHandle::new(
134+
TrackedTorrent {
135135
swarm: PeerList::default(),
136136
downloaded: *completed,
137137
}
@@ -144,7 +144,7 @@ impl TorrentsSkipMapMutexStd {
144144
}
145145
}
146146

147-
pub fn remove(&self, key: &InfoHash) -> Option<TorrentEntry> {
147+
pub fn remove(&self, key: &InfoHash) -> Option<TrackedTorrentHandle> {
148148
self.torrents.remove(key).map(|entry| entry.value().clone())
149149
}
150150

packages/torrent-repository/tests/common/repo.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use torrust_tracker_configuration::TrackerPolicy;
55
use torrust_tracker_primitives::pagination::Pagination;
66
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
77
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
8-
use torrust_tracker_torrent_repository::entry::torrent::Torrent;
9-
use torrust_tracker_torrent_repository::Torrents;
8+
use torrust_tracker_torrent_repository::entry::torrent::TrackedTorrent;
9+
use torrust_tracker_torrent_repository::TorrentRepository;
1010

1111
#[derive(Debug)]
1212
pub(crate) enum Repo {
13-
SkipMapMutexStd(Torrents),
13+
SkipMapMutexStd(TorrentRepository),
1414
}
1515

1616
impl Repo {
@@ -31,7 +31,7 @@ impl Repo {
3131
}
3232
}
3333

34-
pub(crate) fn get(&self, key: &InfoHash) -> Option<Torrent> {
34+
pub(crate) fn get(&self, key: &InfoHash) -> Option<TrackedTorrent> {
3535
match self {
3636
Repo::SkipMapMutexStd(repo) => Some(repo.get(key)?.lock().unwrap().clone()),
3737
}
@@ -43,7 +43,7 @@ impl Repo {
4343
}
4444
}
4545

46-
pub(crate) fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, Torrent)> {
46+
pub(crate) fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, TrackedTorrent)> {
4747
match self {
4848
Repo::SkipMapMutexStd(repo) => repo
4949
.get_paginated(pagination)
@@ -59,7 +59,7 @@ impl Repo {
5959
}
6060
}
6161

62-
pub(crate) fn remove(&self, key: &InfoHash) -> Option<Torrent> {
62+
pub(crate) fn remove(&self, key: &InfoHash) -> Option<TrackedTorrent> {
6363
match self {
6464
Repo::SkipMapMutexStd(repo) => Some(repo.remove(key)?.lock().unwrap().clone()),
6565
}
@@ -77,7 +77,7 @@ impl Repo {
7777
}
7878
}
7979

80-
pub(crate) fn insert(&self, info_hash: &InfoHash, torrent: Torrent) -> Option<Torrent> {
80+
pub(crate) fn insert(&self, info_hash: &InfoHash, torrent: TrackedTorrent) -> Option<TrackedTorrent> {
8181
match self {
8282
Repo::SkipMapMutexStd(repo) => {
8383
repo.torrents.insert(*info_hash, Arc::new(Mutex::new(torrent)));

packages/torrent-repository/tests/common/torrent.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use std::sync::Arc;
44
use torrust_tracker_configuration::TrackerPolicy;
55
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
66
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch};
7-
use torrust_tracker_torrent_repository::{entry, TorrentEntry};
7+
use torrust_tracker_torrent_repository::{entry, TrackedTorrentHandle};
88

99
#[derive(Debug, Clone)]
1010
pub(crate) enum Torrent {
11-
Single(entry::torrent::Torrent),
12-
MutexStd(TorrentEntry),
11+
Single(entry::torrent::TrackedTorrent),
12+
MutexStd(TrackedTorrentHandle),
1313
}
1414

1515
impl Torrent {

packages/torrent-repository/tests/entry/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ use torrust_tracker_clock::clock::{self, Time as _};
99
use torrust_tracker_configuration::{TrackerPolicy, TORRENT_PEERS_LIMIT};
1010
use torrust_tracker_primitives::peer;
1111
use torrust_tracker_primitives::peer::Peer;
12-
use torrust_tracker_torrent_repository::{entry, TorrentEntry};
12+
use torrust_tracker_torrent_repository::{entry, TrackedTorrentHandle};
1313

1414
use crate::common::torrent::Torrent;
1515
use crate::common::torrent_peer_builder::{a_completed_peer, a_started_peer};
1616
use crate::CurrentClock;
1717

1818
#[fixture]
1919
fn single() -> Torrent {
20-
Torrent::Single(entry::torrent::Torrent::default())
20+
Torrent::Single(entry::torrent::TrackedTorrent::default())
2121
}
2222
#[fixture]
2323
fn mutex_std() -> Torrent {
24-
Torrent::MutexStd(TorrentEntry::default())
24+
Torrent::MutexStd(TrackedTorrentHandle::default())
2525
}
2626

2727
#[fixture]

packages/torrent-repository/tests/repository/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ use torrust_tracker_configuration::TrackerPolicy;
88
use torrust_tracker_primitives::pagination::Pagination;
99
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
1010
use torrust_tracker_primitives::PersistentTorrents;
11-
use torrust_tracker_torrent_repository::entry::torrent::Torrent;
12-
use torrust_tracker_torrent_repository::Torrents;
11+
use torrust_tracker_torrent_repository::entry::torrent::TrackedTorrent;
12+
use torrust_tracker_torrent_repository::TorrentRepository;
1313

1414
use crate::common::repo::Repo;
1515
use crate::common::torrent_peer_builder::{a_completed_peer, a_started_peer};
1616

1717
#[fixture]
1818
fn skip_list_mutex_std() -> Repo {
19-
Repo::SkipMapMutexStd(Torrents::default())
19+
Repo::SkipMapMutexStd(TorrentRepository::default())
2020
}
2121

22-
type Entries = Vec<(InfoHash, Torrent)>;
22+
type Entries = Vec<(InfoHash, TrackedTorrent)>;
2323

2424
#[fixture]
2525
fn empty() -> Entries {
@@ -28,26 +28,26 @@ fn empty() -> Entries {
2828

2929
#[fixture]
3030
fn default() -> Entries {
31-
vec![(InfoHash::default(), Torrent::default())]
31+
vec![(InfoHash::default(), TrackedTorrent::default())]
3232
}
3333

3434
#[fixture]
3535
fn started() -> Entries {
36-
let mut torrent = Torrent::default();
36+
let mut torrent = TrackedTorrent::default();
3737
torrent.upsert_peer(&a_started_peer(1));
3838
vec![(InfoHash::default(), torrent)]
3939
}
4040

4141
#[fixture]
4242
fn completed() -> Entries {
43-
let mut torrent = Torrent::default();
43+
let mut torrent = TrackedTorrent::default();
4444
torrent.upsert_peer(&a_completed_peer(2));
4545
vec![(InfoHash::default(), torrent)]
4646
}
4747

4848
#[fixture]
4949
fn downloaded() -> Entries {
50-
let mut torrent = Torrent::default();
50+
let mut torrent = TrackedTorrent::default();
5151
let mut peer = a_started_peer(3);
5252
torrent.upsert_peer(&peer);
5353
peer.event = AnnounceEvent::Completed;
@@ -58,17 +58,17 @@ fn downloaded() -> Entries {
5858

5959
#[fixture]
6060
fn three() -> Entries {
61-
let mut started = Torrent::default();
61+
let mut started = TrackedTorrent::default();
6262
let started_h = &mut DefaultHasher::default();
6363
started.upsert_peer(&a_started_peer(1));
6464
started.hash(started_h);
6565

66-
let mut completed = Torrent::default();
66+
let mut completed = TrackedTorrent::default();
6767
let completed_h = &mut DefaultHasher::default();
6868
completed.upsert_peer(&a_completed_peer(2));
6969
completed.hash(completed_h);
7070

71-
let mut downloaded = Torrent::default();
71+
let mut downloaded = TrackedTorrent::default();
7272
let downloaded_h = &mut DefaultHasher::default();
7373
let mut downloaded_peer = a_started_peer(3);
7474
downloaded.upsert_peer(&downloaded_peer);
@@ -86,10 +86,10 @@ fn three() -> Entries {
8686

8787
#[fixture]
8888
fn many_out_of_order() -> Entries {
89-
let mut entries: HashSet<(InfoHash, Torrent)> = HashSet::default();
89+
let mut entries: HashSet<(InfoHash, TrackedTorrent)> = HashSet::default();
9090

9191
for i in 0..408 {
92-
let mut entry = Torrent::default();
92+
let mut entry = TrackedTorrent::default();
9393
entry.upsert_peer(&a_started_peer(i));
9494

9595
entries.insert((InfoHash::from(&i), entry));
@@ -101,10 +101,10 @@ fn many_out_of_order() -> Entries {
101101

102102
#[fixture]
103103
fn many_hashed_in_order() -> Entries {
104-
let mut entries: BTreeMap<InfoHash, Torrent> = BTreeMap::default();
104+
let mut entries: BTreeMap<InfoHash, TrackedTorrent> = BTreeMap::default();
105105

106106
for i in 0..408 {
107-
let mut entry = Torrent::default();
107+
let mut entry = TrackedTorrent::default();
108108
entry.upsert_peer(&a_started_peer(i));
109109

110110
let hash: &mut DefaultHasher = &mut DefaultHasher::default();

packages/tracker-core/src/torrent/repository/in_memory.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use torrust_tracker_configuration::{TrackerPolicy, TORRENT_PEERS_LIMIT};
77
use torrust_tracker_primitives::pagination::Pagination;
88
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
99
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
10-
use torrust_tracker_torrent_repository::{TorrentEntry, Torrents};
10+
use torrust_tracker_torrent_repository::{TorrentRepository, TrackedTorrentHandle};
1111

1212
/// In-memory repository for torrent entries.
1313
///
@@ -21,7 +21,7 @@ use torrust_tracker_torrent_repository::{TorrentEntry, Torrents};
2121
#[derive(Debug, Default)]
2222
pub struct InMemoryTorrentRepository {
2323
/// The underlying in-memory data structure that stores torrent entries.
24-
torrents: Arc<Torrents>,
24+
torrents: Arc<TorrentRepository>,
2525
}
2626

2727
impl InMemoryTorrentRepository {
@@ -64,7 +64,7 @@ impl InMemoryTorrentRepository {
6464
/// An `Option` containing the removed torrent entry if it existed.
6565
#[cfg(test)]
6666
#[must_use]
67-
pub(crate) fn remove(&self, key: &InfoHash) -> Option<TorrentEntry> {
67+
pub(crate) fn remove(&self, key: &InfoHash) -> Option<TrackedTorrentHandle> {
6868
self.torrents.remove(key)
6969
}
7070

@@ -104,7 +104,7 @@ impl InMemoryTorrentRepository {
104104
///
105105
/// An `Option` containing the torrent entry if found.
106106
#[must_use]
107-
pub(crate) fn get(&self, key: &InfoHash) -> Option<TorrentEntry> {
107+
pub(crate) fn get(&self, key: &InfoHash) -> Option<TrackedTorrentHandle> {
108108
self.torrents.get(key)
109109
}
110110

@@ -122,7 +122,7 @@ impl InMemoryTorrentRepository {
122122
///
123123
/// A vector of `(InfoHash, TorrentEntry)` tuples.
124124
#[must_use]
125-
pub(crate) fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, TorrentEntry)> {
125+
pub(crate) fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, TrackedTorrentHandle)> {
126126
self.torrents.get_paginated(pagination)
127127
}
128128

@@ -510,7 +510,7 @@ mod tests {
510510

511511
use torrust_tracker_primitives::peer::Peer;
512512
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
513-
use torrust_tracker_torrent_repository::TorrentEntry;
513+
use torrust_tracker_torrent_repository::TrackedTorrentHandle;
514514

515515
use crate::test_helpers::tests::{sample_info_hash, sample_peer};
516516
use crate::torrent::repository::in_memory::InMemoryTorrentRepository;
@@ -526,7 +526,7 @@ mod tests {
526526
}
527527

528528
#[allow(clippy::from_over_into)]
529-
impl Into<TorrentEntryInfo> for TorrentEntry {
529+
impl Into<TorrentEntryInfo> for TrackedTorrentHandle {
530530
fn into(self) -> TorrentEntryInfo {
531531
let torrent_guard = self.lock().expect("can't acquire lock for torrent entry");
532532

0 commit comments

Comments
 (0)