keep peer list sorted in client_test

This commit is contained in:
arvidn 2020-01-11 11:49:01 +01:00 committed by Arvid Norberg
parent e18366bb6b
commit af12f5d6b8
1 changed files with 22 additions and 0 deletions

View File

@ -1750,7 +1750,29 @@ COLUMN OPTIONS
h.get_peer_info(peers);
if (print_peers && !peers.empty())
{
using lt::peer_info;
// sort connecting towards the bottom of the list, and by peer_id
// otherwise, to keep the list as stable as possible
std::sort(peers.begin(), peers.end()
, [](peer_info const& lhs, peer_info const& rhs)
{
{
bool const l = bool(lhs.flags & peer_info::connecting);
bool const r = bool(rhs.flags & peer_info::connecting);
if (l != r) return l < r;
}
{
bool const l = bool(lhs.flags & peer_info::handshake);
bool const r = bool(rhs.flags & peer_info::handshake);
if (l != r) return l < r;
}
return lhs.pid < rhs.pid;
});
pos += print_peer_info(out, peers, terminal_height - pos - 2);
}
if (print_trackers)
{