Browse Source

re-shedule introducers updates if router becomes firewalled

pull/1640/head
orignal 4 years ago
parent
commit
e70ffc9d7c
  1. 24
      libi2pd/SSU.cpp
  2. 3
      libi2pd/SSU.h
  3. 3
      libi2pd/SSUSession.cpp

24
libi2pd/SSU.cpp

@ -653,6 +653,14 @@ namespace transport @@ -653,6 +653,14 @@ namespace transport
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 ()
{
m_IntroducersUpdateTimer.expires_from_now (boost::posix_time::seconds(SSU_KEEP_ALIVE_INTERVAL));
@ -671,7 +679,12 @@ namespace transport @@ -671,7 +679,12 @@ namespace transport
ScheduleIntroducersUpdateTimer ();
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
if (!i2p::context.IsUnreachable ()) i2p::context.SetUnreachable ();
std::list<boost::asio::ip::udp::endpoint> newList;
@ -712,16 +725,21 @@ namespace transport @@ -712,16 +725,21 @@ namespace transport
m_Introducers = newList;
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++)
{
auto introducer = i2p::data::netdb.GetRandomIntroducer ();
if (introducer)
if (introducer && !requested.count (introducer)) // not requested already
{
auto address = introducer->GetSSUAddress (true); // v4
if (address && !address->host.is_unspecified ())
{
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);
}
}
}
}

3
libi2pd/SSU.h

@ -70,7 +70,8 @@ namespace transport @@ -70,7 +70,8 @@ namespace transport
void AddRelay (uint32_t tag, std::shared_ptr<SSUSession> relay);
void RemoveRelay (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);
PeerTestParticipant GetPeerTestParticipant (uint32_t nonce);
std::shared_ptr<SSUSession> GetPeerTestSession (uint32_t nonce);

3
libi2pd/SSUSession.cpp

@ -999,7 +999,10 @@ namespace transport @@ -999,7 +999,10 @@ namespace transport
{
LogPrint (eLogDebug, "SSU: peer test from Bob. We are Alice");
if (i2p::context.GetStatus () == eRouterStatusTesting) // still not OK
{
i2p::context.SetStatus (eRouterStatusFirewalled);
m_Server.RescheduleIntroducersUpdateTimer ();
}
}
else
{

Loading…
Cancel
Save