2424use std:: net:: { IpAddr , SocketAddr } ;
2525use std:: sync:: Arc ;
2626
27+ use aquatic_udp_protocol:: AnnounceEvent ;
2728use serde:: Serialize ;
2829
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 } ;
3131
3232/// Peer struct used by the core `Tracker`.
3333///
@@ -51,7 +51,7 @@ use crate::{ser_unix_time_value, DurationSinceUnixEpoch, IPVersion, NumberOfByte
5151/// event: AnnounceEvent::Started,
5252/// };
5353/// ```
54- #[ derive( Debug , Clone , Serialize , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
54+ #[ derive( Debug , Clone , Serialize , Copy , PartialEq , Eq , Hash ) ]
5555pub struct Peer {
5656 /// ID used by the downloader peer
5757 pub peer_id : Id ,
@@ -67,9 +67,22 @@ pub struct Peer {
6767 /// The number of bytes this peer still has to download
6868 pub left : NumberOfBytes ,
6969 /// 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" ) ]
7071 pub event : AnnounceEvent ,
7172}
7273
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+
7386pub trait ReadInfo {
7487 fn is_seeder ( & self ) -> bool ;
7588 fn get_event ( & self ) -> AnnounceEvent ;
@@ -344,8 +357,9 @@ impl<P: Encoding> FromIterator<Peer> for Vec<P> {
344357pub mod fixture {
345358 use std:: net:: { IpAddr , Ipv4Addr , SocketAddr } ;
346359
360+ use aquatic_udp_protocol:: AnnounceEvent ;
361+
347362 use super :: { Id , Peer } ;
348- use crate :: announce_event:: AnnounceEvent ;
349363 use crate :: { DurationSinceUnixEpoch , NumberOfBytes } ;
350364
351365 #[ derive( PartialEq , Debug ) ]
0 commit comments