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 @@ -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;

3
NTCPSession.h

@ -62,6 +62,7 @@ namespace ntcp @@ -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 @@ -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;

4
Transports.cpp

@ -230,9 +230,9 @@ namespace i2p @@ -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);

10
TunnelEndpoint.cpp

@ -125,6 +125,13 @@ namespace tunnel @@ -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 @@ -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

Loading…
Cancel
Save