|
|
@ -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,46 +535,54 @@ namespace data |
|
|
|
i2p::DeleteI2NPMessage (msg); |
|
|
|
i2p::DeleteI2NPMessage (msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NetDb::Explore () |
|
|
|
void NetDb::Explore (int numDestinations) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool (); |
|
|
|
|
|
|
|
auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : nullptr; |
|
|
|
|
|
|
|
auto inbound = exploratoryPool ? exploratoryPool->GetNextInboundTunnel () : nullptr; |
|
|
|
|
|
|
|
bool throughTunnels = outbound && inbound; |
|
|
|
|
|
|
|
|
|
|
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); |
|
|
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); |
|
|
|
uint8_t randomHash[32]; |
|
|
|
uint8_t randomHash[32]; |
|
|
|
rnd.GenerateBlock (randomHash, 32); |
|
|
|
std::vector<i2p::tunnel::TunnelMessageBlock> msgs; |
|
|
|
RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true); |
|
|
|
std::set<const RouterInfo *> floodfills; |
|
|
|
auto floodfill = GetClosestFloodfill (randomHash, dest->GetExcludedPeers ()); |
|
|
|
LogPrint ("Exploring new ", numDestinations, " routers ..."); |
|
|
|
if (floodfill) |
|
|
|
for (int i = 0; i < numDestinations; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Exploring new routers ..."); |
|
|
|
rnd.GenerateBlock (randomHash, 32); |
|
|
|
auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool (); |
|
|
|
RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true); |
|
|
|
auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : nullptr; |
|
|
|
auto floodfill = GetClosestFloodfill (randomHash, dest->GetExcludedPeers ()); |
|
|
|
auto inbound = exploratoryPool ? exploratoryPool->GetNextInboundTunnel () : nullptr; |
|
|
|
if (floodfill && !floodfills.count (floodfill)) // request floodfill only once
|
|
|
|
if (outbound && inbound) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
dest->SetLastOutboundTunnel (outbound); |
|
|
|
floodfills.insert (floodfill); |
|
|
|
std::vector<i2p::tunnel::TunnelMessageBlock> msgs; |
|
|
|
if (throughTunnels) |
|
|
|
msgs.push_back (i2p::tunnel::TunnelMessageBlock |
|
|
|
{ |
|
|
|
{ |
|
|
|
dest->SetLastOutboundTunnel (outbound); |
|
|
|
i2p::tunnel::eDeliveryTypeRouter, |
|
|
|
msgs.push_back (i2p::tunnel::TunnelMessageBlock |
|
|
|
floodfill->GetIdentHash (), 0, |
|
|
|
{ |
|
|
|
CreateDatabaseStoreMsg () // tell floodfill about us
|
|
|
|
i2p::tunnel::eDeliveryTypeRouter, |
|
|
|
}); |
|
|
|
floodfill->GetIdentHash (), 0, |
|
|
|
msgs.push_back (i2p::tunnel::TunnelMessageBlock |
|
|
|
CreateDatabaseStoreMsg () // tell floodfill about us
|
|
|
|
{ |
|
|
|
}); |
|
|
|
i2p::tunnel::eDeliveryTypeRouter, |
|
|
|
msgs.push_back (i2p::tunnel::TunnelMessageBlock |
|
|
|
floodfill->GetIdentHash (), 0, |
|
|
|
{ |
|
|
|
dest->CreateRequestMessage (floodfill, inbound) // explore
|
|
|
|
i2p::tunnel::eDeliveryTypeRouter, |
|
|
|
}); |
|
|
|
floodfill->GetIdentHash (), 0, |
|
|
|
outbound->SendTunnelDataMsg (msgs); |
|
|
|
dest->CreateRequestMessage (floodfill, inbound) // explore
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
dest->SetLastOutboundTunnel (nullptr); |
|
|
|
|
|
|
|
dest->SetLastReplyTunnel (nullptr); |
|
|
|
|
|
|
|
i2p::transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
DeleteRequestedDestination (dest); |
|
|
|
dest->SetLastOutboundTunnel (nullptr); |
|
|
|
|
|
|
|
dest->SetLastReplyTunnel (nullptr); |
|
|
|
|
|
|
|
i2p::transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
if (throughTunnels && msgs.size () > 0) |
|
|
|
DeleteRequestedDestination (dest); |
|
|
|
outbound->SendTunnelDataMsg (msgs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NetDb::Publish () |
|
|
|
void NetDb::Publish () |
|
|
|