mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
cache complete request for a while and not send the same request again
This commit is contained in:
parent
8a20d3219b
commit
396aa6944d
@ -780,7 +780,7 @@ namespace data
|
|||||||
auto dest = m_Requests.CreateRequest (destination, false, direct, requestComplete); // non-exploratory
|
auto dest = m_Requests.CreateRequest (destination, false, direct, requestComplete); // non-exploratory
|
||||||
if (!dest)
|
if (!dest)
|
||||||
{
|
{
|
||||||
LogPrint (eLogWarning, "NetDb: Destination ", destination.ToBase64(), " is requested already");
|
LogPrint (eLogWarning, "NetDb: Destination ", destination.ToBase64(), " is requested already or cached");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1000,7 +1000,7 @@ namespace data
|
|||||||
LogPrint (eLogDebug, "NetDb: DatabaseSearchReply for ", key, " num=", num);
|
LogPrint (eLogDebug, "NetDb: DatabaseSearchReply for ", key, " num=", num);
|
||||||
IdentHash ident (buf);
|
IdentHash ident (buf);
|
||||||
auto dest = m_Requests.FindRequest (ident);
|
auto dest = m_Requests.FindRequest (ident);
|
||||||
if (dest)
|
if (dest && dest->IsActive ())
|
||||||
{
|
{
|
||||||
if (!dest->IsExploratory () && (num > 0 || dest->GetNumExcludedPeers () < 3)) // before 3-rd attempt might be just bad luck
|
if (!dest->IsExploratory () && (num > 0 || dest->GetNumExcludedPeers () < 3)) // before 3-rd attempt might be just bad luck
|
||||||
// try to send next requests
|
// try to send next requests
|
||||||
|
@ -80,6 +80,8 @@ namespace data
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RequestedDestination::Success (std::shared_ptr<RouterInfo> r)
|
void RequestedDestination::Success (std::shared_ptr<RouterInfo> r)
|
||||||
|
{
|
||||||
|
if (m_IsActive)
|
||||||
{
|
{
|
||||||
m_IsActive = false;
|
m_IsActive = false;
|
||||||
if (m_RequestComplete)
|
if (m_RequestComplete)
|
||||||
@ -88,8 +90,11 @@ namespace data
|
|||||||
m_RequestComplete = nullptr;
|
m_RequestComplete = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RequestedDestination::Fail ()
|
void RequestedDestination::Fail ()
|
||||||
|
{
|
||||||
|
if (m_IsActive)
|
||||||
{
|
{
|
||||||
m_IsActive = false;
|
m_IsActive = false;
|
||||||
if (m_RequestComplete)
|
if (m_RequestComplete)
|
||||||
@ -98,6 +103,7 @@ namespace data
|
|||||||
m_RequestComplete = nullptr;
|
m_RequestComplete = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NetDbRequests::Start ()
|
void NetDbRequests::Start ()
|
||||||
{
|
{
|
||||||
@ -152,7 +158,9 @@ namespace data
|
|||||||
if (it != m_RequestedDestinations.end ())
|
if (it != m_RequestedDestinations.end ())
|
||||||
{
|
{
|
||||||
request = it->second;
|
request = it->second;
|
||||||
|
if (request->IsExploratory ())
|
||||||
m_RequestedDestinations.erase (it);
|
m_RequestedDestinations.erase (it);
|
||||||
|
// otherwise cache for a while
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (request)
|
if (request)
|
||||||
@ -180,24 +188,37 @@ namespace data
|
|||||||
for (auto it = m_RequestedDestinations.begin (); it != m_RequestedDestinations.end ();)
|
for (auto it = m_RequestedDestinations.begin (); it != m_RequestedDestinations.end ();)
|
||||||
{
|
{
|
||||||
auto& dest = it->second;
|
auto& dest = it->second;
|
||||||
bool done = false;
|
if (dest->IsActive () || ts < dest->GetCreationTime () + REQUEST_CACHE_TIME)
|
||||||
|
{
|
||||||
if (!dest->IsExploratory ())
|
if (!dest->IsExploratory ())
|
||||||
{
|
{
|
||||||
if (ts < dest->GetCreationTime () + MAX_REQUEST_TIME) // request becomes worthless
|
// regular request
|
||||||
|
bool done = false;
|
||||||
|
if (ts < dest->GetCreationTime () + MAX_REQUEST_TIME)
|
||||||
{
|
{
|
||||||
if (ts > dest->GetLastRequestTime () + MIN_REQUEST_TIME) // try next floodfill if no response after min interval
|
if (ts > dest->GetLastRequestTime () + MIN_REQUEST_TIME) // try next floodfill if no response after min interval
|
||||||
done = !SendNextRequest (dest);
|
done = !SendNextRequest (dest);
|
||||||
}
|
}
|
||||||
else // delete obsolete request
|
else // request is expired
|
||||||
done = true;
|
done = true;
|
||||||
}
|
|
||||||
else if (ts >= dest->GetCreationTime () + MAX_EXPLORATORY_REQUEST_TIME)
|
|
||||||
done = true;
|
|
||||||
|
|
||||||
if (done)
|
if (done)
|
||||||
it = m_RequestedDestinations.erase (it);
|
dest->Fail ();
|
||||||
|
it++;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
++it;
|
{
|
||||||
|
// exploratory
|
||||||
|
if (ts >= dest->GetCreationTime () + MAX_EXPLORATORY_REQUEST_TIME)
|
||||||
|
{
|
||||||
|
dest->Fail ();
|
||||||
|
it = m_RequestedDestinations.erase (it); // delete expired exploratory request right a way
|
||||||
|
}
|
||||||
|
else
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
it = m_RequestedDestinations.erase (it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ namespace data
|
|||||||
const uint64_t MIN_REQUEST_TIME = 5; // in seconds
|
const uint64_t MIN_REQUEST_TIME = 5; // in seconds
|
||||||
const uint64_t MAX_REQUEST_TIME = MAX_NUM_REQUEST_ATTEMPTS * (MIN_REQUEST_TIME + MANAGE_REQUESTS_INTERVAL);
|
const uint64_t MAX_REQUEST_TIME = MAX_NUM_REQUEST_ATTEMPTS * (MIN_REQUEST_TIME + MANAGE_REQUESTS_INTERVAL);
|
||||||
const uint64_t MAX_EXPLORATORY_REQUEST_TIME = 30; // in seconds
|
const uint64_t MAX_EXPLORATORY_REQUEST_TIME = 30; // in seconds
|
||||||
|
const uint64_t REQUEST_CACHE_TIME = MAX_REQUEST_TIME + 40; // in seconds
|
||||||
|
|
||||||
class RequestedDestination
|
class RequestedDestination
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user