1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-22 04:04:16 +00:00

limit SSU message size to 32K

This commit is contained in:
orignal 2018-10-11 11:17:14 -04:00
parent a97300f8be
commit b84f74c167
3 changed files with 10 additions and 3 deletions

View File

@ -320,7 +320,7 @@ namespace transport
uint8_t * msgBuf = msg->GetSSUHeader ();
uint32_t fragmentNum = 0;
while (len > 0)
while (len > 0 && fragmentNum <= 127)
{
Fragment * fragment = new Fragment;
fragment->fragmentNum = fragmentNum;
@ -332,7 +332,7 @@ namespace transport
payload++;
htobe32buf (payload, msgID);
payload += 4;
bool isLast = (len <= payloadSize);
bool isLast = (len <= payloadSize) || fragmentNum == 127; // 127 fragments max
size_t size = isLast ? len : payloadSize;
uint32_t fragmentInfo = (fragmentNum << 17);
if (isLast)

View File

@ -929,7 +929,13 @@ namespace transport
if (m_State == eSessionStateEstablished)
{
for (const auto& it: msgs)
if (it) m_Data.Send (it);
if (it)
{
if (it->GetLength () <= SSU_MAX_I2NP_MESSAGE_SIZE)
m_Data.Send (it);
else
LogPrint (eLogError, "SSU: I2NP message of size ", it->GetLength (), " can't be sent. Dropped");
}
}
}

View File

@ -28,6 +28,7 @@ namespace transport
const int SSU_CONNECT_TIMEOUT = 5; // 5 seconds
const int SSU_TERMINATION_TIMEOUT = 330; // 5.5 minutes
const int SSU_CLOCK_SKEW = 60; // in seconds
const size_t SSU_MAX_I2NP_MESSAGE_SIZE = 32768;
// payload types (4 bits)
const uint8_t PAYLOAD_TYPE_SESSION_REQUEST = 0;