From 381f6b184e6ad3e71270d3465518c01956720df9 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 6 Dec 2016 16:23:52 -0500 Subject: [PATCH] clean up incomplete messages --- TunnelEndpoint.cpp | 9 +++++++++ TunnelEndpoint.h | 1 + 2 files changed, 10 insertions(+) diff --git a/TunnelEndpoint.cpp b/TunnelEndpoint.cpp index 23cf16f3..b4ddc109 100644 --- a/TunnelEndpoint.cpp +++ b/TunnelEndpoint.cpp @@ -116,6 +116,7 @@ namespace tunnel if (!isFollowOnFragment) // create new incomlete message { m.nextFragmentNum = 1; + m.receiveTime = i2p::util::GetMillisecondsSinceEpoch (); auto ret = m_IncompleteMessages.insert (std::pair(msgID, m)); if (ret.second) HandleOutOfSequenceFragments (msgID, ret.first->second); @@ -284,6 +285,14 @@ namespace tunnel else ++it; } + // incomplete messages + for (auto it = m_IncompleteMessages.begin (); it != m_IncompleteMessages.end ();) + { + if (ts > it->second.receiveTime + i2p::I2NP_MESSAGE_EXPIRATION_TIMEOUT) + it = m_IncompleteMessages.erase (it); + else + ++it; + } } } } diff --git a/TunnelEndpoint.h b/TunnelEndpoint.h index 60c4fc0a..e13ced34 100644 --- a/TunnelEndpoint.h +++ b/TunnelEndpoint.h @@ -15,6 +15,7 @@ namespace tunnel { struct TunnelMessageBlockEx: public TunnelMessageBlock { + uint64_t receiveTime; // milliseconds since epoch uint8_t nextFragmentNum; };