11
11
//! That's the most valuable information the peer want to get from the tracker, because it allows them to
12
12
//! start downloading torrent from those peers.
13
13
//!
14
- //! > **NOTICE**: that both swarm data (torrent entries) and swarm metadata (aggregate counters) are related to only one torrent.
15
- //!
16
14
//! The "swarm metadata" contains aggregate data derived from the torrent entries. There two types of data:
17
15
//!
18
16
//! - For **active peers**: metrics related to the current active peers in the swarm.
@@ -35,10 +33,10 @@ use derive_more::Constructor;
35
33
36
34
pub type Torrents = TorrentsRwLockStd ; // Currently Used
37
35
38
- pub type TorrentsRwLockStd = repository:: RwLockStd < entry:: Entry > ;
36
+ pub type TorrentsRwLockStd = repository:: RwLockStd < entry:: Single > ;
39
37
pub type TorrentsRwLockStdMutexStd = repository:: RwLockStd < entry:: MutexStd > ;
40
38
pub type TorrentsRwLockStdMutexTokio = repository:: RwLockStd < entry:: MutexTokio > ;
41
- pub type TorrentsRwLockTokio = repository:: RwLockTokio < entry:: Entry > ;
39
+ pub type TorrentsRwLockTokio = repository:: RwLockTokio < entry:: Single > ;
42
40
pub type TorrentsRwLockTokioMutexStd = repository:: RwLockTokio < entry:: MutexStd > ;
43
41
pub type TorrentsRwLockTokioMutexTokio = repository:: RwLockTokio < entry:: MutexTokio > ;
44
42
@@ -147,14 +145,14 @@ mod tests {
147
145
148
146
#[ test]
149
147
fn the_default_torrent_entry_should_contain_an_empty_list_of_peers ( ) {
150
- let torrent_entry = entry:: Entry :: default ( ) ;
148
+ let torrent_entry = entry:: Single :: default ( ) ;
151
149
152
150
assert_eq ! ( torrent_entry. get_peers( None ) . len( ) , 0 ) ;
153
151
}
154
152
155
153
#[ test]
156
154
fn a_new_peer_can_be_added_to_a_torrent_entry ( ) {
157
- let mut torrent_entry = entry:: Entry :: default ( ) ;
155
+ let mut torrent_entry = entry:: Single :: default ( ) ;
158
156
let torrent_peer = TorrentPeerBuilder :: default ( ) . into ( ) ;
159
157
160
158
torrent_entry. insert_or_update_peer ( & torrent_peer) ; // Add the peer
@@ -165,7 +163,7 @@ mod tests {
165
163
166
164
#[ test]
167
165
fn a_torrent_entry_should_contain_the_list_of_peers_that_were_added_to_the_torrent ( ) {
168
- let mut torrent_entry = entry:: Entry :: default ( ) ;
166
+ let mut torrent_entry = entry:: Single :: default ( ) ;
169
167
let torrent_peer = TorrentPeerBuilder :: default ( ) . into ( ) ;
170
168
171
169
torrent_entry. insert_or_update_peer ( & torrent_peer) ; // Add the peer
@@ -175,7 +173,7 @@ mod tests {
175
173
176
174
#[ test]
177
175
fn a_peer_can_be_updated_in_a_torrent_entry ( ) {
178
- let mut torrent_entry = entry:: Entry :: default ( ) ;
176
+ let mut torrent_entry = entry:: Single :: default ( ) ;
179
177
let mut torrent_peer = TorrentPeerBuilder :: default ( ) . into ( ) ;
180
178
torrent_entry. insert_or_update_peer ( & torrent_peer) ; // Add the peer
181
179
@@ -187,7 +185,7 @@ mod tests {
187
185
188
186
#[ test]
189
187
fn a_peer_should_be_removed_from_a_torrent_entry_when_the_peer_announces_it_has_stopped ( ) {
190
- let mut torrent_entry = entry:: Entry :: default ( ) ;
188
+ let mut torrent_entry = entry:: Single :: default ( ) ;
191
189
let mut torrent_peer = TorrentPeerBuilder :: default ( ) . into ( ) ;
192
190
torrent_entry. insert_or_update_peer ( & torrent_peer) ; // Add the peer
193
191
@@ -199,7 +197,7 @@ mod tests {
199
197
200
198
#[ test]
201
199
fn torrent_stats_change_when_a_previously_known_peer_announces_it_has_completed_the_torrent ( ) {
202
- let mut torrent_entry = entry:: Entry :: default ( ) ;
200
+ let mut torrent_entry = entry:: Single :: default ( ) ;
203
201
let mut torrent_peer = TorrentPeerBuilder :: default ( ) . into ( ) ;
204
202
205
203
torrent_entry. insert_or_update_peer ( & torrent_peer) ; // Add the peer
@@ -213,7 +211,7 @@ mod tests {
213
211
#[ test]
214
212
fn torrent_stats_should_not_change_when_a_peer_announces_it_has_completed_the_torrent_if_it_is_the_first_announce_from_the_peer (
215
213
) {
216
- let mut torrent_entry = entry:: Entry :: default ( ) ;
214
+ let mut torrent_entry = entry:: Single :: default ( ) ;
217
215
let torrent_peer_announcing_complete_event = TorrentPeerBuilder :: default ( ) . with_event_completed ( ) . into ( ) ;
218
216
219
217
// Add a peer that did not exist before in the entry
@@ -225,7 +223,7 @@ mod tests {
225
223
#[ test]
226
224
fn a_torrent_entry_should_return_the_list_of_peers_for_a_given_peer_filtering_out_the_client_that_is_making_the_request ( )
227
225
{
228
- let mut torrent_entry = entry:: Entry :: default ( ) ;
226
+ let mut torrent_entry = entry:: Single :: default ( ) ;
229
227
let peer_socket_address = SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ) , 8080 ) ;
230
228
let torrent_peer = TorrentPeerBuilder :: default ( ) . with_peer_address ( peer_socket_address) . into ( ) ;
231
229
torrent_entry. insert_or_update_peer ( & torrent_peer) ; // Add peer
@@ -238,7 +236,7 @@ mod tests {
238
236
239
237
#[ test]
240
238
fn two_peers_with_the_same_ip_but_different_port_should_be_considered_different_peers ( ) {
241
- let mut torrent_entry = entry:: Entry :: default ( ) ;
239
+ let mut torrent_entry = entry:: Single :: default ( ) ;
242
240
243
241
let peer_ip = IpAddr :: V4 ( Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ) ;
244
242
@@ -272,7 +270,7 @@ mod tests {
272
270
273
271
#[ test]
274
272
fn the_tracker_should_limit_the_list_of_peers_to_74_when_clients_scrape_torrents ( ) {
275
- let mut torrent_entry = entry:: Entry :: default ( ) ;
273
+ let mut torrent_entry = entry:: Single :: default ( ) ;
276
274
277
275
// We add one more peer than the scrape limit
278
276
for peer_number in 1 ..=74 + 1 {
@@ -289,7 +287,7 @@ mod tests {
289
287
290
288
#[ test]
291
289
fn torrent_stats_should_have_the_number_of_seeders_for_a_torrent ( ) {
292
- let mut torrent_entry = entry:: Entry :: default ( ) ;
290
+ let mut torrent_entry = entry:: Single :: default ( ) ;
293
291
let torrent_seeder = a_torrent_seeder ( ) ;
294
292
295
293
torrent_entry. insert_or_update_peer ( & torrent_seeder) ; // Add seeder
@@ -299,7 +297,7 @@ mod tests {
299
297
300
298
#[ test]
301
299
fn torrent_stats_should_have_the_number_of_leechers_for_a_torrent ( ) {
302
- let mut torrent_entry = entry:: Entry :: default ( ) ;
300
+ let mut torrent_entry = entry:: Single :: default ( ) ;
303
301
let torrent_leecher = a_torrent_leecher ( ) ;
304
302
305
303
torrent_entry. insert_or_update_peer ( & torrent_leecher) ; // Add leecher
@@ -310,7 +308,7 @@ mod tests {
310
308
#[ test]
311
309
fn torrent_stats_should_have_the_number_of_peers_that_having_announced_at_least_two_events_the_latest_one_is_the_completed_event (
312
310
) {
313
- let mut torrent_entry = entry:: Entry :: default ( ) ;
311
+ let mut torrent_entry = entry:: Single :: default ( ) ;
314
312
let mut torrent_peer = TorrentPeerBuilder :: default ( ) . into ( ) ;
315
313
torrent_entry. insert_or_update_peer ( & torrent_peer) ; // Add the peer
316
314
@@ -325,7 +323,7 @@ mod tests {
325
323
326
324
#[ test]
327
325
fn torrent_stats_should_not_include_a_peer_in_the_completed_counter_if_the_peer_has_announced_only_one_event ( ) {
328
- let mut torrent_entry = entry:: Entry :: default ( ) ;
326
+ let mut torrent_entry = entry:: Single :: default ( ) ;
329
327
let torrent_peer_announcing_complete_event = TorrentPeerBuilder :: default ( ) . with_event_completed ( ) . into ( ) ;
330
328
331
329
// Announce "Completed" torrent download event.
@@ -339,7 +337,7 @@ mod tests {
339
337
340
338
#[ test]
341
339
fn a_torrent_entry_should_remove_a_peer_not_updated_after_a_timeout_in_seconds ( ) {
342
- let mut torrent_entry = entry:: Entry :: default ( ) ;
340
+ let mut torrent_entry = entry:: Single :: default ( ) ;
343
341
344
342
let timeout = 120u32 ;
345
343
0 commit comments