From 12fbc9cb862c95b24fa79043189ee6fcaf81946b Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 4 Jul 2014 12:35:02 -0400 Subject: [PATCH] increased I2NP max message size to 32K and check if fragmented message exceeds it --- I2NPProtocol.h | 4 ++-- NTCPSession.h | 3 ++- Transports.cpp | 4 ++-- TunnelEndpoint.cpp | 10 +++++++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/I2NPProtocol.h b/I2NPProtocol.h index 0b6e45d4..42eb85f6 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -100,10 +100,10 @@ namespace tunnel class InboundTunnel; } - const int NTCP_MAX_MESSAGE_SIZE = 16384; + const size_t I2NP_MAX_MESSAGE_SIZE = 32768; struct I2NPMessage { - uint8_t buf[NTCP_MAX_MESSAGE_SIZE]; + uint8_t buf[I2NP_MAX_MESSAGE_SIZE]; size_t len, offset; i2p::tunnel::InboundTunnel * from; diff --git a/NTCPSession.h b/NTCPSession.h index f453c417..4b9e40ce 100644 --- a/NTCPSession.h +++ b/NTCPSession.h @@ -62,6 +62,7 @@ namespace ntcp #pragma pack() + const size_t NTCP_MAX_MESSAGE_SIZE = 16384; const int NTCP_TERMINATION_TIMEOUT = 120; // 2 minutes class NTCPSession { @@ -135,7 +136,7 @@ namespace ntcp NTCPPhase3 m_Phase3; NTCPPhase4 m_Phase4; - uint8_t m_ReceiveBuffer[i2p::NTCP_MAX_MESSAGE_SIZE*2], m_TimeSyncBuffer[16]; + uint8_t m_ReceiveBuffer[NTCP_MAX_MESSAGE_SIZE*2], m_TimeSyncBuffer[16]; int m_ReceiveBufferOffset; i2p::I2NPMessage * m_NextMessage; diff --git a/Transports.cpp b/Transports.cpp index e0763aac..54562fc7 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -230,9 +230,9 @@ namespace i2p else { // existing session not found. create new - // try NTCP first + // try NTCP first if message size < 16K auto address = r->GetNTCPAddress (); - if (address && !r->UsesIntroducer () && !r->IsUnreachable ()) + if (address && !r->UsesIntroducer () && !r->IsUnreachable () && msg->GetLength () < i2p::ntcp::NTCP_MAX_MESSAGE_SIZE) { auto s = new i2p::ntcp::NTCPClient (m_Service, address->host, address->port, *r); AddNTCPSession (s); diff --git a/TunnelEndpoint.cpp b/TunnelEndpoint.cpp index 82495a8e..86106dd5 100644 --- a/TunnelEndpoint.cpp +++ b/TunnelEndpoint.cpp @@ -125,6 +125,13 @@ namespace tunnel if (fragmentNum == it->second.nextFragmentNum) { I2NPMessage * incompleteMessage = it->second.data; + if (incompleteMessage->len + size >= I2NP_MAX_MESSAGE_SIZE) + { + LogPrint ("Fragment ", fragmentNum, " of message ", msgID, "exceeds max I2NP message size. Message dropped"); + i2p::DeleteI2NPMessage (it->second.data); + m_IncompleteMessages.erase (it); + continue; + } memcpy (incompleteMessage->buf + incompleteMessage->len, fragment, size); // concatenate fragment incompleteMessage->len += size; if (isLastFragment) @@ -139,7 +146,8 @@ namespace tunnel else { LogPrint ("Unexpected fragment ", fragmentNum, " instead ", it->second.nextFragmentNum, " of message ", msgID, ". Discarded"); - m_IncompleteMessages.erase (it); // TODO: store unexpect fragment for a while + i2p::DeleteI2NPMessage (it->second.data); + m_IncompleteMessages.erase (it); // TODO: store unexpected fragment for a while } } else