Browse Source

cleanup routing sessions

pull/151/head
orignal 10 years ago
parent
commit
a25646a129
  1. 39
      Garlic.cpp
  2. 3
      Garlic.h

39
Garlic.cpp

@ -67,18 +67,34 @@ namespace garlic @@ -67,18 +67,34 @@ namespace garlic
m_UnconfirmedTagsMsgs.erase (it);
delete tags;
}
CleanupExpiredTags ();
}
bool GarlicRoutingSession::CleanupExpiredTags ()
{
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
for (auto it = m_SessionTags.begin (); it != m_SessionTags.end ();)
{
if (ts >= it->creationTime + OUTGOING_TAGS_EXPIRATION_TIMEOUT)
it = m_SessionTags.erase (it);
else
it++;
}
// delete expired unconfirmed tags
for (auto it = m_UnconfirmedTagsMsgs.begin (); it != m_UnconfirmedTagsMsgs.end ();)
{
if (ts >= it->second->tagsCreationTime + OUTGOING_TAGS_EXPIRATION_TIMEOUT)
{
if (m_Owner)
m_Owner->RemoveCreatedSession (it->first);
delete it->second;
it = m_UnconfirmedTagsMsgs.erase (it);
}
else
it++;
}
}
return !m_SessionTags.empty () || m_UnconfirmedTagsMsgs.empty ();
}
I2NPMessage * GarlicRoutingSession::WrapSingleMessage (I2NPMessage * msg)
{
@ -149,7 +165,7 @@ namespace garlic @@ -149,7 +165,7 @@ namespace garlic
size_t GarlicRoutingSession::CreateAESBlock (uint8_t * buf, const I2NPMessage * msg)
{
size_t blockSize = 0;
bool createNewTags = m_Owner && m_NumTags && ((int)m_SessionTags.size () <= m_NumTags/2);
bool createNewTags = m_Owner && m_NumTags && ((int)m_SessionTags.size () <= m_NumTags*2/3);
UnconfirmedTags * newTags = createNewTags ? GenerateSessionTags () : nullptr;
htobuf16 (buf, newTags ? htobe16 (newTags->numTags) : 0); // tag count
blockSize += 2;
@ -515,7 +531,24 @@ namespace garlic @@ -515,7 +531,24 @@ namespace garlic
}
return session;
}
void GarlicDestination::CleanupRoutingSessions ()
{
std::unique_lock<std::mutex> l(m_SessionsMutex);
for (auto it = m_Sessions.begin (); it != m_Sessions.end ();)
{
if (!it->second->CleanupExpiredTags ())
it = m_Sessions.erase (it);
else
it++;
}
}
void GarlicDestination::RemoveCreatedSession (uint32_t msgID)
{
m_CreatedSessions.erase (msgID);
}
void GarlicDestination::DeliveryStatusSent (std::shared_ptr<GarlicRoutingSession> session, uint32_t msgID)
{
m_CreatedSessions[msgID] = session;

3
Garlic.h

@ -72,6 +72,7 @@ namespace garlic @@ -72,6 +72,7 @@ namespace garlic
~GarlicRoutingSession ();
I2NPMessage * WrapSingleMessage (I2NPMessage * msg);
void TagsConfirmed (uint32_t msgID);
bool CleanupExpiredTags (); // returns true if something left
void SetLeaseSetUpdated () { m_LeaseSetUpdated = true; };
@ -106,6 +107,8 @@ namespace garlic @@ -106,6 +107,8 @@ namespace garlic
~GarlicDestination ();
std::shared_ptr<GarlicRoutingSession> GetRoutingSession (const i2p::data::RoutingDestination& destination, int numTags);
void CleanupRoutingSessions ();
void RemoveCreatedSession (uint32_t msgID);
I2NPMessage * WrapMessage (const i2p::data::RoutingDestination& destination,
I2NPMessage * msg, bool attachLeaseSet = false);

Loading…
Cancel
Save