mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-19 01:09:58 +00:00
memory pool for requested destination. Reduced request attaempts to 5
This commit is contained in:
parent
b91f5a7430
commit
d0cf385f4b
@ -107,11 +107,13 @@ namespace data
|
|||||||
|
|
||||||
void NetDbRequests::Start ()
|
void NetDbRequests::Start ()
|
||||||
{
|
{
|
||||||
|
m_LastPoolCleanUpTime = i2p::util::GetSecondsSinceEpoch ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDbRequests::Stop ()
|
void NetDbRequests::Stop ()
|
||||||
{
|
{
|
||||||
m_RequestedDestinations.clear ();
|
m_RequestedDestinations.clear ();
|
||||||
|
m_RequestedDestinationsPool.CleanUpMt ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -119,7 +121,7 @@ namespace data
|
|||||||
bool isExploratory, bool direct, RequestedDestination::RequestComplete requestComplete)
|
bool isExploratory, bool direct, RequestedDestination::RequestComplete requestComplete)
|
||||||
{
|
{
|
||||||
// request RouterInfo directly
|
// request RouterInfo directly
|
||||||
auto dest = std::make_shared<RequestedDestination> (destination, isExploratory, direct);
|
auto dest = m_RequestedDestinationsPool.AcquireSharedMt (destination, isExploratory, direct);
|
||||||
dest->SetRequestComplete (requestComplete);
|
dest->SetRequestComplete (requestComplete);
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
|
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
|
||||||
@ -182,6 +184,11 @@ namespace data
|
|||||||
void NetDbRequests::ManageRequests ()
|
void NetDbRequests::ManageRequests ()
|
||||||
{
|
{
|
||||||
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
|
if (ts > m_LastPoolCleanUpTime + REQUESTED_DESTINATIONS_POOL_CLEANUP_INTERVAL)
|
||||||
|
{
|
||||||
|
m_RequestedDestinationsPool.CleanUpMt ();
|
||||||
|
m_LastPoolCleanUpTime = ts;
|
||||||
|
}
|
||||||
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
|
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
|
||||||
for (auto it = m_RequestedDestinations.begin (); it != m_RequestedDestinations.end ();)
|
for (auto it = m_RequestedDestinations.begin (); it != m_RequestedDestinations.end ();)
|
||||||
{
|
{
|
||||||
|
@ -15,17 +15,19 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "RouterInfo.h"
|
#include "RouterInfo.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace data
|
namespace data
|
||||||
{
|
{
|
||||||
const size_t MAX_NUM_REQUEST_ATTEMPTS = 7;
|
const size_t MAX_NUM_REQUEST_ATTEMPTS = 5;
|
||||||
const uint64_t MANAGE_REQUESTS_INTERVAL = 1; // in seconds
|
const uint64_t MANAGE_REQUESTS_INTERVAL = 1; // in seconds
|
||||||
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
|
const uint64_t REQUEST_CACHE_TIME = MAX_REQUEST_TIME + 40; // in seconds
|
||||||
|
const uint64_t REQUESTED_DESTINATIONS_POOL_CLEANUP_INTERVAL = 191; // in seconds
|
||||||
|
|
||||||
class RequestedDestination
|
class RequestedDestination
|
||||||
{
|
{
|
||||||
@ -83,6 +85,8 @@ namespace data
|
|||||||
|
|
||||||
mutable std::mutex m_RequestedDestinationsMutex;
|
mutable std::mutex m_RequestedDestinationsMutex;
|
||||||
std::unordered_map<IdentHash, std::shared_ptr<RequestedDestination> > m_RequestedDestinations;
|
std::unordered_map<IdentHash, std::shared_ptr<RequestedDestination> > m_RequestedDestinations;
|
||||||
|
i2p::util::MemoryPoolMt<RequestedDestination> m_RequestedDestinationsPool;
|
||||||
|
uint64_t m_LastPoolCleanUpTime = 0; // in seconds
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user