protocol: prefer cycling low score peers

Cycling is meant to opportunistically connecting to a new peer
in case we're connected to a malicious subset of the network.
We now prefer dropping a low score peer, since those will be
either ones which already failed newly at least one test, or
newly connected ones at the same height. In particular, they
can't be a newly connected one that's found another chain, or
they'd be in synchronizing state, not normal state.
This commit is contained in:
moneromooo 2020-10-28 19:23:39 +00:00 committed by wowario
parent 4cc5e174d9
commit 83a80eb65a
No known key found for this signature in database
GPG key ID: 24DCBE762DE9C111

View file

@ -1691,6 +1691,7 @@ skip:
MTRACE("Checking for outgoing syncing peers..."); MTRACE("Checking for outgoing syncing peers...");
unsigned n_syncing = 0, n_synced = 0; unsigned n_syncing = 0, n_synced = 0;
boost::uuids::uuid last_synced_peer_id(boost::uuids::nil_uuid()); boost::uuids::uuid last_synced_peer_id(boost::uuids::nil_uuid());
int64_t lowest_score = std::numeric_limits<int64_t>::max();
m_p2p->for_each_connection([&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags)->bool m_p2p->for_each_connection([&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags)->bool
{ {
if (!peer_id || context.m_is_income) // only consider connected outgoing peers if (!peer_id || context.m_is_income) // only consider connected outgoing peers
@ -1700,8 +1701,14 @@ skip:
if (context.m_state == cryptonote_connection_context::state_normal) if (context.m_state == cryptonote_connection_context::state_normal)
{ {
++n_synced; ++n_synced;
if (!context.m_anchor) if (!context.m_anchor || context.m_score < 0)
last_synced_peer_id = context.m_connection_id; {
if (context.m_score <= lowest_score)
{
last_synced_peer_id = context.m_connection_id;
lowest_score = context.m_score;
}
}
} }
return true; return true;
}); });