mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
explore 5 addresses at the time
This commit is contained in:
parent
d6b97670c4
commit
566909a50c
37
NetDb.cpp
37
NetDb.cpp
|
@ -122,7 +122,10 @@ namespace data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // if no new DatabaseStore coming, explore it
|
else // if no new DatabaseStore coming, explore it
|
||||||
Explore ();
|
{
|
||||||
|
auto numRouters = m_RouterInfos.size ();
|
||||||
|
Explore (numRouters < 1500 ? 5 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
if (ts - lastSave >= 60) // save routers and validate subscriptions every minute
|
if (ts - lastSave >= 60) // save routers and validate subscriptions every minute
|
||||||
|
@ -532,23 +535,29 @@ namespace data
|
||||||
i2p::DeleteI2NPMessage (msg);
|
i2p::DeleteI2NPMessage (msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDb::Explore ()
|
void NetDb::Explore (int numDestinations)
|
||||||
{
|
{
|
||||||
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
|
||||||
uint8_t randomHash[32];
|
|
||||||
rnd.GenerateBlock (randomHash, 32);
|
|
||||||
RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true);
|
|
||||||
auto floodfill = GetClosestFloodfill (randomHash, dest->GetExcludedPeers ());
|
|
||||||
if (floodfill)
|
|
||||||
{
|
|
||||||
LogPrint ("Exploring new routers ...");
|
|
||||||
auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
||||||
auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : nullptr;
|
auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : nullptr;
|
||||||
auto inbound = exploratoryPool ? exploratoryPool->GetNextInboundTunnel () : nullptr;
|
auto inbound = exploratoryPool ? exploratoryPool->GetNextInboundTunnel () : nullptr;
|
||||||
if (outbound && inbound)
|
bool throughTunnels = outbound && inbound;
|
||||||
|
|
||||||
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
||||||
|
uint8_t randomHash[32];
|
||||||
|
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
||||||
|
std::set<const RouterInfo *> floodfills;
|
||||||
|
LogPrint ("Exploring new ", numDestinations, " routers ...");
|
||||||
|
for (int i = 0; i < numDestinations; i++)
|
||||||
|
{
|
||||||
|
rnd.GenerateBlock (randomHash, 32);
|
||||||
|
RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true);
|
||||||
|
auto floodfill = GetClosestFloodfill (randomHash, dest->GetExcludedPeers ());
|
||||||
|
if (floodfill && !floodfills.count (floodfill)) // request floodfill only once
|
||||||
|
{
|
||||||
|
floodfills.insert (floodfill);
|
||||||
|
if (throughTunnels)
|
||||||
{
|
{
|
||||||
dest->SetLastOutboundTunnel (outbound);
|
dest->SetLastOutboundTunnel (outbound);
|
||||||
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
|
||||||
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
||||||
{
|
{
|
||||||
i2p::tunnel::eDeliveryTypeRouter,
|
i2p::tunnel::eDeliveryTypeRouter,
|
||||||
|
@ -561,7 +570,6 @@ namespace data
|
||||||
floodfill->GetIdentHash (), 0,
|
floodfill->GetIdentHash (), 0,
|
||||||
dest->CreateRequestMessage (floodfill, inbound) // explore
|
dest->CreateRequestMessage (floodfill, inbound) // explore
|
||||||
});
|
});
|
||||||
outbound->SendTunnelDataMsg (msgs);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -573,6 +581,9 @@ namespace data
|
||||||
else
|
else
|
||||||
DeleteRequestedDestination (dest);
|
DeleteRequestedDestination (dest);
|
||||||
}
|
}
|
||||||
|
if (throughTunnels && msgs.size () > 0)
|
||||||
|
outbound->SendTunnelDataMsg (msgs);
|
||||||
|
}
|
||||||
|
|
||||||
void NetDb::Publish ()
|
void NetDb::Publish ()
|
||||||
{
|
{
|
||||||
|
|
2
NetDb.h
2
NetDb.h
|
@ -91,7 +91,7 @@ namespace data
|
||||||
void Load (const char * directory);
|
void Load (const char * directory);
|
||||||
void SaveUpdated (const char * directory);
|
void SaveUpdated (const char * directory);
|
||||||
void Run (); // exploratory thread
|
void Run (); // exploratory thread
|
||||||
void Explore ();
|
void Explore (int numDestinations);
|
||||||
void Publish ();
|
void Publish ();
|
||||||
void ValidateSubscriptions ();
|
void ValidateSubscriptions ();
|
||||||
const RouterInfo * GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
|
const RouterInfo * GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
|
||||||
|
|
Loading…
Reference in a new issue