@@ -8,6 +8,8 @@ use torrust_tracker_primitives::peer::ReadInfo as _;
8
8
use torrust_tracker_primitives:: swarm_metadata:: SwarmMetadata ;
9
9
use torrust_tracker_primitives:: { peer, DurationSinceUnixEpoch } ;
10
10
11
+ use crate :: { EntryMutexStd , EntryMutexTokio , EntrySingle } ;
12
+
11
13
/// A data structure containing all the information about a torrent in the tracker.
12
14
///
13
15
/// This is the tracker entry for a given torrent and contains the swarm data,
@@ -21,9 +23,6 @@ pub struct Entry {
21
23
/// The number of peers that have ever completed downloading the torrent associated to this entry
22
24
pub ( crate ) completed : u32 ,
23
25
}
24
- pub type Single = Entry ;
25
- pub type MutexStd = Arc < std:: sync:: Mutex < Entry > > ;
26
- pub type MutexTokio = Arc < tokio:: sync:: Mutex < Entry > > ;
27
26
28
27
pub trait ReadInfo {
29
28
/// It returns the swarm metadata (statistics) as a struct:
@@ -115,7 +114,7 @@ pub trait UpdateAsync {
115
114
fn remove_inactive_peers ( self , current_cutoff : DurationSinceUnixEpoch ) -> impl std:: future:: Future < Output = ( ) > + Send ;
116
115
}
117
116
118
- impl ReadInfo for Single {
117
+ impl ReadInfo for EntrySingle {
119
118
#[ allow( clippy:: cast_possible_truncation) ]
120
119
fn get_stats ( & self ) -> SwarmMetadata {
121
120
let complete: u32 = self . peers . values ( ) . filter ( |peer| peer. is_seeder ( ) ) . count ( ) as u32 ;
@@ -149,7 +148,7 @@ impl ReadInfo for Single {
149
148
}
150
149
}
151
150
152
- impl ReadInfo for MutexStd {
151
+ impl ReadInfo for EntryMutexStd {
153
152
fn get_stats ( & self ) -> SwarmMetadata {
154
153
self . lock ( ) . expect ( "it should get a lock" ) . get_stats ( )
155
154
}
@@ -167,7 +166,7 @@ impl ReadInfo for MutexStd {
167
166
}
168
167
}
169
168
170
- impl ReadInfoAsync for MutexTokio {
169
+ impl ReadInfoAsync for EntryMutexTokio {
171
170
async fn get_stats ( self ) -> SwarmMetadata {
172
171
self . lock ( ) . await . get_stats ( )
173
172
}
@@ -185,7 +184,7 @@ impl ReadInfoAsync for MutexTokio {
185
184
}
186
185
}
187
186
188
- impl ReadPeers for Single {
187
+ impl ReadPeers for EntrySingle {
189
188
fn get_peers ( & self , limit : Option < usize > ) -> Vec < Arc < peer:: Peer > > {
190
189
match limit {
191
190
Some ( limit) => self . peers . values ( ) . take ( limit) . cloned ( ) . collect ( ) ,
@@ -215,7 +214,7 @@ impl ReadPeers for Single {
215
214
}
216
215
}
217
216
218
- impl ReadPeers for MutexStd {
217
+ impl ReadPeers for EntryMutexStd {
219
218
fn get_peers ( & self , limit : Option < usize > ) -> Vec < Arc < peer:: Peer > > {
220
219
self . lock ( ) . expect ( "it should get lock" ) . get_peers ( limit)
221
220
}
@@ -225,7 +224,7 @@ impl ReadPeers for MutexStd {
225
224
}
226
225
}
227
226
228
- impl ReadPeersAsync for MutexTokio {
227
+ impl ReadPeersAsync for EntryMutexTokio {
229
228
async fn get_peers ( self , limit : Option < usize > ) -> Vec < Arc < peer:: Peer > > {
230
229
self . lock ( ) . await . get_peers ( limit)
231
230
}
@@ -235,7 +234,7 @@ impl ReadPeersAsync for MutexTokio {
235
234
}
236
235
}
237
236
238
- impl Update for Single {
237
+ impl Update for EntrySingle {
239
238
fn insert_or_update_peer ( & mut self , peer : & peer:: Peer ) -> bool {
240
239
let mut did_torrent_stats_change: bool = false ;
241
240
@@ -270,7 +269,7 @@ impl Update for Single {
270
269
}
271
270
}
272
271
273
- impl UpdateSync for MutexStd {
272
+ impl UpdateSync for EntryMutexStd {
274
273
fn insert_or_update_peer ( & self , peer : & peer:: Peer ) -> bool {
275
274
self . lock ( ) . expect ( "it should lock the entry" ) . insert_or_update_peer ( peer)
276
275
}
@@ -288,7 +287,7 @@ impl UpdateSync for MutexStd {
288
287
}
289
288
}
290
289
291
- impl UpdateAsync for MutexTokio {
290
+ impl UpdateAsync for EntryMutexTokio {
292
291
async fn insert_or_update_peer ( self , peer : & peer:: Peer ) -> bool {
293
292
self . lock ( ) . await . insert_or_update_peer ( peer)
294
293
}
0 commit comments