From 5cb691fb0bc0eebb566d51574ab6f8cd46898677 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 9 Sep 2014 13:45:12 -0400 Subject: [PATCH] limit session to introducer by 1 hour --- SSU.cpp | 10 +++++++--- SSU.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/SSU.cpp b/SSU.cpp index 4daa04e9..b0b3c0c3 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -22,6 +22,7 @@ namespace ssu m_IsSessionKey (false), m_RelayTag (0), m_Data (*this), m_NumSentBytes (0), m_NumReceivedBytes (0) { + m_CreationTime = i2p::util::GetSecondsSinceEpoch (); m_DHKeysPair = i2p::transports.GetNextDHKeysPair (); if (!router) // incoming session ScheduleConnectTimer (); @@ -1124,14 +1125,16 @@ namespace ssu std::set SSUServer::FindIntroducers (int maxNumIntroducers) { + uint32_t ts = i2p::util::GetSecondsSinceEpoch (); std::set ret; for (int i = 0; i < maxNumIntroducers; i++) { auto session = GetRandomSession ( - [&ret](SSUSession * session)->bool + [&ret, ts](SSUSession * session)->bool { return session->GetRelayTag () && !ret.count (session) && - session->GetState () == eSessionStateEstablished; + session->GetState () == eSessionStateEstablished && + ts < session->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION; } ); if (session) @@ -1157,10 +1160,11 @@ namespace ssu // timeout expired std::list newList; size_t numIntroducers = 0; + uint32_t ts = i2p::util::GetSecondsSinceEpoch (); for (auto it :m_Introducers) { auto session = FindSession (it); - if (session) + if (session && ts < session->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION) { session->SendKeepAlive (); newList.push_back (it); diff --git a/SSU.h b/SSU.h index 9bf1bea0..bcf1aecf 100644 --- a/SSU.h +++ b/SSU.h @@ -81,6 +81,7 @@ namespace ssu void SendKeepAlive (); uint32_t GetRelayTag () const { return m_RelayTag; }; + uint32_t GetCreationTime () const { return m_CreationTime; }; private: @@ -141,6 +142,7 @@ namespace ssu std::list m_DelayedMessages; SSUData m_Data; size_t m_NumSentBytes, m_NumReceivedBytes; + uint32_t m_CreationTime; // seconds since epoch }; class SSUServer