refactor: improve criteria for choosing peers to save to resume (#6922)

* fix: only consider peers with listening ports interesting

It's a waste of space to store peers we cannot connect to (because we don't know what their listening port is).

* fix: don't consider peer as interesting just because we are currently connected to it

For example, it's possible for a peer to be "in-use" and "banned" at the same time, albeit just for a very short while.

* code review: assert that peer port is not empty
This commit is contained in:
Yat Ho 2024-10-14 02:48:49 +08:00 committed by GitHub
parent 4db50dae10
commit 21d7720749
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 3 deletions

View File

@ -1465,14 +1465,15 @@ namespace get_peers_helpers
[[nodiscard]] bool is_peer_interesting(tr_torrent const* tor, tr_peer_info const& info)
{
if (tor->is_done() && info.is_upload_only())
TR_ASSERT(!std::empty(info.listen_port()));
if (std::empty(info.listen_port()))
{
return false;
}
if (info.is_in_use())
if (tor->is_done() && info.is_upload_only())
{
return true;
return false;
}
if (info.is_blocklisted(tor->session->blocklist()))