mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-13 04:46:38 +01:00
remove expired session through one pass
This commit is contained in:
parent
bee407ea34
commit
a4762fe65c
1 changed files with 12 additions and 17 deletions
27
Datagram.cpp
27
Datagram.cpp
|
@ -118,25 +118,20 @@ namespace datagram
|
||||||
|
|
||||||
void DatagramDestination::CleanUp ()
|
void DatagramDestination::CleanUp ()
|
||||||
{
|
{
|
||||||
std::vector<i2p::data::IdentHash> expiredSessions;
|
auto now = i2p::util::GetMillisecondsSinceEpoch();
|
||||||
|
LogPrint(eLogDebug, "DatagramDestination: clean up sessions");
|
||||||
|
std::lock_guard<std::mutex> lock(m_SessionsMutex);
|
||||||
|
// for each session ...
|
||||||
|
for (auto it = m_Sessions.begin (); it != m_Sessions.end (); )
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_SessionsMutex);
|
// check if expired
|
||||||
auto now = i2p::util::GetMillisecondsSinceEpoch();
|
if (now - it->second->LastActivity() >= DATAGRAM_SESSION_MAX_IDLE)
|
||||||
LogPrint(eLogDebug, "DatagramDestination: clean up sessions");
|
|
||||||
// for each session ...
|
|
||||||
for (auto & e : m_Sessions)
|
|
||||||
{
|
{
|
||||||
// check if expired
|
LogPrint(eLogInfo, "DatagramDestination: expiring idle session with ", it->first.ToBase32());
|
||||||
if(now - e.second->LastActivity() >= DATAGRAM_SESSION_MAX_IDLE)
|
it = m_Sessions.erase (it); // we are expired
|
||||||
expiredSessions.push_back(e.first); // we are expired
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
// for each expired session ...
|
it++;
|
||||||
for (auto & ident : expiredSessions)
|
|
||||||
{
|
|
||||||
// remove the expired session
|
|
||||||
LogPrint(eLogInfo, "DatagramDestination: expiring idle session with ", ident.ToBase32());
|
|
||||||
m_Sessions.erase(ident);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue