Browse Source

manage non-reponded database requests

pull/120/head
orignal 10 years ago
parent
commit
78c06bdd22
  1. 62
      NetDb.cpp
  2. 3
      NetDb.h

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++;
}
}
} }
} }

3
NetDb.h

@ -94,9 +94,10 @@ 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 (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…
Cancel
Save