@ -6,6 +6,7 @@
@@ -6,6 +6,7 @@
# include "I2NPProtocol.h"
# include "Transports.h"
# include "RouterContext.h"
# include "Timestamp.h"
# include "TunnelEndpoint.h"
namespace i2p
@ -192,7 +193,7 @@ namespace tunnel
@@ -192,7 +193,7 @@ namespace tunnel
void TunnelEndpoint : : AddOutOfSequenceFragment ( uint32_t msgID , uint8_t fragmentNum , bool isLastFragment , std : : shared_ptr < I2NPMessage > data )
{
if ( ! m_OutOfSequenceFragments . insert ( { { msgID , fragmentNum } , { fragmentNum , isLastFragment , data } } ) . second )
if ( ! m_OutOfSequenceFragments . insert ( { { msgID , fragmentNum } , { isLastFragment , data , i2p : : util : : GetMillisecondsSinceEpoch ( ) } } ) . second )
LogPrint ( eLogInfo , " TunnelMessage: duplicate out-of-sequence fragment " , fragmentNum , " of message " , msgID ) ;
}
@ -214,9 +215,7 @@ namespace tunnel
@@ -214,9 +215,7 @@ namespace tunnel
auto it = m_OutOfSequenceFragments . find ( { msgID , msg . nextFragmentNum } ) ;
if ( it ! = m_OutOfSequenceFragments . end ( ) )
{
if ( it - > second . fragmentNum = = msg . nextFragmentNum )
{
LogPrint ( eLogDebug , " TunnelMessage: Out-of-sequence fragment " , ( int ) it - > second . fragmentNum , " of message " , msgID , " found " ) ;
LogPrint ( eLogDebug , " TunnelMessage: Out-of-sequence fragment " , ( int ) msg . nextFragmentNum , " of message " , msgID , " found " ) ;
size_t size = it - > second . data - > GetLength ( ) ;
if ( msg . data - > len + size > msg . data - > maxLen )
{
@ -235,9 +234,6 @@ namespace tunnel
@@ -235,9 +234,6 @@ namespace tunnel
m_OutOfSequenceFragments . erase ( it ) ;
return true ;
}
else
LogPrint ( eLogError , " Tunnel message: next fragment " , ( int ) it - > second . fragmentNum , " of message " , msgID , " mismatch. " , ( int ) msg . nextFragmentNum , " expected " ) ;
}
return false ;
}
@ -276,5 +272,18 @@ namespace tunnel
@@ -276,5 +272,18 @@ namespace tunnel
LogPrint ( eLogError , " TunnelMessage: Unknown delivery type " , ( int ) msg . deliveryType ) ;
} ;
}
void TunnelEndpoint : : Cleanup ( )
{
auto ts = i2p : : util : : GetMillisecondsSinceEpoch ( ) ;
// out-of-sequence fragments
for ( auto it = m_OutOfSequenceFragments . begin ( ) ; it ! = m_OutOfSequenceFragments . end ( ) ; )
{
if ( ts > it - > second . receiveTime + i2p : : I2NP_MESSAGE_EXPIRATION_TIMEOUT )
it = m_OutOfSequenceFragments . erase ( it ) ;
else
+ + it ;
}
}
}
}