mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
moved netdb requests to separate thread
This commit is contained in:
parent
d8707ceb57
commit
e3be409945
@ -118,7 +118,7 @@ namespace data
|
||||
{
|
||||
i2p::util::SetThreadName("NetDB");
|
||||
|
||||
uint64_t lastManage = 0, lastExploratory = 0, lastManageRequest = 0;
|
||||
uint64_t lastManage = 0, lastExploratory = 0;
|
||||
uint64_t lastProfilesCleanup = i2p::util::GetMonotonicMilliseconds (), lastObsoleteProfilesCleanup = lastProfilesCleanup;
|
||||
int16_t profilesCleanupVariance = 0, obsoleteProfilesCleanVariance = 0, exploratoryIntervalVariance = 0;
|
||||
|
||||
@ -162,15 +162,6 @@ namespace data
|
||||
continue; // don't manage netdb when offline or transports are not running
|
||||
|
||||
uint64_t mts = i2p::util::GetMonotonicMilliseconds ();
|
||||
if (mts >= lastManageRequest + MANAGE_REQUESTS_INTERVAL*1000)
|
||||
{
|
||||
if (lastManageRequest || i2p::tunnel::tunnels.GetExploratoryPool ()) // expolratory pool is ready?
|
||||
{
|
||||
if (m_Requests) m_Requests->ManageRequests ();
|
||||
lastManageRequest = mts;
|
||||
}
|
||||
}
|
||||
|
||||
if (mts >= lastManage + 60000) // manage routers and leasesets every minute
|
||||
{
|
||||
if (lastManage)
|
||||
|
@ -104,15 +104,37 @@ namespace data
|
||||
}
|
||||
}
|
||||
|
||||
NetDbRequests::NetDbRequests ():
|
||||
RunnableServiceWithWork ("NetDbReq"),
|
||||
m_ManageRequestsTimer (GetIOService ())
|
||||
{
|
||||
}
|
||||
|
||||
NetDbRequests::~NetDbRequests ()
|
||||
{
|
||||
Stop ();
|
||||
}
|
||||
|
||||
void NetDbRequests::Start ()
|
||||
{
|
||||
m_LastPoolCleanUpTime = i2p::util::GetSecondsSinceEpoch ();
|
||||
if (!IsRunning ())
|
||||
{
|
||||
StartIOService ();
|
||||
ScheduleManageRequests ();
|
||||
}
|
||||
}
|
||||
|
||||
void NetDbRequests::Stop ()
|
||||
{
|
||||
m_RequestedDestinations.clear ();
|
||||
m_RequestedDestinationsPool.CleanUpMt ();
|
||||
if (IsRunning ())
|
||||
{
|
||||
m_ManageRequestsTimer.cancel ();
|
||||
StopIOService ();
|
||||
|
||||
m_RequestedDestinations.clear ();
|
||||
m_RequestedDestinationsPool.CleanUpMt ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -294,5 +316,22 @@ namespace data
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void NetDbRequests::ScheduleManageRequests ()
|
||||
{
|
||||
m_ManageRequestsTimer.expires_from_now (boost::posix_time::seconds(MANAGE_REQUESTS_INTERVAL));
|
||||
m_ManageRequestsTimer.async_wait (std::bind (&NetDbRequests::HandleManageRequestsTimer,
|
||||
this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void NetDbRequests::HandleManageRequestsTimer (const boost::system::error_code& ecode)
|
||||
{
|
||||
if (ecode != boost::asio::error::operation_aborted)
|
||||
{
|
||||
if (i2p::tunnel::tunnels.GetExploratoryPool ()) // expolratory pool is ready?
|
||||
ManageRequests ();
|
||||
ScheduleManageRequests ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,10 +68,14 @@ namespace data
|
||||
int m_NumAttempts;
|
||||
};
|
||||
|
||||
class NetDbRequests: public std::enable_shared_from_this<NetDbRequests>
|
||||
class NetDbRequests: public std::enable_shared_from_this<NetDbRequests>,
|
||||
private i2p::util::RunnableServiceWithWork
|
||||
{
|
||||
public:
|
||||
|
||||
NetDbRequests ();
|
||||
~NetDbRequests ();
|
||||
|
||||
void Start ();
|
||||
void Stop ();
|
||||
|
||||
@ -79,15 +83,22 @@ namespace data
|
||||
bool direct = false, RequestedDestination::RequestComplete requestComplete = nullptr);
|
||||
void RequestComplete (const IdentHash& ident, std::shared_ptr<RouterInfo> r);
|
||||
std::shared_ptr<RequestedDestination> FindRequest (const IdentHash& ident) const;
|
||||
void ManageRequests ();
|
||||
bool SendNextRequest (std::shared_ptr<RequestedDestination> dest);
|
||||
|
||||
private:
|
||||
|
||||
void ManageRequests ();
|
||||
// timer
|
||||
void ScheduleManageRequests ();
|
||||
void HandleManageRequestsTimer (const boost::system::error_code& ecode);
|
||||
|
||||
private:
|
||||
|
||||
mutable std::mutex m_RequestedDestinationsMutex;
|
||||
std::unordered_map<IdentHash, std::shared_ptr<RequestedDestination> > m_RequestedDestinations;
|
||||
i2p::util::MemoryPoolMt<RequestedDestination> m_RequestedDestinationsPool;
|
||||
uint64_t m_LastPoolCleanUpTime = 0; // in seconds
|
||||
boost::asio::deadline_timer m_ManageRequestsTimer;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user