mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-31 13:14:13 +00:00
reduce exploratory selection size
This commit is contained in:
parent
7e5370fbe5
commit
13a746162a
@ -1458,25 +1458,26 @@ namespace data
|
|||||||
if (!num) return ret; // empty list
|
if (!num) return ret; // empty list
|
||||||
// collect eligible
|
// collect eligible
|
||||||
std::vector<std::shared_ptr<const RouterInfo> > 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
|
bool checkIsReal = i2p::tunnel::tunnels.GetPreciseTunnelCreationSuccessRate () < NETDB_TUNNEL_CREATION_RATE_THRESHOLD; // too low rate
|
||||||
std::lock_guard<std::mutex> l(m_RouterInfosMutex);
|
std::lock_guard<std::mutex> l(m_RouterInfosMutex);
|
||||||
for (const auto& it: m_RouterInfos)
|
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 ())))
|
(!checkIsReal || (it.second->HasProfile () && it.second->GetProfile ()->IsReal ())))
|
||||||
eligible.push_back (it.second);
|
eligible.push_back (it.second);
|
||||||
}
|
}
|
||||||
// reduce number of eligible routers if too many
|
// 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()()));
|
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
|
// sort by distance
|
||||||
IdentHash destKey = CreateRoutingKey (destination);
|
IdentHash destKey = CreateRoutingKey (destination);
|
||||||
std::map<XORMetric, std::shared_ptr<const RouterInfo> > sorted;
|
std::map<XORMetric, std::shared_ptr<const RouterInfo> > sorted;
|
||||||
for (const auto& it: eligible)
|
for (const auto& it: eligible)
|
||||||
|
if (!excluded.count (it->GetIdentHash ()))
|
||||||
sorted.emplace (destKey ^ it->GetIdentHash (), it);
|
sorted.emplace (destKey ^ it->GetIdentHash (), it);
|
||||||
// return first num closest routers
|
// return first num closest routers
|
||||||
for (const auto& it: sorted)
|
for (const auto& it: sorted)
|
||||||
|
@ -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_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 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_NUM_SEARCH_REPLY_PEER_HASHES = 16;
|
||||||
|
const size_t NETDB_MAX_EXPLORATORY_SELECTION_SIZE = 500;
|
||||||
|
|
||||||
/** function for visiting a leaseset stored in a floodfill */
|
/** function for visiting a leaseset stored in a floodfill */
|
||||||
typedef std::function<void(const IdentHash, std::shared_ptr<LeaseSet>)> LeaseSetVisitor;
|
typedef std::function<void(const IdentHash, std::shared_ptr<LeaseSet>)> LeaseSetVisitor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user