11use std:: fmt:: Debug ;
2+ use std:: net:: SocketAddr ;
23use std:: sync:: Arc ;
34
45//use serde::{Deserialize, Serialize};
@@ -17,7 +18,7 @@ pub trait Entry {
1718 fn get_stats ( & self ) -> SwarmMetadata ;
1819
1920 /// 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 ;
2122
2223 /// Returns True if the Peers is Empty
2324 fn peers_is_empty ( & self ) -> bool ;
@@ -33,7 +34,7 @@ pub trait Entry {
3334 ///
3435 /// It filters out the input peer, typically because we want to return this
3536 /// 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 > > ;
3738
3839 /// It updates a peer and returns true if the number of complete downloads have increased.
3940 ///
@@ -51,28 +52,26 @@ pub trait Entry {
5152#[ allow( clippy:: module_name_repetitions) ]
5253pub trait EntrySync {
5354 fn get_stats ( & self ) -> SwarmMetadata ;
54- fn is_not_zombie ( & self , policy : & TrackerPolicy ) -> bool ;
55+ fn is_good ( & self , policy : & TrackerPolicy ) -> bool ;
5556 fn peers_is_empty ( & self ) -> bool ;
5657 fn get_peers_len ( & self ) -> usize ;
5758 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 > > ;
5960 fn insert_or_update_peer ( & self , peer : & peer:: Peer ) -> bool ;
6061 fn insert_or_update_peer_and_get_stats ( & self , peer : & peer:: Peer ) -> ( bool , SwarmMetadata ) ;
6162 fn remove_inactive_peers ( & self , current_cutoff : DurationSinceUnixEpoch ) ;
6263}
6364
6465#[ allow( clippy:: module_name_repetitions) ]
6566pub 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 ,
7675 limit : Option < usize > ,
7776 ) -> impl std:: future:: Future < Output = Vec < Arc < peer:: Peer > > > + Send ;
7877 fn insert_or_update_peer ( self , peer : & peer:: Peer ) -> impl std:: future:: Future < Output = bool > + Send ;
@@ -88,11 +87,11 @@ pub trait EntryAsync {
8887/// This is the tracker entry for a given torrent and contains the swarm data,
8988/// that's the list of all the peers trying to download the same torrent.
9089/// 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 ) ]
9291pub struct Torrent {
9392 /// The swarm: a network of peers that are all trying to download the torrent associated to this entry
9493 // #[serde(skip)]
9594 pub ( crate ) peers : std:: collections:: BTreeMap < peer:: Id , Arc < peer:: Peer > > ,
9695 /// 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 ,
9897}
0 commit comments