diff --git a/aquatic/src/lib/common.rs b/aquatic/src/lib/common.rs index e53dfc4..4ff7273 100644 --- a/aquatic/src/lib/common.rs +++ b/aquatic/src/lib/common.rs @@ -22,6 +22,7 @@ pub struct ConnectionKey { pub socket_addr: SocketAddr } + pub type ConnectionMap = DashMap; @@ -32,13 +33,14 @@ pub enum PeerStatus { Stopped } + impl PeerStatus { /// Determine peer status from announce event and number of bytes left. /// /// Likely, the last branch will be taken most of the time. #[inline] pub fn from_event_and_bytes_left( - event: AnnounceEvent, + event: AnnounceEvent, bytes_left: NumberOfBytes ) -> Self { if event == AnnounceEvent::Stopped { @@ -51,10 +53,9 @@ impl PeerStatus { } } + #[derive(Clone, Debug)] pub struct Peer { - pub id: PeerId, - pub connection_id: ConnectionId, pub ip_address: IpAddr, pub port: Port, pub status: PeerStatus, @@ -75,20 +76,21 @@ impl Peer { announce_request: &AnnounceRequest, ip_address: IpAddr ) -> Self { + let status = PeerStatus::from_event_and_bytes_left( + announce_request.event, + announce_request.bytes_left + ); + Self { - id: announce_request.peer_id, - connection_id: announce_request.connection_id, ip_address, port: announce_request.port, - status: PeerStatus::from_event_and_bytes_left( - announce_request.event, - announce_request.bytes_left - ), + status, last_announce: Time(Instant::now()) } } } + #[derive(PartialEq, Eq, Hash, Clone)] pub struct PeerMapKey { pub ip: IpAddr, @@ -98,6 +100,7 @@ pub struct PeerMapKey { pub type PeerMap = IndexMap; + pub struct TorrentData { pub peers: PeerMap, pub num_seeders: AtomicUsize, @@ -129,8 +132,6 @@ pub struct Statistics { } - - #[derive(Clone)] pub struct State { pub connections: Arc, diff --git a/aquatic/src/lib/handlers.rs b/aquatic/src/lib/handlers.rs index 77bc3c1..9517ef6 100644 --- a/aquatic/src/lib/handlers.rs +++ b/aquatic/src/lib/handlers.rs @@ -259,9 +259,7 @@ mod tests { peer_id, }; let value = Peer { - connection_id: ConnectionId(0), ip_address, - id: peer_id, port: Port(1), status: PeerStatus::Leeching, last_announce: Time(Instant::now()),