@@ -5,7 +5,6 @@ use torrust_tracker_primitives::pagination::Pagination;
55use torrust_tracker_primitives:: swarm_metadata:: { AggregateSwarmMetadata , SwarmMetadata } ;
66use torrust_tracker_primitives:: { peer, DurationSinceUnixEpoch , PersistentTorrent , PersistentTorrents } ;
77
8- use super :: Repository ;
98use crate :: entry:: peer_list:: PeerList ;
109use crate :: entry:: { Entry , EntrySync } ;
1110use 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 >
1918where
2019 EntryMutexStd : EntrySync ,
2120 EntrySingle : Entry ,
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 {
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
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 ;
0 commit comments