mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-05-20 22:31:47 +02:00
update SSU2 introducers if Firewalled
This commit is contained in:
parent
4a3e481a83
commit
ea0ed9e844
4 changed files with 108 additions and 5 deletions
libi2pd
|
@ -21,7 +21,9 @@ namespace transport
|
|||
RunnableServiceWithWork ("SSU2"), m_ReceiveService ("SSU2r"),
|
||||
m_SocketV4 (m_ReceiveService.GetService ()), m_SocketV6 (m_ReceiveService.GetService ()),
|
||||
m_AddressV4 (boost::asio::ip::address_v4()), m_AddressV6 (boost::asio::ip::address_v6()),
|
||||
m_TerminationTimer (GetService ()), m_ResendTimer (GetService ())
|
||||
m_TerminationTimer (GetService ()), m_ResendTimer (GetService ()),
|
||||
m_IntroducersUpdateTimer (GetService ()), m_IntroducersUpdateTimerV6 (GetService ()),
|
||||
m_IsPublished (true)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -30,6 +32,7 @@ namespace transport
|
|||
if (!IsRunning ())
|
||||
{
|
||||
StartIOService ();
|
||||
i2p::config::GetOption ("ssu2.published", m_IsPublished);
|
||||
bool found = false;
|
||||
auto& addresses = i2p::context.GetRouterInfo ().GetAddresses ();
|
||||
for (const auto& address: addresses)
|
||||
|
@ -59,6 +62,7 @@ namespace transport
|
|||
{
|
||||
Receive (m_SocketV4);
|
||||
});
|
||||
ScheduleIntroducersUpdateTimer (); // wait for 30 seconds and decide if we need introducers
|
||||
}
|
||||
if (address->IsV6 ())
|
||||
{
|
||||
|
@ -69,6 +73,7 @@ namespace transport
|
|||
{
|
||||
Receive (m_SocketV6);
|
||||
});
|
||||
ScheduleIntroducersUpdateTimerV6 (); // wait for 30 seconds and decide if we need introducers
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -827,6 +832,90 @@ namespace transport
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SSU2Server::ScheduleIntroducersUpdateTimer ()
|
||||
{
|
||||
if (m_IsPublished)
|
||||
{
|
||||
m_IntroducersUpdateTimer.expires_from_now (boost::posix_time::seconds(SSU2_KEEP_ALIVE_INTERVAL));
|
||||
m_IntroducersUpdateTimer.async_wait (std::bind (&SSU2Server::HandleIntroducersUpdateTimer,
|
||||
this, std::placeholders::_1, true));
|
||||
}
|
||||
}
|
||||
|
||||
void SSU2Server::RescheduleIntroducersUpdateTimer ()
|
||||
{
|
||||
if (m_IsPublished)
|
||||
{
|
||||
m_IntroducersUpdateTimer.cancel ();
|
||||
m_IntroducersUpdateTimer.expires_from_now (boost::posix_time::seconds(SSU2_KEEP_ALIVE_INTERVAL/2));
|
||||
m_IntroducersUpdateTimer.async_wait (std::bind (&SSU2Server::HandleIntroducersUpdateTimer,
|
||||
this, std::placeholders::_1, true));
|
||||
}
|
||||
}
|
||||
|
||||
void SSU2Server::ScheduleIntroducersUpdateTimerV6 ()
|
||||
{
|
||||
if (m_IsPublished)
|
||||
{
|
||||
m_IntroducersUpdateTimerV6.expires_from_now (boost::posix_time::seconds(SSU2_KEEP_ALIVE_INTERVAL));
|
||||
m_IntroducersUpdateTimerV6.async_wait (std::bind (&SSU2Server::HandleIntroducersUpdateTimer,
|
||||
this, std::placeholders::_1, false));
|
||||
}
|
||||
}
|
||||
|
||||
void SSU2Server::RescheduleIntroducersUpdateTimerV6 ()
|
||||
{
|
||||
if (m_IsPublished)
|
||||
{
|
||||
m_IntroducersUpdateTimerV6.cancel ();
|
||||
m_IntroducersUpdateTimerV6.expires_from_now (boost::posix_time::seconds(SSU2_KEEP_ALIVE_INTERVAL/2));
|
||||
m_IntroducersUpdateTimerV6.async_wait (std::bind (&SSU2Server::HandleIntroducersUpdateTimer,
|
||||
this, std::placeholders::_1, false));
|
||||
}
|
||||
}
|
||||
|
||||
void SSU2Server::HandleIntroducersUpdateTimer (const boost::system::error_code& ecode, bool v4)
|
||||
{
|
||||
if (ecode != boost::asio::error::operation_aborted)
|
||||
{
|
||||
// timeout expired
|
||||
if (v4)
|
||||
{
|
||||
if (i2p::context.GetStatus () == eRouterStatusTesting)
|
||||
{
|
||||
// we still don't know if we need introducers
|
||||
ScheduleIntroducersUpdateTimer ();
|
||||
return;
|
||||
}
|
||||
if (i2p::context.GetStatus () != eRouterStatusFirewalled)
|
||||
{
|
||||
// we don't need introducers
|
||||
m_Introducers.clear ();
|
||||
return;
|
||||
}
|
||||
UpdateIntroducers (true);
|
||||
ScheduleIntroducersUpdateTimer ();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i2p::context.GetStatusV6 () == eRouterStatusTesting)
|
||||
{
|
||||
// we still don't know if we need introducers
|
||||
ScheduleIntroducersUpdateTimerV6 ();
|
||||
return;
|
||||
}
|
||||
if (i2p::context.GetStatusV6 () != eRouterStatusFirewalled)
|
||||
{
|
||||
// we don't need introducers
|
||||
m_IntroducersV6.clear ();
|
||||
return;
|
||||
}
|
||||
UpdateIntroducers (false);
|
||||
ScheduleIntroducersUpdateTimerV6 ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue