mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
reduce CPU usage
This commit is contained in:
parent
b6ec0a3526
commit
20e43951e5
26
NetDb.cpp
26
NetDb.cpp
@ -732,28 +732,13 @@ namespace data
|
||||
if (!replyMsg)
|
||||
{
|
||||
LogPrint ("Requested ", key, " not found. ", numExcluded, " excluded");
|
||||
std::vector<IdentHash> routers;
|
||||
if (numExcluded > 0)
|
||||
{
|
||||
std::set<IdentHash> excludedRouters;
|
||||
for (int i = 0; i < numExcluded; i++)
|
||||
{
|
||||
excludedRouters.insert (excluded);
|
||||
excluded += 32;
|
||||
}
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
auto floodfill = GetClosestFloodfill (ident, excludedRouters);
|
||||
if (floodfill)
|
||||
{
|
||||
routers.push_back (floodfill->GetIdentHash ());
|
||||
excludedRouters.insert (floodfill->GetIdentHash ());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
routers = GetClosestFloodfills (ident, 3);
|
||||
replyMsg = CreateDatabaseSearchReply (ident, routers);
|
||||
replyMsg = CreateDatabaseSearchReply (ident, GetClosestFloodfills (ident, 3, excludedRouters));
|
||||
}
|
||||
}
|
||||
|
||||
@ -955,7 +940,8 @@ namespace data
|
||||
return r;
|
||||
}
|
||||
|
||||
std::vector<IdentHash> NetDb::GetClosestFloodfills (const IdentHash& destination, size_t num) const
|
||||
std::vector<IdentHash> NetDb::GetClosestFloodfills (const IdentHash& destination, size_t num,
|
||||
std::set<IdentHash>& excluded) const
|
||||
{
|
||||
struct Sorted
|
||||
{
|
||||
@ -990,9 +976,13 @@ namespace data
|
||||
{
|
||||
if (i < num)
|
||||
{
|
||||
res.push_back (it.r->GetIdentHash ());
|
||||
auto& ident = it.r->GetIdentHash ();
|
||||
if (!excluded.count (ident))
|
||||
{
|
||||
res.push_back (ident);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
3
NetDb.h
3
NetDb.h
@ -51,7 +51,8 @@ namespace data
|
||||
std::shared_ptr<const RouterInfo> GetRandomPeerTestRouter () const;
|
||||
std::shared_ptr<const RouterInfo> GetRandomIntroducer () const;
|
||||
std::shared_ptr<const RouterInfo> GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
|
||||
std::vector<IdentHash> GetClosestFloodfills (const IdentHash& destination, size_t num) const;
|
||||
std::vector<IdentHash> GetClosestFloodfills (const IdentHash& destination, size_t num,
|
||||
std::set<IdentHash>& excluded) const;
|
||||
std::shared_ptr<const RouterInfo> GetClosestNonFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
|
||||
void SetUnreachable (const IdentHash& ident, bool unreachable);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user