Skip to content

Commit

Permalink
don't include same introducer twice
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Sep 9, 2014
1 parent 98fd1c7 commit 5435d20
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions RouterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion RouterContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
11 changes: 7 additions & 4 deletions SSU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ namespace ssu
{
// timeout expired
std::list<boost::asio::ip::udp::endpoint> newList;
int numIntroducers = 0;
size_t numIntroducers = 0;
for (auto it :m_Introducers)
{
auto session = FindSession (it);
Expand All @@ -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;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion SSU.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5435d20

Please sign in to comment.