From e70ffc9d7c57aaa4b739d71bb34ca86f77e06875 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 4 Mar 2021 15:55:51 -0500 Subject: [PATCH] re-shedule introducers updates if router becomes firewalled --- libi2pd/SSU.cpp | 24 +++++++++++++++++++++--- libi2pd/SSU.h | 3 ++- libi2pd/SSUSession.cpp | 3 +++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/libi2pd/SSU.cpp b/libi2pd/SSU.cpp index f1de3893..3b2dc122 100644 --- a/libi2pd/SSU.cpp +++ b/libi2pd/SSU.cpp @@ -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 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 newList; @@ -712,16 +725,21 @@ namespace transport m_Introducers = newList; if (m_Introducers.size () < SSU_MAX_NUM_INTRODUCERS) { + std::set > 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); + } } } } diff --git a/libi2pd/SSU.h b/libi2pd/SSU.h index bfcfed4e..daaa83f3 100644 --- a/libi2pd/SSU.h +++ b/libi2pd/SSU.h @@ -70,7 +70,8 @@ namespace transport void AddRelay (uint32_t tag, std::shared_ptr relay); void RemoveRelay (uint32_t tag); std::shared_ptr FindRelaySession (uint32_t tag); - + void RescheduleIntroducersUpdateTimer (); + void NewPeerTest (uint32_t nonce, PeerTestParticipant role, std::shared_ptr session = nullptr); PeerTestParticipant GetPeerTestParticipant (uint32_t nonce); std::shared_ptr GetPeerTestSession (uint32_t nonce); diff --git a/libi2pd/SSUSession.cpp b/libi2pd/SSUSession.cpp index e1e48b75..9685caf7 100644 --- a/libi2pd/SSUSession.cpp +++ b/libi2pd/SSUSession.cpp @@ -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 {