aboutsummaryrefslogtreecommitdiff
path: root/src/p2p
diff options
context:
space:
mode:
authorMiguel Herranz <miguel@ipglider.org>2017-02-05 23:46:47 +0100
committerMiguel Herranz <miguel@ipglider.org>2017-02-27 18:29:50 +0100
commitf3be9991d7517182c416b1139d09f3943e31f0ee (patch)
treedd311599d47746a7652b8f27bbbf1c0508e77379 /src/p2p
parentMerge pull request #1798 (diff)
downloadmonero-f3be9991d7517182c416b1139d09f3943e31f0ee.tar.xz
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
Diffstat (limited to 'src/p2p')
-rw-r--r--src/p2p/net_peerlist.h7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h
index 6b999207b..11d995995 100644
--- a/src/p2p/net_peerlist.h
+++ b/src/p2p/net_peerlist.h
@@ -408,13 +408,10 @@ namespace nodetool
return false;
}
- size_t x = crypto::rand<size_t>() % (m_peers_gray.size() + 1);
- 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() << ")");
+ size_t random_index = crypto::rand<size_t>() % m_peers_gray.size();
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;