From 78c06bdd229d9901507c3a9c840359036ec3720c Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 24 Dec 2014 11:20:38 -0500 Subject: [PATCH] manage non-reponded database requests --- NetDb.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++----------- NetDb.h | 3 ++- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/NetDb.cpp b/NetDb.cpp index 3aeb79e2..8848f692 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -153,6 +153,7 @@ namespace data { if (!m_IsRunning) break; // if no new DatabaseStore coming, explore it + ManageRequests (); auto numRouters = m_RouterInfos.size (); Explore (numRouters < 1500 ? 5 : 1); } @@ -713,18 +714,6 @@ namespace data 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 auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool (); auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : i2p::tunnel::tunnels.GetNextOutboundTunnel (); @@ -918,5 +907,54 @@ namespace data 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++; + } + } } } diff --git a/NetDb.h b/NetDb.h index 93dab40d..ae21e6ce 100644 --- a/NetDb.h +++ b/NetDb.h @@ -94,9 +94,10 @@ namespace data void Load (const char * directory); void SaveUpdated (const char * directory); void Run (); // exploratory thread - void Explore (int numDestinations); + void Explore (int numDestinations); void Publish (); void ManageLeaseSets (); + void ManageRequests (); RequestedDestination * CreateRequestedDestination (const IdentHash& dest, bool isLeaseSet, bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr);