mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-24 01:46:36 +02:00
delete expired incoming tags
This commit is contained in:
parent
00d9ef806b
commit
fcd3680547
2 changed files with 28 additions and 5 deletions
24
Garlic.cpp
24
Garlic.cpp
|
@ -148,7 +148,7 @@ namespace garlic
|
||||||
size_t GarlicRoutingSession::CreateAESBlock (uint8_t * buf, const I2NPMessage * msg)
|
size_t GarlicRoutingSession::CreateAESBlock (uint8_t * buf, const I2NPMessage * msg)
|
||||||
{
|
{
|
||||||
size_t blockSize = 0;
|
size_t blockSize = 0;
|
||||||
bool createNewTags = m_Owner && ((int)m_SessionTags.size () <= m_NumTags/4);
|
bool createNewTags = m_Owner && ((int)m_SessionTags.size () <= m_NumTags/2);
|
||||||
UnconfirmedTags * newTags = createNewTags ? GenerateSessionTags () : nullptr;
|
UnconfirmedTags * newTags = createNewTags ? GenerateSessionTags () : nullptr;
|
||||||
*(uint16_t *)buf = newTags ? htobe16 (newTags->numTags) : 0; // tag count
|
*(uint16_t *)buf = newTags ? htobe16 (newTags->numTags) : 0; // tag count
|
||||||
blockSize += 2;
|
blockSize += 2;
|
||||||
|
@ -344,6 +344,28 @@ namespace garlic
|
||||||
LogPrint ("Failed to decrypt garlic");
|
LogPrint ("Failed to decrypt garlic");
|
||||||
}
|
}
|
||||||
DeleteI2NPMessage (msg);
|
DeleteI2NPMessage (msg);
|
||||||
|
|
||||||
|
// cleanup expired tags
|
||||||
|
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
|
if (ts > m_LastTagsCleanupTime + INCOMING_TAGS_EXPIRATION_TIMEOUT)
|
||||||
|
{
|
||||||
|
if (m_LastTagsCleanupTime)
|
||||||
|
{
|
||||||
|
int numExpiredTags = 0;
|
||||||
|
for (auto it = m_Tags.begin (); it != m_Tags.end ();)
|
||||||
|
{
|
||||||
|
if (ts > it->first.creationTime + INCOMING_TAGS_EXPIRATION_TIMEOUT)
|
||||||
|
{
|
||||||
|
numExpiredTags++;
|
||||||
|
it = m_Tags.erase (it);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
LogPrint (numExpiredTags, " tags expired for ", GetIdentHash().ToBase64 ());
|
||||||
|
}
|
||||||
|
m_LastTagsCleanupTime = ts;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GarlicDestination::HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr<i2p::crypto::CBCDecryption> decryption,
|
void GarlicDestination::HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr<i2p::crypto::CBCDecryption> decryption,
|
||||||
|
|
5
Garlic.h
5
Garlic.h
|
@ -37,7 +37,7 @@ namespace garlic
|
||||||
};
|
};
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
const int INCOMING_TAGS_EXPIRATION_TIMEOUT = 900; // 15 minutes
|
const int INCOMING_TAGS_EXPIRATION_TIMEOUT = 960; // 16 minutes
|
||||||
const int OUTGOING_TAGS_EXPIRATION_TIMEOUT = 720; // 12 minutes
|
const int OUTGOING_TAGS_EXPIRATION_TIMEOUT = 720; // 12 minutes
|
||||||
|
|
||||||
struct SessionTag: public i2p::data::Tag<32>
|
struct SessionTag: public i2p::data::Tag<32>
|
||||||
|
@ -102,7 +102,7 @@ namespace garlic
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GarlicDestination () {};
|
GarlicDestination (): m_LastTagsCleanupTime (0) {};
|
||||||
~GarlicDestination ();
|
~GarlicDestination ();
|
||||||
|
|
||||||
GarlicRoutingSession * GetRoutingSession (const i2p::data::RoutingDestination& destination, int numTags);
|
GarlicRoutingSession * GetRoutingSession (const i2p::data::RoutingDestination& destination, int numTags);
|
||||||
|
@ -137,6 +137,7 @@ namespace garlic
|
||||||
std::map<i2p::data::IdentHash, GarlicRoutingSession *> m_Sessions;
|
std::map<i2p::data::IdentHash, GarlicRoutingSession *> m_Sessions;
|
||||||
// incoming
|
// incoming
|
||||||
std::map<SessionTag, std::shared_ptr<i2p::crypto::CBCDecryption>> m_Tags;
|
std::map<SessionTag, std::shared_ptr<i2p::crypto::CBCDecryption>> m_Tags;
|
||||||
|
uint32_t m_LastTagsCleanupTime;
|
||||||
// DeliveryStatus
|
// DeliveryStatus
|
||||||
std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session
|
std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue