trim behind ECIESx25519 tags

This commit is contained in:
orignal 2020-09-07 18:45:05 -04:00
parent a0685d804d
commit a05a54b38e
4 changed files with 19 additions and 12 deletions

View File

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

View File

@ -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
} 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;

View File

@ -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
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
{
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)

View File

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