mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic: announce: fix bug in calculation of number of peers to take
This commit is contained in:
parent
8f68b3a9a2
commit
c44c5b017f
1 changed files with 20 additions and 2 deletions
|
|
@ -228,8 +228,10 @@ pub fn handle_announce_requests(
|
|||
.map(|peer| peer.status)
|
||||
};
|
||||
|
||||
let max_num_peers_to_take = (request.peers_wanted.0.max(0) as usize)
|
||||
.min(config.network.max_response_peers);
|
||||
let max_num_peers_to_take = calc_number_of_peers_to_take(
|
||||
config,
|
||||
request.peers_wanted.0
|
||||
);
|
||||
|
||||
match peer_status {
|
||||
PeerStatus::Leeching => {
|
||||
|
|
@ -359,6 +361,22 @@ pub fn extract_response_peers(
|
|||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
fn calc_number_of_peers_to_take(
|
||||
config: &Config,
|
||||
peers_wanted: i32,
|
||||
) -> usize {
|
||||
if peers_wanted <= 0 {
|
||||
config.network.max_response_peers as usize
|
||||
} else {
|
||||
::std::cmp::min(
|
||||
config.network.max_response_peers as usize,
|
||||
peers_wanted as usize
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[inline(always)]
|
||||
pub fn create_torrent_scrape_statistics(
|
||||
seeders: i32,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue