mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
increased I2NP max message size to 32K and check if fragmented message exceeds it
This commit is contained in:
parent
d4ac1391fe
commit
12fbc9cb86
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user