1
1
use std:: fmt:: Debug ;
2
+ use std:: net:: SocketAddr ;
2
3
use std:: sync:: Arc ;
3
4
4
5
//use serde::{Deserialize, Serialize};
@@ -17,7 +18,7 @@ pub trait Entry {
17
18
fn get_stats ( & self ) -> SwarmMetadata ;
18
19
19
20
/// Returns True if Still a Valid Entry according to the Tracker Policy
20
- fn is_not_zombie ( & self , policy : & TrackerPolicy ) -> bool ;
21
+ fn is_good ( & self , policy : & TrackerPolicy ) -> bool ;
21
22
22
23
/// Returns True if the Peers is Empty
23
24
fn peers_is_empty ( & self ) -> bool ;
@@ -33,7 +34,7 @@ pub trait Entry {
33
34
///
34
35
/// It filters out the input peer, typically because we want to return this
35
36
/// list of peers to that client peer.
36
- fn get_peers_for_peer ( & self , client : & peer :: Peer , limit : Option < usize > ) -> Vec < Arc < peer:: Peer > > ;
37
+ fn get_peers_for_client ( & self , client : & SocketAddr , limit : Option < usize > ) -> Vec < Arc < peer:: Peer > > ;
37
38
38
39
/// It updates a peer and returns true if the number of complete downloads have increased.
39
40
///
@@ -51,28 +52,26 @@ pub trait Entry {
51
52
#[ allow( clippy:: module_name_repetitions) ]
52
53
pub trait EntrySync {
53
54
fn get_stats ( & self ) -> SwarmMetadata ;
54
- fn is_not_zombie ( & self , policy : & TrackerPolicy ) -> bool ;
55
+ fn is_good ( & self , policy : & TrackerPolicy ) -> bool ;
55
56
fn peers_is_empty ( & self ) -> bool ;
56
57
fn get_peers_len ( & self ) -> usize ;
57
58
fn get_peers ( & self , limit : Option < usize > ) -> Vec < Arc < peer:: Peer > > ;
58
- fn get_peers_for_peer ( & self , client : & peer :: Peer , limit : Option < usize > ) -> Vec < Arc < peer:: Peer > > ;
59
+ fn get_peers_for_client ( & self , client : & SocketAddr , limit : Option < usize > ) -> Vec < Arc < peer:: Peer > > ;
59
60
fn insert_or_update_peer ( & self , peer : & peer:: Peer ) -> bool ;
60
61
fn insert_or_update_peer_and_get_stats ( & self , peer : & peer:: Peer ) -> ( bool , SwarmMetadata ) ;
61
62
fn remove_inactive_peers ( & self , current_cutoff : DurationSinceUnixEpoch ) ;
62
63
}
63
64
64
65
#[ allow( clippy:: module_name_repetitions) ]
65
66
pub trait EntryAsync {
66
- fn get_stats ( self ) -> impl std:: future:: Future < Output = SwarmMetadata > + Send ;
67
-
68
- #[ allow( clippy:: wrong_self_convention) ]
69
- fn is_not_zombie ( self , policy : & TrackerPolicy ) -> impl std:: future:: Future < Output = bool > + Send ;
70
- fn peers_is_empty ( self ) -> impl std:: future:: Future < Output = bool > + Send ;
71
- fn get_peers_len ( self ) -> impl std:: future:: Future < Output = usize > + Send ;
72
- fn get_peers ( self , limit : Option < usize > ) -> impl std:: future:: Future < Output = Vec < Arc < peer:: Peer > > > + Send ;
73
- fn get_peers_for_peer (
74
- self ,
75
- client : & peer:: Peer ,
67
+ fn get_stats ( & self ) -> impl std:: future:: Future < Output = SwarmMetadata > + Send ;
68
+ fn check_good ( self , policy : & TrackerPolicy ) -> impl std:: future:: Future < Output = bool > + Send ;
69
+ fn peers_is_empty ( & self ) -> impl std:: future:: Future < Output = bool > + Send ;
70
+ fn get_peers_len ( & self ) -> impl std:: future:: Future < Output = usize > + Send ;
71
+ fn get_peers ( & self , limit : Option < usize > ) -> impl std:: future:: Future < Output = Vec < Arc < peer:: Peer > > > + Send ;
72
+ fn get_peers_for_client (
73
+ & self ,
74
+ client : & SocketAddr ,
76
75
limit : Option < usize > ,
77
76
) -> impl std:: future:: Future < Output = Vec < Arc < peer:: Peer > > > + Send ;
78
77
fn insert_or_update_peer ( self , peer : & peer:: Peer ) -> impl std:: future:: Future < Output = bool > + Send ;
@@ -88,11 +87,11 @@ pub trait EntryAsync {
88
87
/// This is the tracker entry for a given torrent and contains the swarm data,
89
88
/// that's the list of all the peers trying to download the same torrent.
90
89
/// The tracker keeps one entry like this for every torrent.
91
- #[ derive( Clone , Debug , Default ) ]
90
+ #[ derive( Clone , Debug , Default , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
92
91
pub struct Torrent {
93
92
/// The swarm: a network of peers that are all trying to download the torrent associated to this entry
94
93
// #[serde(skip)]
95
94
pub ( crate ) peers : std:: collections:: BTreeMap < peer:: Id , Arc < peer:: Peer > > ,
96
95
/// The number of peers that have ever completed downloading the torrent associated to this entry
97
- pub ( crate ) completed : u32 ,
96
+ pub ( crate ) downloaded : u32 ,
98
97
}
0 commit comments