aboutsummaryrefslogtreecommitdiff
path: root/src/p2p/net_node.inl
diff options
context:
space:
mode:
authormoneromooo <moneromoo@nowhere.nowhere.nowhere>2020-10-27 13:18:40 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2020-11-29 15:55:58 +0000
commit6c9980a55beabf8ad386156c91df13a997584fe9 (patch)
tree261e3029bcb36461de43ebe28665059f1ebb0b85 /src/p2p/net_node.inl
parentMerge pull request #7021 (diff)
downloadmonero-6c9980a55beabf8ad386156c91df13a997584fe9.tar.xz
p2p: give all hosts the same chance of being picked for connecting
even if some run more than one node
Diffstat (limited to '')
-rw-r--r--src/p2p/net_node.inl27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index f19865adb..2f47de0f0 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -1502,13 +1502,28 @@ namespace nodetool
});
}
+ auto get_host_string = [](const epee::net_utils::network_address &address) {
+#if BOOST_VERSION > 106600
+ if (address.get_type_id() == epee::net_utils::ipv6_network_address::get_type_id())
+ {
+ boost::asio::ip::address_v6 actual_ip = address.as<const epee::net_utils::ipv6_network_address>().ip();
+ if (actual_ip.is_v4_mapped())
+ {
+ boost::asio::ip::address_v4 v4ip = make_address_v4(boost::asio::ip::v4_mapped, actual_ip);
+ return epee::net_utils::ipv4_network_address(v4ip.to_uint(), 0).host_str();
+ }
+ }
+#endif
+ return address.host_str();
+ };
+ std::unordered_set<std::string> hosts_added;
std::deque<size_t> filtered;
const size_t limit = use_white_list ? 20 : std::numeric_limits<size_t>::max();
for (int step = 0; step < 2; ++step)
{
bool skip_duplicate_class_B = step == 0;
size_t idx = 0, skipped = 0;
- zone.m_peerlist.foreach (use_white_list, [&classB, &filtered, &idx, &skipped, skip_duplicate_class_B, limit, next_needed_pruning_stripe](const peerlist_entry &pe){
+ zone.m_peerlist.foreach (use_white_list, [&classB, &filtered, &idx, &skipped, skip_duplicate_class_B, limit, next_needed_pruning_stripe, &hosts_added, &get_host_string](const peerlist_entry &pe){
if (filtered.size() >= limit)
return false;
bool skip = false;
@@ -1532,6 +1547,15 @@ namespace nodetool
}
}
#endif
+
+ // consider each host once, to avoid giving undue inflence to hosts running several nodes
+ if (!skip)
+ {
+ const auto i = hosts_added.find(get_host_string(pe.adr));
+ if (i != hosts_added.end())
+ skip = true;
+ }
+
if (skip)
++skipped;
else if (next_needed_pruning_stripe == 0 || pe.pruning_seed == 0)
@@ -1539,6 +1563,7 @@ namespace nodetool
else if (next_needed_pruning_stripe == tools::get_pruning_stripe(pe.pruning_seed))
filtered.push_front(idx);
++idx;
+ hosts_added.insert(get_host_string(pe.adr));
return true;
});
if (skipped == 0 || !filtered.empty())