aboutsummaryrefslogtreecommitdiff
path: root/src/p2p
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-03-03 14:29:23 +0200
committerRiccardo Spagni <ric@spagni.net>2017-03-03 14:29:23 +0200
commit11f8e0d33f4a2c0ed854ab1e486bda23a719aa64 (patch)
treef6940f35f7fddaf410c1f11b6c738ca377f314a1 /src/p2p
parentMerge pull request #1814 (diff)
parentMake gray peer selection uniform (diff)
downloadmonero-11f8e0d33f4a2c0ed854ab1e486bda23a719aa64.tar.xz
Merge pull request #1687
1a7e18bf Make gray peer selection uniform (Miguel Herranz) f3be9991 Make get_random_gray_peer distribution uniform (Miguel Herranz)
Diffstat (limited to 'src/p2p')
-rw-r--r--src/p2p/net_node.inl9
-rw-r--r--src/p2p/net_peerlist.h7
2 files changed, 10 insertions, 6 deletions
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index c40bd8c5d..99c4e9282 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -1023,7 +1023,14 @@ namespace nodetool
while(rand_count < (max_random_index+1)*3 && try_count < 10 && !m_net_server.is_stop_signal_sent())
{
++rand_count;
- size_t random_index = get_random_index_with_fixed_probability(max_random_index);
+ size_t random_index;
+
+ if (use_white_list) {
+ random_index = get_random_index_with_fixed_probability(max_random_index);
+ } else {
+ random_index = crypto::rand<size_t>() % m_peerlist.get_gray_peers_count();
+ }
+
CHECK_AND_ASSERT_MES(random_index < local_peers_count, false, "random_starter_index < peers_local.size() failed!!");
if(tried_peers.count(random_index))
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;