moved netdb requests to separate thread

This commit is contained in:
orignal 2024-05-21 21:25:19 -04:00
parent d8707ceb57
commit e3be409945
3 changed files with 55 additions and 14 deletions

View file

@ -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 ();
}
}
}
}