mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
handle exploratory lookups
This commit is contained in:
parent
7f75d250c7
commit
c5a3832eae
105
NetDb.cpp
105
NetDb.cpp
@ -649,6 +649,7 @@ namespace data
|
|||||||
key[l] = 0;
|
key[l] = 0;
|
||||||
uint8_t flag = buf[64];
|
uint8_t flag = buf[64];
|
||||||
LogPrint ("DatabaseLookup for ", key, " recieved flags=", (int)flag);
|
LogPrint ("DatabaseLookup for ", key, " recieved flags=", (int)flag);
|
||||||
|
uint8_t lookupType = flag & DATABASE_LOOKUP_TYPE_FLAGS_MASK;
|
||||||
uint8_t * excluded = buf + 65;
|
uint8_t * excluded = buf + 65;
|
||||||
uint32_t replyTunnelID = 0;
|
uint32_t replyTunnelID = 0;
|
||||||
if (flag & DATABASE_LOOKUP_DELIVERY_FLAG) //reply to tunnel
|
if (flag & DATABASE_LOOKUP_DELIVERY_FLAG) //reply to tunnel
|
||||||
@ -663,49 +664,72 @@ namespace data
|
|||||||
LogPrint ("Number of excluded peers", numExcluded, " exceeds 512");
|
LogPrint ("Number of excluded peers", numExcluded, " exceeds 512");
|
||||||
numExcluded = 0; // TODO:
|
numExcluded = 0; // TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
I2NPMessage * replyMsg = nullptr;
|
|
||||||
|
|
||||||
auto router = FindRouter (buf);
|
|
||||||
if (router)
|
|
||||||
{
|
|
||||||
LogPrint ("Requested RouterInfo ", key, " found");
|
|
||||||
router->LoadBuffer ();
|
|
||||||
if (router->GetBuffer ())
|
|
||||||
replyMsg = CreateDatabaseStoreMsg (router.get ());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!replyMsg)
|
I2NPMessage * replyMsg = nullptr;
|
||||||
|
if (lookupType == DATABASE_LOOKUP_TYPE_EXPLORATORY_LOOKUP)
|
||||||
{
|
{
|
||||||
auto leaseSet = FindLeaseSet (buf);
|
LogPrint ("Exploratory close to ", key, " ", numExcluded, " excluded");
|
||||||
if (leaseSet) // we don't send back our LeaseSets
|
|
||||||
{
|
|
||||||
LogPrint ("Requested LeaseSet ", key, " found");
|
|
||||||
replyMsg = CreateDatabaseStoreMsg (leaseSet.get ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!replyMsg)
|
|
||||||
{
|
|
||||||
LogPrint ("Requested ", key, " not found. ", numExcluded, " excluded");
|
|
||||||
std::set<IdentHash> excludedRouters;
|
std::set<IdentHash> excludedRouters;
|
||||||
for (int i = 0; i < numExcluded; i++)
|
for (int i = 0; i < numExcluded; i++)
|
||||||
{
|
{
|
||||||
// TODO: check for all zeroes (exploratory)
|
|
||||||
excludedRouters.insert (excluded);
|
excludedRouters.insert (excluded);
|
||||||
excluded += 32;
|
excluded += 32;
|
||||||
}
|
}
|
||||||
std::vector<IdentHash> routers;
|
std::vector<IdentHash> routers;
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
auto floodfill = GetClosestFloodfill (buf, excludedRouters);
|
auto r = GetClosestNonFloodfill (buf, excludedRouters);
|
||||||
if (floodfill)
|
if (r)
|
||||||
routers.push_back (floodfill->GetIdentHash ());
|
{
|
||||||
|
routers.push_back (r->GetIdentHash ());
|
||||||
|
excludedRouters.insert (r->GetIdentHash ());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
replyMsg = CreateDatabaseSearchReply (buf, routers);
|
replyMsg = CreateDatabaseSearchReply (buf, routers);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
excluded += numExcluded*32; // we don't care about exluded
|
{
|
||||||
|
auto router = FindRouter (buf);
|
||||||
|
if (router)
|
||||||
|
{
|
||||||
|
LogPrint ("Requested RouterInfo ", key, " found");
|
||||||
|
router->LoadBuffer ();
|
||||||
|
if (router->GetBuffer ())
|
||||||
|
replyMsg = CreateDatabaseStoreMsg (router.get ());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!replyMsg)
|
||||||
|
{
|
||||||
|
auto leaseSet = FindLeaseSet (buf);
|
||||||
|
if (leaseSet) // we don't send back our LeaseSets
|
||||||
|
{
|
||||||
|
LogPrint ("Requested LeaseSet ", key, " found");
|
||||||
|
replyMsg = CreateDatabaseStoreMsg (leaseSet.get ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!replyMsg)
|
||||||
|
{
|
||||||
|
LogPrint ("Requested ", key, " not found. ", numExcluded, " excluded");
|
||||||
|
std::set<IdentHash> excludedRouters;
|
||||||
|
for (int i = 0; i < numExcluded; i++)
|
||||||
|
{
|
||||||
|
excludedRouters.insert (excluded);
|
||||||
|
excluded += 32;
|
||||||
|
}
|
||||||
|
std::vector<IdentHash> routers;
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
auto floodfill = GetClosestFloodfill (buf, excludedRouters);
|
||||||
|
if (floodfill)
|
||||||
|
{
|
||||||
|
routers.push_back (floodfill->GetIdentHash ());
|
||||||
|
excludedRouters.insert (floodfill->GetIdentHash ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
replyMsg = CreateDatabaseSearchReply (buf, routers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (replyMsg)
|
if (replyMsg)
|
||||||
{
|
{
|
||||||
if (replyTunnelID)
|
if (replyTunnelID)
|
||||||
@ -903,6 +927,29 @@ namespace data
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<const RouterInfo> NetDb::GetClosestNonFloodfill (const IdentHash& destination,
|
||||||
|
const std::set<IdentHash>& excluded) const
|
||||||
|
{
|
||||||
|
std::shared_ptr<const RouterInfo> r;
|
||||||
|
XORMetric minMetric;
|
||||||
|
IdentHash destKey = CreateRoutingKey (destination);
|
||||||
|
minMetric.SetMax ();
|
||||||
|
// must be called from NetDb thread only
|
||||||
|
for (auto it: m_RouterInfos)
|
||||||
|
{
|
||||||
|
if (!it.second->IsFloodfill () && !excluded.count (it.first))
|
||||||
|
{
|
||||||
|
XORMetric m = destKey ^ it.first;
|
||||||
|
if (m < minMetric)
|
||||||
|
{
|
||||||
|
minMetric = m;
|
||||||
|
r = it.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
void NetDb::ManageLeaseSets ()
|
void NetDb::ManageLeaseSets ()
|
||||||
{
|
{
|
||||||
for (auto it = m_LeaseSets.begin (); it != m_LeaseSets.end ();)
|
for (auto it = m_LeaseSets.begin (); it != m_LeaseSets.end ();)
|
||||||
|
1
NetDb.h
1
NetDb.h
@ -80,6 +80,7 @@ namespace data
|
|||||||
std::shared_ptr<const RouterInfo> GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const;
|
std::shared_ptr<const RouterInfo> GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const;
|
||||||
std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const;
|
std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const;
|
||||||
std::shared_ptr<const RouterInfo> GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
|
std::shared_ptr<const RouterInfo> GetClosestFloodfill (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);
|
||||||
|
|
||||||
void PostI2NPMsg (I2NPMessage * msg);
|
void PostI2NPMsg (I2NPMessage * msg);
|
||||||
|
Loading…
Reference in New Issue
Block a user