From af12f5d6b8dc47add564d7ce544bbaf26cd1de1e Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 11 Jan 2020 11:49:01 +0100 Subject: [PATCH] keep peer list sorted in client_test --- examples/client_test.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 9aac3fbc8..cb74d17f4 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -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) {