Browse Source

fixed #1256 I2NP messages up to 64K

pull/1258/head
orignal 6 years ago
parent
commit
a97300f8be
  1. 2
      libi2pd/I2NPProtocol.cpp
  2. 2
      libi2pd/I2NPProtocol.h
  3. 12
      libi2pd/NTCP2.cpp

2
libi2pd/I2NPProtocol.cpp

@ -36,7 +36,7 @@ namespace i2p
std::shared_ptr<I2NPMessage> NewI2NPMessage (size_t len) std::shared_ptr<I2NPMessage> NewI2NPMessage (size_t len)
{ {
return (len < I2NP_MAX_SHORT_MESSAGE_SIZE/2) ? NewI2NPShortMessage () : NewI2NPMessage (); return (len < I2NP_MAX_SHORT_MESSAGE_SIZE - I2NP_HEADER_SIZE - 2) ? NewI2NPShortMessage () : NewI2NPMessage ();
} }
void I2NPMessage::FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID) void I2NPMessage::FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID)

2
libi2pd/I2NPProtocol.h

@ -106,7 +106,7 @@ namespace tunnel
class TunnelPool; class TunnelPool;
} }
const size_t I2NP_MAX_MESSAGE_SIZE = 32768; const size_t I2NP_MAX_MESSAGE_SIZE = 62708;
const size_t I2NP_MAX_SHORT_MESSAGE_SIZE = 4096; const size_t I2NP_MAX_SHORT_MESSAGE_SIZE = 4096;
const unsigned int I2NP_MESSAGE_EXPIRATION_TIMEOUT = 8000; // in milliseconds (as initial RTT) const unsigned int I2NP_MESSAGE_EXPIRATION_TIMEOUT = 8000; // in milliseconds (as initial RTT)
const unsigned int I2NP_MESSAGE_CLOCK_SKEW = 60*1000; // 1 minute in milliseconds const unsigned int I2NP_MESSAGE_CLOCK_SKEW = 60*1000; // 1 minute in milliseconds

12
libi2pd/NTCP2.cpp

@ -900,6 +900,11 @@ namespace transport
case eNTCP2BlkI2NPMessage: case eNTCP2BlkI2NPMessage:
{ {
LogPrint (eLogDebug, "NTCP2: I2NP"); LogPrint (eLogDebug, "NTCP2: I2NP");
if (size > I2NP_MAX_MESSAGE_SIZE)
{
LogPrint (eLogError, "NTCP2: I2NP block is too long ", size);
break;
}
auto nextMsg = NewI2NPMessage (size); auto nextMsg = NewI2NPMessage (size);
nextMsg->len = nextMsg->offset + size + 7; // 7 more bytes for full I2NP header nextMsg->len = nextMsg->offset + size + 7; // 7 more bytes for full I2NP header
memcpy (nextMsg->GetNTCP2Header (), frame + offset, size); memcpy (nextMsg->GetNTCP2Header (), frame + offset, size);
@ -993,6 +998,11 @@ namespace transport
s += len; s += len;
m_SendQueue.pop_front (); m_SendQueue.pop_front ();
} }
else if (len + 3 > NTCP2_UNENCRYPTED_FRAME_MAX_SIZE)
{
LogPrint (eLogError, "NTCP2: I2NP message of size ", len, " can't be sent. Dropped");
m_SendQueue.pop_front ();
}
else else
break; break;
} }
@ -1122,7 +1132,7 @@ namespace transport
auto conn = std::make_shared<NTCP2Session> (*this); auto conn = std::make_shared<NTCP2Session> (*this);
m_NTCP2V6Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCP2Server::HandleAcceptV6, this, conn, std::placeholders::_1)); m_NTCP2V6Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCP2Server::HandleAcceptV6, this, conn, std::placeholders::_1));
} catch ( std::exception & ex ) { } catch ( std::exception & ex ) {
LogPrint(eLogError, "NTCP: failed to bind to ip6 port ", address->port); LogPrint(eLogError, "NTCP2: failed to bind to ip6 port ", address->port);
continue; continue;
} }
} }

Loading…
Cancel
Save