reduce exploratory selection size

This commit is contained in:
orignal 2024-05-02 21:38:51 -04:00
parent 7e5370fbe5
commit 13a746162a
2 changed files with 9 additions and 7 deletions

View File

@ -1458,25 +1458,26 @@ namespace data
if (!num) return ret; // empty list
// collect eligible
std::vector<std::shared_ptr<const RouterInfo> > 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<std::mutex> l(m_RouterInfosMutex);
for (const auto& it: m_RouterInfos)
if (!it.second->IsDeclaredFloodfill () && !excluded.count (it.first) &&
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<XORMetric, std::shared_ptr<const RouterInfo> > sorted;
for (const auto& it: eligible)
if (!excluded.count (it->GetIdentHash ()))
sorted.emplace (destKey ^ it->GetIdentHash (), it);
// return first num closest routers
for (const auto& it: sorted)

View File

@ -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<void(const IdentHash, std::shared_ptr<LeaseSet>)> LeaseSetVisitor;