mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
cleanup previous tagsets
This commit is contained in:
parent
17e69e67b1
commit
ec4e17f75c
3 changed files with 23 additions and 10 deletions
|
@ -78,6 +78,12 @@ namespace garlic
|
||||||
LogPrint (eLogError, "Garlic: Missing symmetric key for index ", index);
|
LogPrint (eLogError, "Garlic: Missing symmetric key for index ", index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RatchetTagSet::Expire ()
|
||||||
|
{
|
||||||
|
if (!m_ExpirationTimestamp)
|
||||||
|
m_ExpirationTimestamp = i2p::util::GetSecondsSinceEpoch () + ECIESX25519_PREVIOUS_TAGSET_EXPIRATION_TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
ECIESX25519AEADRatchetSession::ECIESX25519AEADRatchetSession (GarlicDestination * owner, bool attachLeaseSet):
|
ECIESX25519AEADRatchetSession::ECIESX25519AEADRatchetSession (GarlicDestination * owner, bool attachLeaseSet):
|
||||||
GarlicRoutingSession (owner, attachLeaseSet)
|
GarlicRoutingSession (owner, attachLeaseSet)
|
||||||
|
@ -311,7 +317,8 @@ namespace garlic
|
||||||
newTagset->SetTagSetID (tagsetID);
|
newTagset->SetTagSetID (tagsetID);
|
||||||
newTagset->DHInitialize (receiveTagset->GetNextRootKey (), tagsetKey);
|
newTagset->DHInitialize (receiveTagset->GetNextRootKey (), tagsetKey);
|
||||||
newTagset->NextSessionTagRatchet ();
|
newTagset->NextSessionTagRatchet ();
|
||||||
GenerateMoreReceiveTags (newTagset, ECIESX25519_MAX_NUM_GENERATED_TAGS);
|
GenerateMoreReceiveTags (newTagset, ECIESX25519_MAX_NUM_GENERATED_TAGS);
|
||||||
|
receiveTagset->Expire ();
|
||||||
LogPrint (eLogDebug, "Garlic: next receive tagset ", tagsetID, " created");
|
LogPrint (eLogDebug, "Garlic: next receive tagset ", tagsetID, " created");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -608,6 +615,7 @@ namespace garlic
|
||||||
case eSessionStateNew:
|
case eSessionStateNew:
|
||||||
return HandleNewIncomingSession (buf, len);
|
return HandleNewIncomingSession (buf, len);
|
||||||
case eSessionStateNewSessionSent:
|
case eSessionStateNewSessionSent:
|
||||||
|
receiveTagset->Expire (); // NSR tagset
|
||||||
return HandleNewOutgoingSessionReply (buf, len);
|
return HandleNewOutgoingSessionReply (buf, len);
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -17,6 +17,15 @@ namespace i2p
|
||||||
{
|
{
|
||||||
namespace garlic
|
namespace garlic
|
||||||
{
|
{
|
||||||
|
const int ECIESX25519_RESTART_TIMEOUT = 120; // number of second of inactivity we should restart after
|
||||||
|
const int ECIESX25519_EXPIRATION_TIMEOUT = 480; // in seconds
|
||||||
|
const int ECIESX25519_INCOMING_TAGS_EXPIRATION_TIMEOUT = 600; // in seconds
|
||||||
|
const int ECIESX25519_PREVIOUS_TAGSET_EXPIRATION_TIMEOUT = 180; // 180
|
||||||
|
const int ECIESX25519_TAGSET_MAX_NUM_TAGS = 1024; // number of tags we request new tagset after
|
||||||
|
const int ECIESX25519_MIN_NUM_GENERATED_TAGS = 24;
|
||||||
|
const int ECIESX25519_MAX_NUM_GENERATED_TAGS = 160;
|
||||||
|
const int ECIESX25519_NSR_NUM_GENERATED_TAGS = 12;
|
||||||
|
|
||||||
class ECIESX25519AEADRatchetSession;
|
class ECIESX25519AEADRatchetSession;
|
||||||
class RatchetTagSet
|
class RatchetTagSet
|
||||||
{
|
{
|
||||||
|
@ -34,6 +43,9 @@ 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 Expire ();
|
||||||
|
bool IsExpired (uint64_t ts) const { return m_ExpirationTimestamp && ts > m_ExpirationTimestamp; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -52,6 +64,7 @@ namespace garlic
|
||||||
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;
|
||||||
|
uint64_t m_ExpirationTimestamp = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ECIESx25519BlockType
|
enum ECIESx25519BlockType
|
||||||
|
@ -71,14 +84,6 @@ namespace garlic
|
||||||
const uint8_t ECIESX25519_NEXT_KEY_REVERSE_KEY_FLAG = 0x02;
|
const uint8_t ECIESX25519_NEXT_KEY_REVERSE_KEY_FLAG = 0x02;
|
||||||
const uint8_t ECIESX25519_NEXT_KEY_REQUEST_REVERSE_KEY_FLAG = 0x04;
|
const uint8_t ECIESX25519_NEXT_KEY_REQUEST_REVERSE_KEY_FLAG = 0x04;
|
||||||
|
|
||||||
const int ECIESX25519_RESTART_TIMEOUT = 120; // number of second of inactivity we should restart after
|
|
||||||
const int ECIESX25519_EXPIRATION_TIMEOUT = 480; // in seconds
|
|
||||||
const int ECIESX25519_INCOMING_TAGS_EXPIRATION_TIMEOUT = 600; // in seconds
|
|
||||||
const int ECIESX25519_TAGSET_MAX_NUM_TAGS = 1024; // number of tags we request new tagset after
|
|
||||||
const int ECIESX25519_MIN_NUM_GENERATED_TAGS = 24;
|
|
||||||
const int ECIESX25519_MAX_NUM_GENERATED_TAGS = 160;
|
|
||||||
const int ECIESX25519_NSR_NUM_GENERATED_TAGS = 12;
|
|
||||||
|
|
||||||
class ECIESX25519AEADRatchetSession: public GarlicRoutingSession, public std::enable_shared_from_this<ECIESX25519AEADRatchetSession>
|
class ECIESX25519AEADRatchetSession: public GarlicRoutingSession, public std::enable_shared_from_this<ECIESX25519AEADRatchetSession>
|
||||||
{
|
{
|
||||||
enum SessionState
|
enum SessionState
|
||||||
|
|
|
@ -788,7 +788,7 @@ namespace garlic
|
||||||
// ECIESx25519
|
// ECIESx25519
|
||||||
for (auto it = m_ECIESx25519Tags.begin (); it != m_ECIESx25519Tags.end ();)
|
for (auto it = m_ECIESx25519Tags.begin (); it != m_ECIESx25519Tags.end ();)
|
||||||
{
|
{
|
||||||
if (ts > it->second.creationTime + ECIESX25519_INCOMING_TAGS_EXPIRATION_TIMEOUT)
|
if (it->second.tagset->IsExpired (ts) || ts > it->second.creationTime + ECIESX25519_INCOMING_TAGS_EXPIRATION_TIMEOUT)
|
||||||
it = m_ECIESx25519Tags.erase (it);
|
it = m_ECIESx25519Tags.erase (it);
|
||||||
else
|
else
|
||||||
++it;
|
++it;
|
||||||
|
|
Loading…
Add table
Reference in a new issue