Browse Source

increased I2NP max message size to 32K and check if fragmented message exceeds it

pull/73/merge
orignal 11 years ago
parent
commit
12fbc9cb86
  1. 4
      I2NPProtocol.h
  2. 3
      NTCPSession.h
  3. 4
      Transports.cpp
  4. 10
      TunnelEndpoint.cpp

4
I2NPProtocol.h

@ -100,10 +100,10 @@ namespace tunnel
class InboundTunnel; class InboundTunnel;
} }
const int NTCP_MAX_MESSAGE_SIZE = 16384; const size_t I2NP_MAX_MESSAGE_SIZE = 32768;
struct I2NPMessage struct I2NPMessage
{ {
uint8_t buf[NTCP_MAX_MESSAGE_SIZE]; uint8_t buf[I2NP_MAX_MESSAGE_SIZE];
size_t len, offset; size_t len, offset;
i2p::tunnel::InboundTunnel * from; i2p::tunnel::InboundTunnel * from;

3
NTCPSession.h

@ -62,6 +62,7 @@ namespace ntcp
#pragma pack() #pragma pack()
const size_t NTCP_MAX_MESSAGE_SIZE = 16384;
const int NTCP_TERMINATION_TIMEOUT = 120; // 2 minutes const int NTCP_TERMINATION_TIMEOUT = 120; // 2 minutes
class NTCPSession class NTCPSession
{ {
@ -135,7 +136,7 @@ namespace ntcp
NTCPPhase3 m_Phase3; NTCPPhase3 m_Phase3;
NTCPPhase4 m_Phase4; 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; int m_ReceiveBufferOffset;
i2p::I2NPMessage * m_NextMessage; i2p::I2NPMessage * m_NextMessage;

4
Transports.cpp

@ -230,9 +230,9 @@ namespace i2p
else else
{ {
// existing session not found. create new // existing session not found. create new
// try NTCP first // try NTCP first if message size < 16K
auto address = r->GetNTCPAddress (); 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); auto s = new i2p::ntcp::NTCPClient (m_Service, address->host, address->port, *r);
AddNTCPSession (s); AddNTCPSession (s);

10
TunnelEndpoint.cpp

@ -125,6 +125,13 @@ namespace tunnel
if (fragmentNum == it->second.nextFragmentNum) if (fragmentNum == it->second.nextFragmentNum)
{ {
I2NPMessage * incompleteMessage = it->second.data; 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 memcpy (incompleteMessage->buf + incompleteMessage->len, fragment, size); // concatenate fragment
incompleteMessage->len += size; incompleteMessage->len += size;
if (isLastFragment) if (isLastFragment)
@ -139,7 +146,8 @@ namespace tunnel
else else
{ {
LogPrint ("Unexpected fragment ", fragmentNum, " instead ", it->second.nextFragmentNum, " of message ", msgID, ". Discarded"); 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 else

Loading…
Cancel
Save