aquatic: announce handler: improve safety by small margin

This commit is contained in:
Joakim Frostegård 2020-04-08 20:26:39 +02:00
parent 789783cfe4
commit 766606cc08

View file

@ -84,8 +84,9 @@ pub fn handle_announce_requests(
let max_num_peers_to_take = (request.peers_wanted.0.max(0) as usize) let max_num_peers_to_take = (request.peers_wanted.0.max(0) as usize)
.min(config.max_response_peers); .min(config.max_response_peers);
let torrent_data = state.torrents.get(&request.info_hash).unwrap(); // Since there is a miniscule risk of the torrent having been removed
// by now, don't unwrap the result.
if let Some(torrent_data) = state.torrents.get(&request.info_hash){
match peer_status { match peer_status {
PeerStatus::Leeching => { PeerStatus::Leeching => {
torrent_data.num_leechers.fetch_add(1, Ordering::SeqCst); torrent_data.num_leechers.fetch_add(1, Ordering::SeqCst);
@ -121,6 +122,9 @@ pub fn handle_announce_requests(
}); });
Some((response, src)) Some((response, src))
} else {
None
}
})); }));
} }