mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
re-shedule introducers updates if router becomes firewalled
This commit is contained in:
parent
065cfe3b9d
commit
e70ffc9d7c
|
@ -653,6 +653,14 @@ namespace transport
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SSUServer::RescheduleIntroducersUpdateTimer ()
|
||||||
|
{
|
||||||
|
m_IntroducersUpdateTimer.cancel ();
|
||||||
|
m_IntroducersUpdateTimer.expires_from_now (boost::posix_time::seconds(SSU_KEEP_ALIVE_INTERVAL/2));
|
||||||
|
m_IntroducersUpdateTimer.async_wait (std::bind (&SSUServer::HandleIntroducersUpdateTimer,
|
||||||
|
this, std::placeholders::_1));
|
||||||
|
}
|
||||||
|
|
||||||
void SSUServer::ScheduleIntroducersUpdateTimer ()
|
void SSUServer::ScheduleIntroducersUpdateTimer ()
|
||||||
{
|
{
|
||||||
m_IntroducersUpdateTimer.expires_from_now (boost::posix_time::seconds(SSU_KEEP_ALIVE_INTERVAL));
|
m_IntroducersUpdateTimer.expires_from_now (boost::posix_time::seconds(SSU_KEEP_ALIVE_INTERVAL));
|
||||||
|
@ -671,7 +679,12 @@ namespace transport
|
||||||
ScheduleIntroducersUpdateTimer ();
|
ScheduleIntroducersUpdateTimer ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (i2p::context.GetStatus () != eRouterStatusFirewalled) return; // we don't need introducers
|
if (i2p::context.GetStatus () != eRouterStatusFirewalled)
|
||||||
|
{
|
||||||
|
// we don't need introducers
|
||||||
|
m_Introducers.clear ();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// we are firewalled
|
// we are firewalled
|
||||||
if (!i2p::context.IsUnreachable ()) i2p::context.SetUnreachable ();
|
if (!i2p::context.IsUnreachable ()) i2p::context.SetUnreachable ();
|
||||||
std::list<boost::asio::ip::udp::endpoint> newList;
|
std::list<boost::asio::ip::udp::endpoint> newList;
|
||||||
|
@ -712,16 +725,21 @@ namespace transport
|
||||||
m_Introducers = newList;
|
m_Introducers = newList;
|
||||||
if (m_Introducers.size () < SSU_MAX_NUM_INTRODUCERS)
|
if (m_Introducers.size () < SSU_MAX_NUM_INTRODUCERS)
|
||||||
{
|
{
|
||||||
|
std::set<std::shared_ptr<const i2p::data::RouterInfo> > requested;
|
||||||
for (auto i = m_Introducers.size (); i < SSU_MAX_NUM_INTRODUCERS; i++)
|
for (auto i = m_Introducers.size (); i < SSU_MAX_NUM_INTRODUCERS; i++)
|
||||||
{
|
{
|
||||||
auto introducer = i2p::data::netdb.GetRandomIntroducer ();
|
auto introducer = i2p::data::netdb.GetRandomIntroducer ();
|
||||||
if (introducer)
|
if (introducer && !requested.count (introducer)) // not requested already
|
||||||
{
|
{
|
||||||
auto address = introducer->GetSSUAddress (true); // v4
|
auto address = introducer->GetSSUAddress (true); // v4
|
||||||
if (address && !address->host.is_unspecified ())
|
if (address && !address->host.is_unspecified ())
|
||||||
{
|
{
|
||||||
boost::asio::ip::udp::endpoint ep (address->host, address->port);
|
boost::asio::ip::udp::endpoint ep (address->host, address->port);
|
||||||
CreateDirectSession (introducer, ep, false);
|
if (std::find (m_Introducers.begin (), m_Introducers.end (), ep) == m_Introducers.end ()) // not connected yet
|
||||||
|
{
|
||||||
|
CreateDirectSession (introducer, ep, false);
|
||||||
|
requested.insert (introducer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,8 @@ namespace transport
|
||||||
void AddRelay (uint32_t tag, std::shared_ptr<SSUSession> relay);
|
void AddRelay (uint32_t tag, std::shared_ptr<SSUSession> relay);
|
||||||
void RemoveRelay (uint32_t tag);
|
void RemoveRelay (uint32_t tag);
|
||||||
std::shared_ptr<SSUSession> FindRelaySession (uint32_t tag);
|
std::shared_ptr<SSUSession> FindRelaySession (uint32_t tag);
|
||||||
|
void RescheduleIntroducersUpdateTimer ();
|
||||||
|
|
||||||
void NewPeerTest (uint32_t nonce, PeerTestParticipant role, std::shared_ptr<SSUSession> session = nullptr);
|
void NewPeerTest (uint32_t nonce, PeerTestParticipant role, std::shared_ptr<SSUSession> session = nullptr);
|
||||||
PeerTestParticipant GetPeerTestParticipant (uint32_t nonce);
|
PeerTestParticipant GetPeerTestParticipant (uint32_t nonce);
|
||||||
std::shared_ptr<SSUSession> GetPeerTestSession (uint32_t nonce);
|
std::shared_ptr<SSUSession> GetPeerTestSession (uint32_t nonce);
|
||||||
|
|
|
@ -999,7 +999,10 @@ namespace transport
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "SSU: peer test from Bob. We are Alice");
|
LogPrint (eLogDebug, "SSU: peer test from Bob. We are Alice");
|
||||||
if (i2p::context.GetStatus () == eRouterStatusTesting) // still not OK
|
if (i2p::context.GetStatus () == eRouterStatusTesting) // still not OK
|
||||||
|
{
|
||||||
i2p::context.SetStatus (eRouterStatusFirewalled);
|
i2p::context.SetStatus (eRouterStatusFirewalled);
|
||||||
|
m_Server.RescheduleIntroducersUpdateTimer ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue