mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-09 07:17:53 +00: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");
|
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;
|
uint64_t lastProfilesCleanup = i2p::util::GetMonotonicMilliseconds (), lastObsoleteProfilesCleanup = lastProfilesCleanup;
|
||||||
int16_t profilesCleanupVariance = 0, obsoleteProfilesCleanVariance = 0, exploratoryIntervalVariance = 0;
|
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
|
continue; // don't manage netdb when offline or transports are not running
|
||||||
|
|
||||||
uint64_t mts = i2p::util::GetMonotonicMilliseconds ();
|
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 (mts >= lastManage + 60000) // manage routers and leasesets every minute
|
||||||
{
|
{
|
||||||
if (lastManage)
|
if (lastManage)
|
||||||
|
@ -104,16 +104,38 @@ namespace data
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NetDbRequests::NetDbRequests ():
|
||||||
|
RunnableServiceWithWork ("NetDbReq"),
|
||||||
|
m_ManageRequestsTimer (GetIOService ())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NetDbRequests::~NetDbRequests ()
|
||||||
|
{
|
||||||
|
Stop ();
|
||||||
|
}
|
||||||
|
|
||||||
void NetDbRequests::Start ()
|
void NetDbRequests::Start ()
|
||||||
{
|
{
|
||||||
m_LastPoolCleanUpTime = i2p::util::GetSecondsSinceEpoch ();
|
m_LastPoolCleanUpTime = i2p::util::GetSecondsSinceEpoch ();
|
||||||
|
if (!IsRunning ())
|
||||||
|
{
|
||||||
|
StartIOService ();
|
||||||
|
ScheduleManageRequests ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDbRequests::Stop ()
|
void NetDbRequests::Stop ()
|
||||||
{
|
{
|
||||||
|
if (IsRunning ())
|
||||||
|
{
|
||||||
|
m_ManageRequestsTimer.cancel ();
|
||||||
|
StopIOService ();
|
||||||
|
|
||||||
m_RequestedDestinations.clear ();
|
m_RequestedDestinations.clear ();
|
||||||
m_RequestedDestinationsPool.CleanUpMt ();
|
m_RequestedDestinationsPool.CleanUpMt ();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<RequestedDestination> NetDbRequests::CreateRequest (const IdentHash& destination,
|
std::shared_ptr<RequestedDestination> NetDbRequests::CreateRequest (const IdentHash& destination,
|
||||||
@ -294,5 +316,22 @@ namespace data
|
|||||||
}
|
}
|
||||||
return ret;
|
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;
|
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:
|
public:
|
||||||
|
|
||||||
|
NetDbRequests ();
|
||||||
|
~NetDbRequests ();
|
||||||
|
|
||||||
void Start ();
|
void Start ();
|
||||||
void Stop ();
|
void Stop ();
|
||||||
|
|
||||||
@ -79,15 +83,22 @@ namespace data
|
|||||||
bool direct = false, RequestedDestination::RequestComplete requestComplete = nullptr);
|
bool direct = false, RequestedDestination::RequestComplete requestComplete = nullptr);
|
||||||
void RequestComplete (const IdentHash& ident, std::shared_ptr<RouterInfo> r);
|
void RequestComplete (const IdentHash& ident, std::shared_ptr<RouterInfo> r);
|
||||||
std::shared_ptr<RequestedDestination> FindRequest (const IdentHash& ident) const;
|
std::shared_ptr<RequestedDestination> FindRequest (const IdentHash& ident) const;
|
||||||
void ManageRequests ();
|
|
||||||
bool SendNextRequest (std::shared_ptr<RequestedDestination> dest);
|
bool SendNextRequest (std::shared_ptr<RequestedDestination> dest);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void ManageRequests ();
|
||||||
|
// timer
|
||||||
|
void ScheduleManageRequests ();
|
||||||
|
void HandleManageRequestsTimer (const boost::system::error_code& ecode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
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;
|
i2p::util::MemoryPoolMt<RequestedDestination> m_RequestedDestinationsPool;
|
||||||
uint64_t m_LastPoolCleanUpTime = 0; // in seconds
|
uint64_t m_LastPoolCleanUpTime = 0; // in seconds
|
||||||
|
boost::asio::deadline_timer m_ManageRequestsTimer;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user