mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
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:
parent
4cc5e174d9
commit
83a80eb65a
1 changed files with 9 additions and 2 deletions
|
@ -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;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue