diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp index b946c49c..f1d221ce 100644 --- a/libi2pd/NetDb.cpp +++ b/libi2pd/NetDb.cpp @@ -1458,26 +1458,27 @@ namespace data if (!num) return ret; // empty list // collect eligible std::vector > eligible; - eligible.reserve (NETDB_NUM_ROUTERS_THRESHOLD); + eligible.reserve (NETDB_MAX_EXPLORATORY_SELECTION_SIZE); { bool checkIsReal = i2p::tunnel::tunnels.GetPreciseTunnelCreationSuccessRate () < NETDB_TUNNEL_CREATION_RATE_THRESHOLD; // too low rate std::lock_guard l(m_RouterInfosMutex); for (const auto& it: m_RouterInfos) - if (!it.second->IsDeclaredFloodfill () && !excluded.count (it.first) && - (!checkIsReal || (it.second->HasProfile () && it.second->GetProfile ()->IsReal ()))) - eligible.push_back (it.second); + if (!it.second->IsDeclaredFloodfill () && + (!checkIsReal || (it.second->HasProfile () && it.second->GetProfile ()->IsReal ()))) + eligible.push_back (it.second); } // reduce number of eligible routers if too many - if (eligible.size () > NETDB_NUM_ROUTERS_THRESHOLD) + if (eligible.size () > NETDB_MAX_EXPLORATORY_SELECTION_SIZE) { std::shuffle (eligible.begin(), eligible.end(), std::mt19937(std::random_device()())); - eligible.resize (NETDB_NUM_ROUTERS_THRESHOLD); + eligible.resize (NETDB_MAX_EXPLORATORY_SELECTION_SIZE); } // sort by distance IdentHash destKey = CreateRoutingKey (destination); std::map > sorted; for (const auto& it: eligible) - sorted.emplace (destKey ^ it->GetIdentHash (), it); + if (!excluded.count (it->GetIdentHash ())) + sorted.emplace (destKey ^ it->GetIdentHash (), it); // return first num closest routers for (const auto& it: sorted) { diff --git a/libi2pd/NetDb.hpp b/libi2pd/NetDb.hpp index d3c7b451..dedced61 100644 --- a/libi2pd/NetDb.hpp +++ b/libi2pd/NetDb.hpp @@ -54,6 +54,7 @@ namespace data const int NETDB_MIN_FLOODFILL_VERSION = MAKE_VERSION_NUMBER(0, 9, 51); // 0.9.51 const int NETDB_MIN_SHORT_TUNNEL_BUILD_VERSION = MAKE_VERSION_NUMBER(0, 9, 51); // 0.9.51 const size_t NETDB_MAX_NUM_SEARCH_REPLY_PEER_HASHES = 16; + const size_t NETDB_MAX_EXPLORATORY_SELECTION_SIZE = 500; /** function for visiting a leaseset stored in a floodfill */ typedef std::function)> LeaseSetVisitor;