mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-21 16:49:10 +01:00
manage non-reponded database requests
This commit is contained in:
parent
afd69e4afd
commit
78c06bdd22
2 changed files with 52 additions and 13 deletions
62
NetDb.cpp
62
NetDb.cpp
|
@ -153,6 +153,7 @@ namespace data
|
||||||
{
|
{
|
||||||
if (!m_IsRunning) break;
|
if (!m_IsRunning) break;
|
||||||
// if no new DatabaseStore coming, explore it
|
// if no new DatabaseStore coming, explore it
|
||||||
|
ManageRequests ();
|
||||||
auto numRouters = m_RouterInfos.size ();
|
auto numRouters = m_RouterInfos.size ();
|
||||||
Explore (numRouters < 1500 ? 5 : 1);
|
Explore (numRouters < 1500 ? 5 : 1);
|
||||||
}
|
}
|
||||||
|
@ -713,18 +714,6 @@ namespace data
|
||||||
|
|
||||||
void NetDb::Explore (int numDestinations)
|
void NetDb::Explore (int numDestinations)
|
||||||
{
|
{
|
||||||
// clean up previous exploratories
|
|
||||||
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
|
||||||
for (auto it = m_RequestedDestinations.begin (); it != m_RequestedDestinations.end ();)
|
|
||||||
{
|
|
||||||
if (it->second->IsExploratory () || ts > it->second->GetCreationTime () + 60) // no response for 1 minute
|
|
||||||
{
|
|
||||||
delete it->second;
|
|
||||||
it = m_RequestedDestinations.erase (it);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
// new requests
|
// new requests
|
||||||
auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
||||||
auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : i2p::tunnel::tunnels.GetNextOutboundTunnel ();
|
auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : i2p::tunnel::tunnels.GetNextOutboundTunnel ();
|
||||||
|
@ -918,5 +907,54 @@ namespace data
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetDb::ManageRequests ()
|
||||||
|
{
|
||||||
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
|
for (auto it = m_RequestedDestinations.begin (); it != m_RequestedDestinations.end ();)
|
||||||
|
{
|
||||||
|
auto dest = it->second;
|
||||||
|
bool done = false;
|
||||||
|
if (!dest->IsExploratory () && ts < dest->GetCreationTime () + 60) // request is worthless after 1 minute
|
||||||
|
{
|
||||||
|
if (ts > dest->GetCreationTime () + 5) // no response for 5 seconds
|
||||||
|
{
|
||||||
|
auto count = dest->GetExcludedPeers ().size ();
|
||||||
|
if (count < 7)
|
||||||
|
{
|
||||||
|
auto pool = dest->GetTunnelPool ();
|
||||||
|
auto outbound = pool ? pool->GetNextOutboundTunnel () : nullptr;
|
||||||
|
auto inbound = pool ? pool->GetNextInboundTunnel () : nullptr;
|
||||||
|
auto nextFloodfill = GetClosestFloodfill (dest->GetDestination (), dest->GetExcludedPeers ());
|
||||||
|
if (nextFloodfill && outbound && inbound)
|
||||||
|
outbound->SendTunnelDataMsg (nextFloodfill->GetIdentHash (), 0,
|
||||||
|
dest->CreateRequestMessage (nextFloodfill, inbound));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
done = true;
|
||||||
|
if (!inbound) LogPrint (eLogWarning, "No inbound tunnels");
|
||||||
|
if (!outbound) LogPrint (eLogWarning, "No outbound tunnels");
|
||||||
|
if (!nextFloodfill) LogPrint (eLogWarning, "No more floodfills");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogPrint (eLogWarning, dest->GetDestination ().ToBase64 (), " not found after 7 attempts");
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // delete previous exploratory
|
||||||
|
done = true;
|
||||||
|
|
||||||
|
if (done)
|
||||||
|
{
|
||||||
|
delete it->second;
|
||||||
|
it = m_RequestedDestinations.erase (it);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
NetDb.h
1
NetDb.h
|
@ -97,6 +97,7 @@ namespace data
|
||||||
void Explore (int numDestinations);
|
void Explore (int numDestinations);
|
||||||
void Publish ();
|
void Publish ();
|
||||||
void ManageLeaseSets ();
|
void ManageLeaseSets ();
|
||||||
|
void ManageRequests ();
|
||||||
|
|
||||||
RequestedDestination * CreateRequestedDestination (const IdentHash& dest,
|
RequestedDestination * CreateRequestedDestination (const IdentHash& dest,
|
||||||
bool isLeaseSet, bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr);
|
bool isLeaseSet, bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr);
|
||||||
|
|
Loading…
Add table
Reference in a new issue