24
24
use std:: net:: { IpAddr , SocketAddr } ;
25
25
use std:: sync:: Arc ;
26
26
27
+ use aquatic_udp_protocol:: AnnounceEvent ;
27
28
use serde:: Serialize ;
28
29
29
- use crate :: announce_event:: AnnounceEvent ;
30
- use crate :: { ser_unix_time_value, DurationSinceUnixEpoch , IPVersion , NumberOfBytes } ;
30
+ use crate :: { ser_announce_event, ser_unix_time_value, DurationSinceUnixEpoch , IPVersion , NumberOfBytes } ;
31
31
32
32
/// Peer struct used by the core `Tracker`.
33
33
///
@@ -51,7 +51,7 @@ use crate::{ser_unix_time_value, DurationSinceUnixEpoch, IPVersion, NumberOfByte
51
51
/// event: AnnounceEvent::Started,
52
52
/// };
53
53
/// ```
54
- #[ derive( Debug , Clone , Serialize , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
54
+ #[ derive( Debug , Clone , Serialize , Copy , PartialEq , Eq , Hash ) ]
55
55
pub struct Peer {
56
56
/// ID used by the downloader peer
57
57
pub peer_id : Id ,
@@ -67,9 +67,22 @@ pub struct Peer {
67
67
/// The number of bytes this peer still has to download
68
68
pub left : NumberOfBytes ,
69
69
/// This is an optional key which maps to started, completed, or stopped (or empty, which is the same as not being present).
70
+ #[ serde( serialize_with = "ser_announce_event" ) ]
70
71
pub event : AnnounceEvent ,
71
72
}
72
73
74
+ impl Ord for Peer {
75
+ fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
76
+ self . peer_id . cmp ( & other. peer_id )
77
+ }
78
+ }
79
+
80
+ impl PartialOrd for Peer {
81
+ fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
82
+ Some ( self . peer_id . cmp ( & other. peer_id ) )
83
+ }
84
+ }
85
+
73
86
pub trait ReadInfo {
74
87
fn is_seeder ( & self ) -> bool ;
75
88
fn get_event ( & self ) -> AnnounceEvent ;
@@ -344,8 +357,9 @@ impl<P: Encoding> FromIterator<Peer> for Vec<P> {
344
357
pub mod fixture {
345
358
use std:: net:: { IpAddr , Ipv4Addr , SocketAddr } ;
346
359
360
+ use aquatic_udp_protocol:: AnnounceEvent ;
361
+
347
362
use super :: { Id , Peer } ;
348
- use crate :: announce_event:: AnnounceEvent ;
349
363
use crate :: { DurationSinceUnixEpoch , NumberOfBytes } ;
350
364
351
365
#[ derive( PartialEq , Debug ) ]
0 commit comments