diff --git a/Garlic.cpp b/Garlic.cpp index c86947d1..113aaa8d 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -15,9 +15,9 @@ namespace i2p namespace garlic { GarlicRoutingSession::GarlicRoutingSession (GarlicDestination * owner, - std::shared_ptr destination, int numTags): + std::shared_ptr destination, int numTags, bool attachLeaseSet): m_Owner (owner), m_Destination (destination), m_NumTags (numTags), - m_LeaseSetUpdateStatus (numTags > 0 ? eLeaseSetUpdated : eLeaseSetUpToDate) + m_LeaseSetUpdateStatus (attachLeaseSet ? eLeaseSetUpdated : eLeaseSetDoNotSend) { // create new session tags and session key m_Rnd.GenerateBlock (m_SessionKey, 32); @@ -25,7 +25,7 @@ namespace garlic } GarlicRoutingSession::GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag): - m_Owner (nullptr), m_Destination (nullptr), m_NumTags (1), m_LeaseSetUpdateStatus (eLeaseSetUpToDate) + m_Owner (nullptr), m_Destination (nullptr), m_NumTags (1), m_LeaseSetUpdateStatus (eLeaseSetDoNotSend) { memcpy (m_SessionKey, sessionKey, 32); m_Encryption.SetKey (m_SessionKey); @@ -524,20 +524,12 @@ namespace garlic I2NPMessage * GarlicDestination::WrapMessage (std::shared_ptr destination, I2NPMessage * msg, bool attachLeaseSet) { - if (attachLeaseSet) // we should maintain this session - { - auto session = GetRoutingSession (destination, 32); // 32 tags by default - return session->WrapSingleMessage (msg); - } - else // one time session - { - GarlicRoutingSession session (this, destination, 0); // don't use tag if no LeaseSet - return session.WrapSingleMessage (msg); - } + auto session = GetRoutingSession (destination, attachLeaseSet); // 32 tags by default + return session->WrapSingleMessage (msg); } std::shared_ptr GarlicDestination::GetRoutingSession ( - std::shared_ptr destination, int numTags) + std::shared_ptr destination, bool attachLeaseSet) { auto it = m_Sessions.find (destination->GetIdentHash ()); std::shared_ptr session; @@ -545,7 +537,8 @@ namespace garlic session = it->second; if (!session) { - session = std::make_shared (this, destination, numTags); + session = std::make_shared (this, destination, + attachLeaseSet ? 40 : 4, attachLeaseSet); // 40 tags for connections and 4 for LS requests std::unique_lock l(m_SessionsMutex); m_Sessions[destination->GetIdentHash ()] = session; } diff --git a/Garlic.h b/Garlic.h index bb60a776..6f96d4e7 100644 --- a/Garlic.h +++ b/Garlic.h @@ -61,7 +61,8 @@ namespace garlic { eLeaseSetUpToDate = 0, eLeaseSetUpdated, - eLeaseSetSubmitted + eLeaseSetSubmitted, + eLeaseSetDoNotSend }; struct UnconfirmedTags @@ -75,14 +76,18 @@ namespace garlic public: - GarlicRoutingSession (GarlicDestination * owner, std::shared_ptr destination, int numTags); + GarlicRoutingSession (GarlicDestination * owner, std::shared_ptr destination, + int numTags, bool attachLeaseSet); GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag); // one time encryption ~GarlicRoutingSession (); I2NPMessage * WrapSingleMessage (I2NPMessage * msg); void MessageConfirmed (uint32_t msgID); bool CleanupExpiredTags (); // returns true if something left - void SetLeaseSetUpdated () { m_LeaseSetUpdateStatus = eLeaseSetUpdated; }; + void SetLeaseSetUpdated () + { + if (m_LeaseSetUpdateStatus != eLeaseSetDoNotSend) m_LeaseSetUpdateStatus = eLeaseSetUpdated; + }; private: @@ -118,7 +123,7 @@ namespace garlic GarlicDestination (): m_LastTagsCleanupTime (0) {}; ~GarlicDestination (); - std::shared_ptr GetRoutingSession (std::shared_ptr destination, int numTags); + std::shared_ptr GetRoutingSession (std::shared_ptr destination, bool attachLeaseSet); void CleanupRoutingSessions (); void RemoveCreatedSession (uint32_t msgID); I2NPMessage * WrapMessage (std::shared_ptr destination,