aquatic_ws: save peer even if AnnounceRequest.bytes_left is None

This commit is contained in:
Joakim Frostegård 2020-05-15 16:02:49 +02:00
parent 008d8b8eff
commit cb66364fa5
3 changed files with 34 additions and 36 deletions

View file

@ -37,11 +37,11 @@ impl PeerStatus {
#[inline] #[inline]
pub fn from_event_and_bytes_left( pub fn from_event_and_bytes_left(
event: AnnounceEvent, event: AnnounceEvent,
bytes_left: usize opt_bytes_left: Option<usize>
) -> Self { ) -> Self {
if let AnnounceEvent::Stopped = event { if let AnnounceEvent::Stopped = event {
Self::Stopped Self::Stopped
} else if bytes_left == 0 { } else if let Some(0) = opt_bytes_left {
Self::Seeding Self::Seeding
} else { } else {
Self::Leeching Self::Leeching

View file

@ -109,11 +109,9 @@ pub fn handle_announce_requests(
} }
} }
// FIXME: correct to only update when bytes_left is Some?
if let Some(bytes_left) = request.bytes_left {
let peer_status = PeerStatus::from_event_and_bytes_left( let peer_status = PeerStatus::from_event_and_bytes_left(
request.event, request.event,
bytes_left request.bytes_left
); );
let peer = Peer { let peer = Peer {
@ -147,7 +145,6 @@ pub fn handle_announce_requests(
}, },
_ => {} _ => {}
} }
}
// If peer sent offers, send them on to random peers // If peer sent offers, send them on to random peers
if let Some(offers) = request.offers { if let Some(offers) = request.offers {

View file

@ -103,7 +103,8 @@ pub struct AnnounceRequestOffer {
pub struct AnnounceRequest { pub struct AnnounceRequest {
pub info_hash: InfoHash, pub info_hash: InfoHash,
pub peer_id: PeerId, pub peer_id: PeerId,
/// Just called "left" in protocol /// Just called "left" in protocol. Is set to None in some cases, such as
/// when opening a magnet link
#[serde(rename = "left")] #[serde(rename = "left")]
pub bytes_left: Option<usize>, pub bytes_left: Option<usize>,
/// Can be empty. Then, default is "update" /// Can be empty. Then, default is "update"