mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-16 00:12:43 +00:00
trim behind ECIESx25519 tags
This commit is contained in:
parent
a0685d804d
commit
a05a54b38e
@ -657,7 +657,10 @@ namespace garlic
|
|||||||
moreTags -= (receiveTagset->GetNextIndex () - index);
|
moreTags -= (receiveTagset->GetNextIndex () - index);
|
||||||
}
|
}
|
||||||
if (moreTags > 0)
|
if (moreTags > 0)
|
||||||
|
{
|
||||||
GenerateMoreReceiveTags (receiveTagset, moreTags);
|
GenerateMoreReceiveTags (receiveTagset, moreTags);
|
||||||
|
receiveTagset->MoveTrimBehind (moreTags >> 1); // /2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -56,9 +56,11 @@ namespace garlic
|
|||||||
std::shared_ptr<ECIESX25519AEADRatchetSession> GetSession () { return m_Session.lock (); };
|
std::shared_ptr<ECIESX25519AEADRatchetSession> GetSession () { return m_Session.lock (); };
|
||||||
int GetTagSetID () const { return m_TagSetID; };
|
int GetTagSetID () const { return m_TagSetID; };
|
||||||
void SetTagSetID (int tagsetID) { m_TagSetID = tagsetID; };
|
void SetTagSetID (int tagsetID) { m_TagSetID = tagsetID; };
|
||||||
|
void MoveTrimBehind (int offset) { m_TrimBehindIndex += offset; };
|
||||||
|
|
||||||
void Expire ();
|
void Expire ();
|
||||||
bool IsExpired (uint64_t ts) const { return m_ExpirationTimestamp && ts > m_ExpirationTimestamp; };
|
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:
|
private:
|
||||||
|
|
||||||
@ -73,7 +75,7 @@ namespace garlic
|
|||||||
|
|
||||||
} m_KeyData;
|
} m_KeyData;
|
||||||
uint8_t m_SessTagConstant[32], m_SymmKeyCK[32], m_CurrentSymmKeyCK[64], m_NextRootKey[32];
|
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::unordered_map<int, i2p::data::Tag<32> > m_ItermediateSymmKeys;
|
||||||
std::weak_ptr<ECIESX25519AEADRatchetSession> m_Session;
|
std::weak_ptr<ECIESX25519AEADRatchetSession> m_Session;
|
||||||
int m_TagSetID = 0;
|
int m_TagSetID = 0;
|
||||||
|
@ -802,14 +802,6 @@ namespace garlic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ECIESx25519
|
// 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 ();)
|
for (auto it = m_ECIESx25519Sessions.begin (); it != m_ECIESx25519Sessions.end ();)
|
||||||
{
|
{
|
||||||
if (it->second->CheckExpired (ts))
|
if (it->second->CheckExpired (ts))
|
||||||
@ -820,6 +812,17 @@ namespace garlic
|
|||||||
else
|
else
|
||||||
++it;
|
++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)
|
void GarlicDestination::RemoveDeliveryStatusSession (uint32_t msgID)
|
||||||
@ -1009,7 +1012,7 @@ namespace garlic
|
|||||||
{
|
{
|
||||||
auto index = tagset->GetNextIndex ();
|
auto index = tagset->GetNextIndex ();
|
||||||
uint64_t tag = tagset->GetNextSessionTag ();
|
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)
|
void GarlicDestination::AddECIESx25519Session (const uint8_t * staticKey, ECIESX25519AEADRatchetSessionPtr session)
|
||||||
|
@ -220,7 +220,6 @@ namespace garlic
|
|||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
RatchetTagSetPtr tagset;
|
RatchetTagSetPtr tagset;
|
||||||
uint64_t creationTime; // seconds since epoch
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class GarlicDestination: public i2p::data::LocalDestination
|
class GarlicDestination: public i2p::data::LocalDestination
|
||||||
|
Loading…
Reference in New Issue
Block a user