Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Packet++/header/TcpReassembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ namespace pcpp
};

using ConnectionList = std::unordered_map<uint32_t, TcpReassemblyData>;
using CleanupList = std::map<time_t, std::list<uint32_t>>;
using CleanupList = std::multimap<time_t, uint32_t>;
Comment thread
Dimi1010 marked this conversation as resolved.
Outdated

OnTcpMessageReady m_OnMessageReadyCallback;
OnTcpConnectionStart m_OnConnStart;
Expand Down
43 changes: 17 additions & 26 deletions Packet++/src/TcpReassembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,16 +798,14 @@ namespace pcpp

void TcpReassembly::insertIntoCleanupList(uint32_t flowKey)
{
// m_CleanupList is a map with key of type time_t (expiration time). The mapped type is a list that stores the
// flow keys to be cleared in certain point of time. m_CleanupList.insert inserts an empty list if the container
// does not already contain an element with an equivalent key, otherwise this method returns an iterator to the
// element that prevents insertion.
std::pair<CleanupList::iterator, bool> pair =
m_CleanupList.insert(std::make_pair(time(nullptr) + m_ClosedConnectionDelay, CleanupList::mapped_type()));

// getting the reference to list
CleanupList::mapped_type& keysList = pair.first->second;
keysList.push_front(flowKey);
// m_CleanupList is a multimap with key of type time_t (expiration time) and a value type uint32_t (flow key).
// Due to being a multimap, multiple flow keys can have the same expiration time.
//
// During purge, up to 'maxNumToClean' entries with expiration time smaller than the current time will be
// removed from storage.

auto expireTime = time(nullptr) + m_ClosedConnectionDelay;
m_CleanupList.insert(std::make_pair(expireTime, flowKey));
Comment thread
Dimi1010 marked this conversation as resolved.
Outdated
}

uint32_t TcpReassembly::purgeClosedConnections(uint32_t maxNumToClean)
Expand All @@ -817,25 +815,18 @@ namespace pcpp
if (maxNumToClean == 0)
maxNumToClean = m_MaxNumToClean;

CleanupList::iterator iterTime = m_CleanupList.begin(), iterTimeEnd = m_CleanupList.upper_bound(time(nullptr));
while (iterTime != iterTimeEnd && count < maxNumToClean)
{
CleanupList::mapped_type& keysList = iterTime->second;
auto it = m_CleanupList.begin();
auto itEnd = m_CleanupList.upper_bound(time(nullptr));

for (; !keysList.empty() && count < maxNumToClean; ++count)
{
CleanupList::mapped_type::const_reference key = keysList.front();
m_ConnectionInfo.erase(key);
m_ConnectionList.erase(key);
keysList.pop_front();
}

if (keysList.empty())
m_CleanupList.erase(iterTime++);
else
++iterTime;
for (; it != itEnd && count < maxNumToClean; ++it, ++count)
{
auto flowKey = it->second;
m_ConnectionInfo.erase(flowKey);
m_ConnectionList.erase(flowKey);
}

m_CleanupList.erase(m_CleanupList.begin(), it);

return count;
}

Expand Down
Loading