mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
send close floodfills only in DatabaseSearchReply
This commit is contained in:
parent
fa67e90767
commit
ecfdc377ec
11
NetDb.cpp
11
NetDb.cpp
@ -677,7 +677,7 @@ namespace data
|
|||||||
excludedRouters.insert (excluded);
|
excludedRouters.insert (excluded);
|
||||||
excluded += 32;
|
excluded += 32;
|
||||||
}
|
}
|
||||||
replyMsg = CreateDatabaseSearchReply (ident, GetClosestFloodfills (ident, 3, excludedRouters));
|
replyMsg = CreateDatabaseSearchReply (ident, GetClosestFloodfills (ident, 3, excludedRouters, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -884,7 +884,7 @@ namespace data
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<IdentHash> NetDb::GetClosestFloodfills (const IdentHash& destination, size_t num,
|
std::vector<IdentHash> NetDb::GetClosestFloodfills (const IdentHash& destination, size_t num,
|
||||||
std::set<IdentHash>& excluded) const
|
std::set<IdentHash>& excluded, bool closeThanUsOnly) const
|
||||||
{
|
{
|
||||||
struct Sorted
|
struct Sorted
|
||||||
{
|
{
|
||||||
@ -895,6 +895,8 @@ namespace data
|
|||||||
|
|
||||||
std::set<Sorted> sorted;
|
std::set<Sorted> sorted;
|
||||||
IdentHash destKey = CreateRoutingKey (destination);
|
IdentHash destKey = CreateRoutingKey (destination);
|
||||||
|
XORMetric ourMetric;
|
||||||
|
if (closeThanUsOnly) ourMetric = destKey ^ i2p::context.GetIdentHash ();
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> l(m_FloodfillsMutex);
|
std::unique_lock<std::mutex> l(m_FloodfillsMutex);
|
||||||
for (auto it: m_Floodfills)
|
for (auto it: m_Floodfills)
|
||||||
@ -902,6 +904,7 @@ namespace data
|
|||||||
if (!it->IsUnreachable ())
|
if (!it->IsUnreachable ())
|
||||||
{
|
{
|
||||||
XORMetric m = destKey ^ it->GetIdentHash ();
|
XORMetric m = destKey ^ it->GetIdentHash ();
|
||||||
|
if (closeThanUsOnly && ourMetric < m) continue;
|
||||||
if (sorted.size () < num)
|
if (sorted.size () < num)
|
||||||
sorted.insert ({it, m});
|
sorted.insert ({it, m});
|
||||||
else if (m < sorted.rbegin ()->metric)
|
else if (m < sorted.rbegin ()->metric)
|
||||||
@ -960,9 +963,9 @@ namespace data
|
|||||||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
for (auto it = m_LeaseSets.begin (); it != m_LeaseSets.end ();)
|
for (auto it = m_LeaseSets.begin (); it != m_LeaseSets.end ();)
|
||||||
{
|
{
|
||||||
if (ts > it->second->GetExpirationTime ())
|
if (ts > it->second->GetExpirationTime () - LEASE_ENDDATE_THRESHOLD)
|
||||||
{
|
{
|
||||||
LogPrint (eLogWarning, "NetDb: LeaseSet ", it->second->GetIdentHash ().ToBase64 (), " expired");
|
LogPrint (eLogInfo, "NetDb: LeaseSet ", it->second->GetIdentHash ().ToBase64 (), " expired");
|
||||||
it = m_LeaseSets.erase (it);
|
it = m_LeaseSets.erase (it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
2
NetDb.h
2
NetDb.h
@ -60,7 +60,7 @@ namespace data
|
|||||||
std::shared_ptr<const RouterInfo> GetRandomIntroducer () const;
|
std::shared_ptr<const RouterInfo> GetRandomIntroducer () const;
|
||||||
std::shared_ptr<const RouterInfo> GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded, bool closeThanUsOnly = false) const;
|
std::shared_ptr<const RouterInfo> GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded, bool closeThanUsOnly = false) const;
|
||||||
std::vector<IdentHash> GetClosestFloodfills (const IdentHash& destination, size_t num,
|
std::vector<IdentHash> GetClosestFloodfills (const IdentHash& destination, size_t num,
|
||||||
std::set<IdentHash>& excluded) const;
|
std::set<IdentHash>& excluded, bool closeThanUsOnly = false) const;
|
||||||
std::shared_ptr<const RouterInfo> GetClosestNonFloodfill (const IdentHash& destination, const 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);
|
void SetUnreachable (const IdentHash& ident, bool unreachable);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user