Skip to content

Commit 382e0af

Browse files
committed
faet!: [torrust#1491] remove unused trait Repository
1 parent 89123fa commit 382e0af

File tree

4 files changed

+18
-33
lines changed

4 files changed

+18
-33
lines changed
Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1 @@
1-
use bittorrent_primitives::info_hash::InfoHash;
2-
use torrust_tracker_configuration::TrackerPolicy;
3-
use torrust_tracker_primitives::pagination::Pagination;
4-
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
5-
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
6-
71
pub mod skip_map_mutex_std;
8-
9-
use std::fmt::Debug;
10-
11-
pub trait Repository<T>: Debug + Default + Sized + 'static {
12-
fn get(&self, key: &InfoHash) -> Option<T>;
13-
fn get_metrics(&self) -> AggregateSwarmMetadata;
14-
fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, T)>;
15-
fn import_persistent(&self, persistent_torrents: &PersistentTorrents);
16-
fn remove(&self, key: &InfoHash) -> Option<T>;
17-
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch);
18-
fn remove_peerless_torrents(&self, policy: &TrackerPolicy);
19-
fn upsert_peer(&self, info_hash: &InfoHash, peer: &peer::Peer, opt_persistent_torrent: Option<PersistentTorrent>) -> bool;
20-
fn get_swarm_metadata(&self, info_hash: &InfoHash) -> Option<SwarmMetadata>;
21-
}

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use torrust_tracker_primitives::pagination::Pagination;
55
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
66
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
77

8-
use super::Repository;
98
use crate::entry::peer_list::PeerList;
109
use crate::entry::{Entry, EntrySync};
1110
use crate::{EntryMutexStd, EntrySingle};
@@ -15,7 +14,7 @@ pub struct CrossbeamSkipList<T> {
1514
pub torrents: SkipMap<InfoHash, T>,
1615
}
1716

18-
impl Repository<EntryMutexStd> for CrossbeamSkipList<EntryMutexStd>
17+
impl CrossbeamSkipList<EntryMutexStd>
1918
where
2019
EntryMutexStd: EntrySync,
2120
EntrySingle: Entry,
@@ -36,7 +35,12 @@ where
3635
///
3736
/// Returns `true` if the number of downloads was increased because the peer
3837
/// completed the download.
39-
fn upsert_peer(&self, info_hash: &InfoHash, peer: &peer::Peer, opt_persistent_torrent: Option<PersistentTorrent>) -> bool {
38+
pub fn upsert_peer(
39+
&self,
40+
info_hash: &InfoHash,
41+
peer: &peer::Peer,
42+
opt_persistent_torrent: Option<PersistentTorrent>,
43+
) -> bool {
4044
if let Some(existing_entry) = self.torrents.get(info_hash) {
4145
existing_entry.value().upsert_peer(peer)
4246
} else {
@@ -58,16 +62,19 @@ where
5862
}
5963
}
6064

61-
fn get_swarm_metadata(&self, info_hash: &InfoHash) -> Option<SwarmMetadata> {
65+
pub fn get_swarm_metadata(&self, info_hash: &InfoHash) -> Option<SwarmMetadata> {
6266
self.torrents.get(info_hash).map(|entry| entry.value().get_swarm_metadata())
6367
}
6468

65-
fn get(&self, key: &InfoHash) -> Option<EntryMutexStd> {
69+
pub fn get(&self, key: &InfoHash) -> Option<EntryMutexStd> {
6670
let maybe_entry = self.torrents.get(key);
6771
maybe_entry.map(|entry| entry.value().clone())
6872
}
6973

70-
fn get_metrics(&self) -> AggregateSwarmMetadata {
74+
/// # Panics
75+
///
76+
/// This function panics if the lock for the entry cannot be obtained.
77+
pub fn get_metrics(&self) -> AggregateSwarmMetadata {
7178
let mut metrics = AggregateSwarmMetadata::default();
7279

7380
for entry in &self.torrents {
@@ -81,7 +88,7 @@ where
8188
metrics
8289
}
8390

84-
fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, EntryMutexStd)> {
91+
pub fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, EntryMutexStd)> {
8592
match pagination {
8693
Some(pagination) => self
8794
.torrents
@@ -98,7 +105,7 @@ where
98105
}
99106
}
100107

101-
fn import_persistent(&self, persistent_torrents: &PersistentTorrents) {
108+
pub fn import_persistent(&self, persistent_torrents: &PersistentTorrents) {
102109
for (info_hash, completed) in persistent_torrents {
103110
if self.torrents.contains_key(info_hash) {
104111
continue;
@@ -118,17 +125,17 @@ where
118125
}
119126
}
120127

121-
fn remove(&self, key: &InfoHash) -> Option<EntryMutexStd> {
128+
pub fn remove(&self, key: &InfoHash) -> Option<EntryMutexStd> {
122129
self.torrents.remove(key).map(|entry| entry.value().clone())
123130
}
124131

125-
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch) {
132+
pub fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch) {
126133
for entry in &self.torrents {
127134
entry.value().remove_inactive_peers(current_cutoff);
128135
}
129136
}
130137

131-
fn remove_peerless_torrents(&self, policy: &TrackerPolicy) {
138+
pub fn remove_peerless_torrents(&self, policy: &TrackerPolicy) {
132139
for entry in &self.torrents {
133140
if entry.value().meets_retaining_policy(policy) {
134141
continue;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use torrust_tracker_configuration::TrackerPolicy;
33
use torrust_tracker_primitives::pagination::Pagination;
44
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
55
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
6-
use torrust_tracker_torrent_repository::repository::Repository as _;
76
use torrust_tracker_torrent_repository::{EntrySingle, TorrentsSkipMapMutexStd};
87

98
#[derive(Debug)]

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use torrust_tracker_primitives::pagination::Pagination;
88
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
99
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent, PersistentTorrents};
1010
use torrust_tracker_torrent_repository::entry::EntrySync;
11-
use torrust_tracker_torrent_repository::repository::Repository;
1211
use torrust_tracker_torrent_repository::EntryMutexStd;
1312

1413
use crate::torrent::Torrents;

0 commit comments

Comments
 (0)