mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
create io_service after daemonization
This commit is contained in:
parent
de82b3ae19
commit
3c9a574e90
|
@ -28,11 +28,11 @@ namespace i2p
|
||||||
{
|
{
|
||||||
RouterContext context;
|
RouterContext context;
|
||||||
|
|
||||||
RouterContext::RouterContext (): RunnableServiceWithWork ("Router"),
|
RouterContext::RouterContext ():
|
||||||
m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false),
|
m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false),
|
||||||
m_ShareRatio (100), m_Status (eRouterStatusUnknown), m_StatusV6 (eRouterStatusUnknown),
|
m_ShareRatio (100), m_Status (eRouterStatusUnknown), m_StatusV6 (eRouterStatusUnknown),
|
||||||
m_Error (eRouterErrorNone), m_ErrorV6 (eRouterErrorNone), m_NetID (I2PD_NET_ID),
|
m_Error (eRouterErrorNone), m_ErrorV6 (eRouterErrorNone), m_NetID (I2PD_NET_ID),
|
||||||
m_PublishTimer (GetIOService ()), m_PublishReplyToken (0), m_IsHiddenMode (false)
|
m_PublishReplyToken (0), m_IsHiddenMode (false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,20 +52,26 @@ namespace i2p
|
||||||
|
|
||||||
void RouterContext::Start ()
|
void RouterContext::Start ()
|
||||||
{
|
{
|
||||||
if (!IsRunning ())
|
if (!m_Service)
|
||||||
{
|
{
|
||||||
StartIOService ();
|
m_Service.reset (new RouterService);
|
||||||
|
m_Service->Start ();
|
||||||
if (!m_IsHiddenMode)
|
if (!m_IsHiddenMode)
|
||||||
|
{
|
||||||
|
m_PublishTimer.reset (new boost::asio::deadline_timer (m_Service->GetService ()));
|
||||||
ScheduleInitialPublish ();
|
ScheduleInitialPublish ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::Stop ()
|
void RouterContext::Stop ()
|
||||||
{
|
{
|
||||||
if (IsRunning ())
|
if (m_Service)
|
||||||
m_PublishTimer.cancel ();
|
{
|
||||||
|
if (m_PublishTimer)
|
||||||
StopIOService ();
|
m_PublishTimer->cancel ();
|
||||||
|
m_Service->Stop ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::CreateNewRouter ()
|
void RouterContext::CreateNewRouter ()
|
||||||
|
@ -1116,7 +1122,10 @@ namespace i2p
|
||||||
|
|
||||||
void RouterContext::ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg)
|
void RouterContext::ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg)
|
||||||
{
|
{
|
||||||
GetIOService ().post (std::bind (&RouterContext::PostGarlicMessage, this, msg));
|
if (m_Service)
|
||||||
|
m_Service->GetService ().post (std::bind (&RouterContext::PostGarlicMessage, this, msg));
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Router: service is NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::PostGarlicMessage (std::shared_ptr<I2NPMessage> msg)
|
void RouterContext::PostGarlicMessage (std::shared_ptr<I2NPMessage> msg)
|
||||||
|
@ -1141,7 +1150,10 @@ namespace i2p
|
||||||
|
|
||||||
void RouterContext::ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
|
void RouterContext::ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
|
||||||
{
|
{
|
||||||
GetIOService ().post (std::bind (&RouterContext::PostDeliveryStatusMessage, this, msg));
|
if (m_Service)
|
||||||
|
m_Service->GetService ().post (std::bind (&RouterContext::PostDeliveryStatusMessage, this, msg));
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Router: service is NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::PostDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
|
void RouterContext::PostDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
|
||||||
|
@ -1159,10 +1171,13 @@ namespace i2p
|
||||||
|
|
||||||
void RouterContext::CleanupDestination ()
|
void RouterContext::CleanupDestination ()
|
||||||
{
|
{
|
||||||
GetIOService ().post ([this]()
|
if (m_Service)
|
||||||
{
|
m_Service->GetService ().post ([this]()
|
||||||
this->i2p::garlic::GarlicDestination::CleanupExpiredTags ();
|
{
|
||||||
});
|
this->i2p::garlic::GarlicDestination::CleanupExpiredTags ();
|
||||||
|
});
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Router: service is NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RouterContext::GetUptime () const
|
uint32_t RouterContext::GetUptime () const
|
||||||
|
@ -1240,9 +1255,14 @@ namespace i2p
|
||||||
|
|
||||||
void RouterContext::ScheduleInitialPublish ()
|
void RouterContext::ScheduleInitialPublish ()
|
||||||
{
|
{
|
||||||
m_PublishTimer.expires_from_now (boost::posix_time::seconds(ROUTER_INFO_INITIAL_PUBLISH_INTERVAL));
|
if (m_PublishTimer)
|
||||||
m_PublishTimer.async_wait (std::bind (&RouterContext::HandleInitialPublishTimer,
|
{
|
||||||
this, std::placeholders::_1));
|
m_PublishTimer->expires_from_now (boost::posix_time::seconds(ROUTER_INFO_INITIAL_PUBLISH_INTERVAL));
|
||||||
|
m_PublishTimer->async_wait (std::bind (&RouterContext::HandleInitialPublishTimer,
|
||||||
|
this, std::placeholders::_1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Router: Publish timer is NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::HandleInitialPublishTimer (const boost::system::error_code& ecode)
|
void RouterContext::HandleInitialPublishTimer (const boost::system::error_code& ecode)
|
||||||
|
@ -1251,20 +1271,22 @@ namespace i2p
|
||||||
{
|
{
|
||||||
if (m_RouterInfo.IsReachableBy (i2p::data::RouterInfo::eAllTransports))
|
if (m_RouterInfo.IsReachableBy (i2p::data::RouterInfo::eAllTransports))
|
||||||
HandlePublishTimer (ecode);
|
HandlePublishTimer (ecode);
|
||||||
else if (!ecode)
|
ScheduleInitialPublish ();
|
||||||
ScheduleInitialPublish ();
|
|
||||||
else
|
|
||||||
LogPrint (eLogError, "Router: initial publish timer error ", ecode.message ());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::SchedulePublish ()
|
void RouterContext::SchedulePublish ()
|
||||||
{
|
{
|
||||||
m_PublishTimer.cancel ();
|
if (m_PublishTimer)
|
||||||
m_PublishTimer.expires_from_now (boost::posix_time::seconds(ROUTER_INFO_PUBLISH_INTERVAL +
|
{
|
||||||
rand () % ROUTER_INFO_PUBLISH_INTERVAL_VARIANCE));
|
m_PublishTimer->cancel ();
|
||||||
m_PublishTimer.async_wait (std::bind (&RouterContext::HandlePublishTimer,
|
m_PublishTimer->expires_from_now (boost::posix_time::seconds(ROUTER_INFO_PUBLISH_INTERVAL +
|
||||||
this, std::placeholders::_1));
|
rand () % ROUTER_INFO_PUBLISH_INTERVAL_VARIANCE));
|
||||||
|
m_PublishTimer->async_wait (std::bind (&RouterContext::HandlePublishTimer,
|
||||||
|
this, std::placeholders::_1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Router: Publish timer is NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::HandlePublishTimer (const boost::system::error_code& ecode)
|
void RouterContext::HandlePublishTimer (const boost::system::error_code& ecode)
|
||||||
|
@ -1280,10 +1302,7 @@ namespace i2p
|
||||||
}
|
}
|
||||||
UpdateTimestamp (i2p::util::GetSecondsSinceEpoch ());
|
UpdateTimestamp (i2p::util::GetSecondsSinceEpoch ());
|
||||||
Publish ();
|
Publish ();
|
||||||
if (!ecode)
|
SchedulePublishResend ();
|
||||||
SchedulePublishResend ();
|
|
||||||
else
|
|
||||||
LogPrint (eLogError, "Router: publish timer error ", ecode.message ());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1328,10 +1347,15 @@ namespace i2p
|
||||||
|
|
||||||
void RouterContext::SchedulePublishResend ()
|
void RouterContext::SchedulePublishResend ()
|
||||||
{
|
{
|
||||||
m_PublishTimer.cancel ();
|
if (m_PublishTimer)
|
||||||
m_PublishTimer.expires_from_now (boost::posix_time::seconds(ROUTER_INFO_CONFIRMATION_TIMEOUT));
|
{
|
||||||
m_PublishTimer.async_wait (std::bind (&RouterContext::HandlePublishResendTimer,
|
m_PublishTimer->cancel ();
|
||||||
this, std::placeholders::_1));
|
m_PublishTimer->expires_from_now (boost::posix_time::seconds(ROUTER_INFO_CONFIRMATION_TIMEOUT));
|
||||||
|
m_PublishTimer->async_wait (std::bind (&RouterContext::HandlePublishResendTimer,
|
||||||
|
this, std::placeholders::_1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Router: Publish timer is NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::HandlePublishResendTimer (const boost::system::error_code& ecode)
|
void RouterContext::HandlePublishResendTimer (const boost::system::error_code& ecode)
|
||||||
|
@ -1340,10 +1364,7 @@ namespace i2p
|
||||||
{
|
{
|
||||||
i2p::context.UpdateTimestamp (i2p::util::GetSecondsSinceEpoch ());
|
i2p::context.UpdateTimestamp (i2p::util::GetSecondsSinceEpoch ());
|
||||||
Publish ();
|
Publish ();
|
||||||
if (!ecode)
|
SchedulePublishResend ();
|
||||||
SchedulePublishResend ();
|
|
||||||
else
|
|
||||||
LogPrint (eLogError, "Router: publish resend timer error ", ecode.message ());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace garlic
|
||||||
eRouterErrorNoDescriptors = 5
|
eRouterErrorNoDescriptors = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
class RouterContext: public i2p::garlic::GarlicDestination, private i2p::util::RunnableServiceWithWork
|
class RouterContext: public i2p::garlic::GarlicDestination
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -76,6 +76,16 @@ namespace garlic
|
||||||
uint8_t intro[32];
|
uint8_t intro[32];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class RouterService: public i2p::util::RunnableServiceWithWork
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
RouterService (): RunnableServiceWithWork ("Router") {};
|
||||||
|
boost::asio::io_service& GetService () { return GetIOService (); };
|
||||||
|
void Start () { StartIOService (); };
|
||||||
|
void Stop () { StopIOService (); };
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RouterContext ();
|
RouterContext ();
|
||||||
|
@ -224,7 +234,8 @@ namespace garlic
|
||||||
// for ECIESx25519
|
// for ECIESx25519
|
||||||
i2p::crypto::NoiseSymmetricState m_InitialNoiseState, m_CurrentNoiseState;
|
i2p::crypto::NoiseSymmetricState m_InitialNoiseState, m_CurrentNoiseState;
|
||||||
// publish
|
// publish
|
||||||
boost::asio::deadline_timer m_PublishTimer;
|
std::unique_ptr<RouterService> m_Service;
|
||||||
|
std::unique_ptr<boost::asio::deadline_timer> m_PublishTimer;
|
||||||
std::set<i2p::data::IdentHash> m_PublishExcluded;
|
std::set<i2p::data::IdentHash> m_PublishExcluded;
|
||||||
uint32_t m_PublishReplyToken;
|
uint32_t m_PublishReplyToken;
|
||||||
bool m_IsHiddenMode; // not publish
|
bool m_IsHiddenMode; // not publish
|
||||||
|
|
Loading…
Reference in a new issue