mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-19 01:09:58 +00:00
remove tag immediately after use
This commit is contained in:
parent
3873e60cbb
commit
ff3fec9a00
@ -431,8 +431,7 @@ namespace garlic
|
|||||||
}
|
}
|
||||||
|
|
||||||
GarlicDestination::GarlicDestination (): m_NumTags (32), // 32 tags by default
|
GarlicDestination::GarlicDestination (): m_NumTags (32), // 32 tags by default
|
||||||
m_PayloadBuffer (nullptr), m_NumRatchetInboundTags (0), // 0 means standard
|
m_PayloadBuffer (nullptr), m_NumRatchetInboundTags (0) // 0 means standard
|
||||||
m_NumUsedECIESx25519Tags (0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,18 +588,11 @@ namespace garlic
|
|||||||
auto it = m_ECIESx25519Tags.find (tag);
|
auto it = m_ECIESx25519Tags.find (tag);
|
||||||
if (it != m_ECIESx25519Tags.end ())
|
if (it != m_ECIESx25519Tags.end ())
|
||||||
{
|
{
|
||||||
if (!it->second.tagset) return true; // duplicate
|
if (it->second.tagset && it->second.tagset->HandleNextMessage (buf, len, it->second.index))
|
||||||
if (it->second.tagset->HandleNextMessage (buf, len, it->second.index))
|
|
||||||
{
|
|
||||||
m_LastTagset = it->second.tagset;
|
m_LastTagset = it->second.tagset;
|
||||||
it->second.tagset = nullptr; // mark as used
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
LogPrint (eLogError, "Garlic: Can't handle ECIES-X25519-AEAD-Ratchet message");
|
LogPrint (eLogError, "Garlic: Can't handle ECIES-X25519-AEAD-Ratchet message");
|
||||||
m_ECIESx25519Tags.erase (it);
|
m_ECIESx25519Tags.erase (it);
|
||||||
}
|
|
||||||
m_NumUsedECIESx25519Tags++;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -885,41 +877,18 @@ namespace garlic
|
|||||||
}
|
}
|
||||||
|
|
||||||
numExpiredTags = 0;
|
numExpiredTags = 0;
|
||||||
if (m_NumUsedECIESx25519Tags > ECIESX25519_TAGSET_MAX_NUM_TAGS) // too many used tags
|
for (auto it = m_ECIESx25519Tags.begin (); it != m_ECIESx25519Tags.end ();)
|
||||||
{
|
{
|
||||||
std::unordered_map<uint64_t, ECIESX25519AEADRatchetIndexTagset> oldTags;
|
if (it->second.tagset->IsExpired (ts) || it->second.tagset->IsIndexExpired (it->second.index))
|
||||||
std::swap (m_ECIESx25519Tags, oldTags); // re-create
|
|
||||||
for (auto& it: oldTags)
|
|
||||||
if (it.second.tagset)
|
|
||||||
{
|
|
||||||
if (it.second.tagset->IsExpired (ts) || it.second.tagset->IsIndexExpired (it.second.index))
|
|
||||||
{
|
|
||||||
it.second.tagset->DeleteSymmKey (it.second.index);
|
|
||||||
numExpiredTags++;
|
|
||||||
}
|
|
||||||
else if (it.second.tagset->IsSessionTerminated())
|
|
||||||
numExpiredTags++;
|
|
||||||
else
|
|
||||||
m_ECIESx25519Tags.emplace (it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (auto it = m_ECIESx25519Tags.begin (); it != m_ECIESx25519Tags.end ();)
|
|
||||||
{
|
{
|
||||||
if (!it->second.tagset)
|
it->second.tagset->DeleteSymmKey (it->second.index);
|
||||||
{
|
it = m_ECIESx25519Tags.erase (it);
|
||||||
// delete used tag
|
numExpiredTags++;
|
||||||
it = m_ECIESx25519Tags.erase (it);
|
}
|
||||||
continue;
|
else
|
||||||
}
|
{
|
||||||
if (it->second.tagset->IsExpired (ts) || it->second.tagset->IsIndexExpired (it->second.index))
|
auto session = it->second.tagset->GetSession ();
|
||||||
{
|
if (!session || session->IsTerminated())
|
||||||
it->second.tagset->DeleteSymmKey (it->second.index);
|
|
||||||
it = m_ECIESx25519Tags.erase (it);
|
|
||||||
numExpiredTags++;
|
|
||||||
}
|
|
||||||
else if (it->second.tagset->IsSessionTerminated())
|
|
||||||
{
|
{
|
||||||
it = m_ECIESx25519Tags.erase (it);
|
it = m_ECIESx25519Tags.erase (it);
|
||||||
numExpiredTags++;
|
numExpiredTags++;
|
||||||
@ -927,8 +896,7 @@ namespace garlic
|
|||||||
else
|
else
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_NumUsedECIESx25519Tags = 0;
|
|
||||||
if (numExpiredTags > 0)
|
if (numExpiredTags > 0)
|
||||||
LogPrint (eLogDebug, "Garlic: ", numExpiredTags, " ECIESx25519 tags expired for ", GetIdentHash().ToBase64 ());
|
LogPrint (eLogDebug, "Garlic: ", numExpiredTags, " ECIESx25519 tags expired for ", GetIdentHash().ToBase64 ());
|
||||||
if (m_LastTagset && m_LastTagset->IsExpired (ts))
|
if (m_LastTagset && m_LastTagset->IsExpired (ts))
|
||||||
|
@ -291,7 +291,6 @@ namespace garlic
|
|||||||
std::unordered_map<SessionTag, std::shared_ptr<AESDecryption>, std::hash<i2p::data::Tag<32> > > m_Tags;
|
std::unordered_map<SessionTag, std::shared_ptr<AESDecryption>, std::hash<i2p::data::Tag<32> > > m_Tags;
|
||||||
std::unordered_map<uint64_t, ECIESX25519AEADRatchetIndexTagset> m_ECIESx25519Tags; // session tag -> session
|
std::unordered_map<uint64_t, ECIESX25519AEADRatchetIndexTagset> m_ECIESx25519Tags; // session tag -> session
|
||||||
ReceiveRatchetTagSetPtr m_LastTagset; // tagset last message came for
|
ReceiveRatchetTagSetPtr m_LastTagset; // tagset last message came for
|
||||||
int m_NumUsedECIESx25519Tags;
|
|
||||||
// DeliveryStatus
|
// DeliveryStatus
|
||||||
std::mutex m_DeliveryStatusSessionsMutex;
|
std::mutex m_DeliveryStatusSessionsMutex;
|
||||||
std::unordered_map<uint32_t, GarlicRoutingSessionPtr> m_DeliveryStatusSessions; // msgID -> session
|
std::unordered_map<uint32_t, GarlicRoutingSessionPtr> m_DeliveryStatusSessions; // msgID -> session
|
||||||
@ -300,7 +299,7 @@ namespace garlic
|
|||||||
|
|
||||||
// for HTTP only
|
// for HTTP only
|
||||||
size_t GetNumIncomingTags () const { return m_Tags.size (); }
|
size_t GetNumIncomingTags () const { return m_Tags.size (); }
|
||||||
size_t GetNumIncomingECIESx25519Tags () const { return m_ECIESx25519Tags.size () - m_NumUsedECIESx25519Tags; }
|
size_t GetNumIncomingECIESx25519Tags () const { return m_ECIESx25519Tags.size (); }
|
||||||
const decltype(m_Sessions)& GetSessions () const { return m_Sessions; };
|
const decltype(m_Sessions)& GetSessions () const { return m_Sessions; };
|
||||||
const decltype(m_ECIESx25519Sessions)& GetECIESx25519Sessions () const { return m_ECIESx25519Sessions; }
|
const decltype(m_ECIESx25519Sessions)& GetECIESx25519Sessions () const { return m_ECIESx25519Sessions; }
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user