Browse Source

correct concatenation of long I2CP messages

pull/511/head
orignal 9 years ago
parent
commit
4d2b535b04
  1. 16
      I2CP.cpp

16
I2CP.cpp

@ -164,25 +164,34 @@ namespace client
Terminate (); Terminate ();
else else
{ {
size_t offset = 0; size_t offset = 0; // from m_Buffer
if (m_NextMessage) if (m_NextMessage)
{ {
if (m_NextMessageOffset + bytes_transferred <= m_NextMessageLen) if (m_NextMessageOffset + bytes_transferred <= m_NextMessageLen)
{ {
memcpy (m_NextMessage + m_NextMessageOffset, m_Buffer, bytes_transferred); memcpy (m_NextMessage + m_NextMessageOffset, m_Buffer, bytes_transferred);
m_NextMessageOffset += bytes_transferred; m_NextMessageOffset += bytes_transferred;
offset = bytes_transferred;
} }
else else
{ {
// m_NextMessage complete
offset = m_NextMessageLen - m_NextMessageOffset; offset = m_NextMessageLen - m_NextMessageOffset;
memcpy (m_NextMessage + m_NextMessageOffset, m_Buffer, offset); memcpy (m_NextMessage + m_NextMessageOffset, m_Buffer, offset);
HandleNextMessage (m_NextMessage); HandleNextMessage (m_NextMessage);
delete[] m_NextMessage; delete[] m_NextMessage;
m_NextMessage = nullptr;
} }
} }
while (offset < bytes_transferred) while (offset < bytes_transferred)
{ {
auto msgLen = bufbe32toh (m_Buffer + offset + I2CP_HEADER_LENGTH_OFFSET) + I2CP_HEADER_SIZE; auto msgLen = bufbe32toh (m_Buffer + offset + I2CP_HEADER_LENGTH_OFFSET) + I2CP_HEADER_SIZE;
if (msgLen > 0xFFFF) // 64K
{
LogPrint (eLogError, "I2CP: message length ", msgLen, " exceeds 64K. Terminated");
Terminate ();
return;
}
if (msgLen <= bytes_transferred - offset) if (msgLen <= bytes_transferred - offset)
{ {
HandleNextMessage (m_Buffer + offset); HandleNextMessage (m_Buffer + offset);
@ -217,6 +226,11 @@ namespace client
m_Destination->Stop (); m_Destination->Stop ();
m_Destination = nullptr; m_Destination = nullptr;
} }
if (m_Socket)
{
m_Socket->close ();
m_Socket = nullptr;
}
m_Owner.RemoveSession (GetSessionID ()); m_Owner.RemoveSession (GetSessionID ());
} }

Loading…
Cancel
Save