Browse Source

trim behind ECIESx25519 tags

pull/1553/head
orignal 4 years ago
parent
commit
a05a54b38e
  1. 3
      libi2pd/ECIESX25519AEADRatchetSession.cpp
  2. 6
      libi2pd/ECIESX25519AEADRatchetSession.h
  3. 21
      libi2pd/Garlic.cpp
  4. 1
      libi2pd/Garlic.h

3
libi2pd/ECIESX25519AEADRatchetSession.cpp

@ -657,7 +657,10 @@ namespace garlic @@ -657,7 +657,10 @@ namespace garlic
moreTags -= (receiveTagset->GetNextIndex () - index);
}
if (moreTags > 0)
{
GenerateMoreReceiveTags (receiveTagset, moreTags);
receiveTagset->MoveTrimBehind (moreTags >> 1); // /2
}
}
return true;
}

6
libi2pd/ECIESX25519AEADRatchetSession.h

@ -56,10 +56,12 @@ namespace garlic @@ -56,10 +56,12 @@ namespace garlic
std::shared_ptr<ECIESX25519AEADRatchetSession> GetSession () { return m_Session.lock (); };
int GetTagSetID () const { return m_TagSetID; };
void SetTagSetID (int tagsetID) { m_TagSetID = tagsetID; };
void MoveTrimBehind (int offset) { m_TrimBehindIndex += offset; };
void Expire ();
bool IsExpired (uint64_t ts) const { return m_ExpirationTimestamp && ts > m_ExpirationTimestamp; };
bool IsIndexExpired (int index) const { return m_Session.expired () || index < m_TrimBehindIndex; };
private:
union
@ -73,7 +75,7 @@ namespace garlic @@ -73,7 +75,7 @@ namespace garlic
} m_KeyData;
uint8_t m_SessTagConstant[32], m_SymmKeyCK[32], m_CurrentSymmKeyCK[64], m_NextRootKey[32];
int m_NextIndex, m_NextSymmKeyIndex;
int m_NextIndex, m_NextSymmKeyIndex, m_TrimBehindIndex = 0;
std::unordered_map<int, i2p::data::Tag<32> > m_ItermediateSymmKeys;
std::weak_ptr<ECIESX25519AEADRatchetSession> m_Session;
int m_TagSetID = 0;

21
libi2pd/Garlic.cpp

@ -802,14 +802,6 @@ namespace garlic @@ -802,14 +802,6 @@ namespace garlic
}
}
// ECIESx25519
for (auto it = m_ECIESx25519Tags.begin (); it != m_ECIESx25519Tags.end ();)
{
if (it->second.tagset->IsExpired (ts) || ts > it->second.creationTime + ECIESX25519_INCOMING_TAGS_EXPIRATION_TIMEOUT)
it = m_ECIESx25519Tags.erase (it);
else
++it;
}
for (auto it = m_ECIESx25519Sessions.begin (); it != m_ECIESx25519Sessions.end ();)
{
if (it->second->CheckExpired (ts))
@ -820,6 +812,17 @@ namespace garlic @@ -820,6 +812,17 @@ namespace garlic
else
++it;
}
numExpiredTags = 0;
for (auto it = m_ECIESx25519Tags.begin (); it != m_ECIESx25519Tags.end ();)
{
if (it->second.tagset->IsExpired (ts) || it->second.tagset->IsIndexExpired (it->second.index))
it = m_ECIESx25519Tags.erase (it);
else
++it;
}
if (numExpiredTags > 0)
LogPrint (eLogDebug, "Garlic: ", numExpiredTags, " ECIESx25519 tags expired for ", GetIdentHash().ToBase64 ());
}
void GarlicDestination::RemoveDeliveryStatusSession (uint32_t msgID)
@ -1009,7 +1012,7 @@ namespace garlic @@ -1009,7 +1012,7 @@ namespace garlic
{
auto index = tagset->GetNextIndex ();
uint64_t tag = tagset->GetNextSessionTag ();
m_ECIESx25519Tags.emplace (tag, ECIESX25519AEADRatchetIndexTagset{index, tagset, i2p::util::GetSecondsSinceEpoch ()});
m_ECIESx25519Tags.emplace (tag, ECIESX25519AEADRatchetIndexTagset{index, tagset});
}
void GarlicDestination::AddECIESx25519Session (const uint8_t * staticKey, ECIESX25519AEADRatchetSessionPtr session)

1
libi2pd/Garlic.h

@ -220,7 +220,6 @@ namespace garlic @@ -220,7 +220,6 @@ namespace garlic
{
int index;
RatchetTagSetPtr tagset;
uint64_t creationTime; // seconds since epoch
};
class GarlicDestination: public i2p::data::LocalDestination

Loading…
Cancel
Save