mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-30 03:03:17 +00:00
Make get_random_gray_peer distribution uniform
get_random_gray_peer is used to implement feeler connections, described in: https://eprint.iacr.org/2015/263.pdf 2. Random selection
This commit is contained in:
parent
beee286c7b
commit
f3be9991d7
1 changed files with 2 additions and 5 deletions
|
@ -408,13 +408,10 @@ namespace nodetool
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t x = crypto::rand<size_t>() % (m_peers_gray.size() + 1);
|
size_t random_index = crypto::rand<size_t>() % m_peers_gray.size();
|
||||||
size_t res = (x * x * x) / (m_peers_gray.size() * m_peers_gray.size()); //parabola \/
|
|
||||||
|
|
||||||
LOG_PRINT_L3("Random gray peer index=" << res << "(x="<< x << ", max_index=" << m_peers_gray.size() << ")");
|
|
||||||
|
|
||||||
peers_indexed::index<by_time>::type& by_time_index = m_peers_gray.get<by_time>();
|
peers_indexed::index<by_time>::type& by_time_index = m_peers_gray.get<by_time>();
|
||||||
pe = *epee::misc_utils::move_it_backward(--by_time_index.end(), res);
|
pe = *epee::misc_utils::move_it_backward(--by_time_index.end(), random_index);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue