diff --git a/RouterContext.cpp b/RouterContext.cpp index 10f9a650..cdd6919f 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -85,14 +85,17 @@ namespace i2p UpdateRouterInfo (); } - void RouterContext::AddIntroducer (const i2p::data::RouterInfo& routerInfo, uint32_t tag) + bool RouterContext::AddIntroducer (const i2p::data::RouterInfo& routerInfo, uint32_t tag) { + bool ret = false; auto address = routerInfo.GetSSUAddress (); if (address) { - if (m_RouterInfo.AddIntroducer (address, tag)) + ret = m_RouterInfo.AddIntroducer (address, tag); + if (ret) UpdateRouterInfo (); } + return true; } void RouterContext::RemoveIntroducer (const boost::asio::ip::udp::endpoint& e) diff --git a/RouterContext.h b/RouterContext.h index d8a387f8..99bb7153 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -28,7 +28,7 @@ namespace i2p void OverrideNTCPAddress (const char * host, int port); // temporary void UpdateAddress (const char * host); // called from SSU - void AddIntroducer (const i2p::data::RouterInfo& routerInfo, uint32_t tag); + bool AddIntroducer (const i2p::data::RouterInfo& routerInfo, uint32_t tag); void RemoveIntroducer (const boost::asio::ip::udp::endpoint& e); bool IsUnreachable () const { return m_IsUnreachable; }; void SetUnreachable (); diff --git a/SSU.cpp b/SSU.cpp index 1e845476..4daa04e9 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -1156,7 +1156,7 @@ namespace ssu { // timeout expired std::list newList; - int numIntroducers = 0; + size_t numIntroducers = 0; for (auto it :m_Introducers) { auto session = FindSession (it); @@ -1173,13 +1173,16 @@ namespace ssu if (numIntroducers < SSU_MAX_NUM_INTRODUCERS) { // create new - auto introducers = FindIntroducers (SSU_MAX_NUM_INTRODUCERS - numIntroducers); + auto introducers = FindIntroducers (SSU_MAX_NUM_INTRODUCERS); if (introducers.size () > 0) { for (auto it1: introducers) { - i2p::context.AddIntroducer (*it1->GetRemoteRouter (), it1->GetRelayTag ()); - newList.push_back (it1->GetRemoteEndpoint ()); + if (i2p::context.AddIntroducer (*it1->GetRemoteRouter (), it1->GetRelayTag ())) + { + newList.push_back (it1->GetRemoteEndpoint ()); + if (newList.size () >= SSU_MAX_NUM_INTRODUCERS) break; + } } } } diff --git a/SSU.h b/SSU.h index bbaf94ad..9bf1bea0 100644 --- a/SSU.h +++ b/SSU.h @@ -35,7 +35,7 @@ namespace ssu const int SSU_TERMINATION_TIMEOUT = 330; // 5.5 minutes const int SSU_KEEP_ALIVE_INTERVAL = 30; // 30 seconds const int SSU_TO_INTRODUCER_SESSION_DURATION = 3600; // 1 hour - const int SSU_MAX_NUM_INTRODUCERS = 3; + const size_t SSU_MAX_NUM_INTRODUCERS = 3; // payload types (4 bits) const uint8_t PAYLOAD_TYPE_SESSION_REQUEST = 0;