Browse Source

receive bigger packets

pull/1776/head
orignal 2 years ago
parent
commit
5026dbc1b3
  1. 2
      libi2pd/SSU2.cpp
  2. 16
      libi2pd/SSU2Session.cpp
  3. 5
      libi2pd/SSU2Session.h

2
libi2pd/SSU2.cpp

@ -175,7 +175,7 @@ namespace transport
while (moreBytes && packets.size () < 32) while (moreBytes && packets.size () < 32)
{ {
packet = m_PacketsPool.AcquireMt (); packet = m_PacketsPool.AcquireMt ();
packet->len = socket.receive_from (boost::asio::buffer (packet->buf, SSU2_MTU), packet->from, 0, ec); packet->len = socket.receive_from (boost::asio::buffer (packet->buf, SSU2_MAX_PACKET_SIZE), packet->from, 0, ec);
if (!ec) if (!ec)
{ {
i2p::transport::transports.UpdateReceivedBytes (packet->len); i2p::transport::transports.UpdateReceivedBytes (packet->len);

16
libi2pd/SSU2Session.cpp

@ -26,7 +26,7 @@ namespace transport
m_SendPacketNum (0), m_ReceivePacketNum (0), m_IsDataReceived (false), m_SendPacketNum (0), m_ReceivePacketNum (0), m_IsDataReceived (false),
m_WindowSize (SSU2_MAX_WINDOW_SIZE), m_RelayTag (0), m_WindowSize (SSU2_MAX_WINDOW_SIZE), m_RelayTag (0),
m_ConnectTimer (server.GetService ()), m_TerminationReason (eSSU2TerminationReasonNormalClose), m_ConnectTimer (server.GetService ()), m_TerminationReason (eSSU2TerminationReasonNormalClose),
m_MaxPayloadSize (SSU2_MAX_PAYLOAD_SIZE) m_MaxPayloadSize (SSU2_MIN_PACKET_SIZE - IPV6_HEADER_SIZE - UDP_HEADER_SIZE - 32) // min size
{ {
m_NoiseState.reset (new i2p::crypto::NoiseSymmetricState); m_NoiseState.reset (new i2p::crypto::NoiseSymmetricState);
if (in_RemoteRouter && m_Address) if (in_RemoteRouter && m_Address)
@ -669,9 +669,9 @@ namespace transport
m_SentHandshakePacket->payloadSize = payloadSize; m_SentHandshakePacket->payloadSize = payloadSize;
if (header.h.flags[0] > 1) if (header.h.flags[0] > 1)
{ {
if (payloadSize > SSU2_MAX_PAYLOAD_SIZE - 64) if (payloadSize > m_MaxPayloadSize - 48)
{ {
payloadSize = SSU2_MAX_PAYLOAD_SIZE - 64 - (rand () % 16); payloadSize = m_MaxPayloadSize - 48 - (rand () % 16);
if (m_SentHandshakePacket->payloadSize - payloadSize < 24) if (m_SentHandshakePacket->payloadSize - payloadSize < 24)
payloadSize -= 24; payloadSize -= 24;
} }
@ -1131,8 +1131,8 @@ namespace transport
memset (header.h.flags, 0, 3); memset (header.h.flags, 0, 3);
uint8_t nonce[12]; uint8_t nonce[12];
CreateNonce (m_SendPacketNum, nonce); CreateNonce (m_SendPacketNum, nonce);
uint8_t payload[SSU2_MTU]; uint8_t payload[SSU2_MAX_PACKET_SIZE];
i2p::crypto::AEADChaCha20Poly1305 (buf, len, header.buf, 16, m_KeyDataSend, nonce, payload, SSU2_MTU, true); i2p::crypto::AEADChaCha20Poly1305 (buf, len, header.buf, 16, m_KeyDataSend, nonce, payload, SSU2_MAX_PACKET_SIZE, true);
header.ll[0] ^= CreateHeaderMask (m_Address->i, payload + (len - 8)); header.ll[0] ^= CreateHeaderMask (m_Address->i, payload + (len - 8));
header.ll[1] ^= CreateHeaderMask (m_KeyDataSend + 32, payload + (len + 4)); header.ll[1] ^= CreateHeaderMask (m_KeyDataSend + 32, payload + (len + 4));
m_Server.Send (header.buf, 16, payload, len + 16, m_RemoteEndpoint); m_Server.Send (header.buf, 16, payload, len + 16, m_RemoteEndpoint);
@ -1154,7 +1154,7 @@ namespace transport
SendQuickAck (); // in case it was SessionConfirmed SendQuickAck (); // in case it was SessionConfirmed
return; return;
} }
uint8_t payload[SSU2_MTU]; uint8_t payload[SSU2_MAX_PACKET_SIZE];
size_t payloadSize = len - 32; size_t payloadSize = len - 32;
uint32_t packetNum = be32toh (header.h.packetNum); uint32_t packetNum = be32toh (header.h.packetNum);
uint8_t nonce[12]; uint8_t nonce[12];
@ -1468,12 +1468,12 @@ namespace transport
i2p::data::netdb.PopulateRouterInfoBuffer (r); i2p::data::netdb.PopulateRouterInfoBuffer (r);
else else
LogPrint (eLogWarning, "SSU2: RelayRequest Alice's router info not found"); LogPrint (eLogWarning, "SSU2: RelayRequest Alice's router info not found");
uint8_t payload[SSU2_MAX_PAYLOAD_SIZE]; uint8_t payload[SSU2_MAX_PACKET_SIZE];
size_t payloadSize = r ? CreateRouterInfoBlock (payload, m_MaxPayloadSize - len - 32, r) : 0; size_t payloadSize = r ? CreateRouterInfoBlock (payload, m_MaxPayloadSize - len - 32, r) : 0;
if (!payloadSize && r) if (!payloadSize && r)
session->SendFragmentedMessage (CreateDatabaseStoreMsg (r)); session->SendFragmentedMessage (CreateDatabaseStoreMsg (r));
payloadSize += CreateRelayIntroBlock (payload + payloadSize, m_MaxPayloadSize - payloadSize, buf + 1, len -1); payloadSize += CreateRelayIntroBlock (payload + payloadSize, m_MaxPayloadSize - payloadSize, buf + 1, len -1);
if (payloadSize < SSU2_MAX_PAYLOAD_SIZE) if (payloadSize < m_MaxPayloadSize)
payloadSize += CreatePaddingBlock (payload + payloadSize, m_MaxPayloadSize - payloadSize); payloadSize += CreatePaddingBlock (payload + payloadSize, m_MaxPayloadSize - payloadSize);
session->SendData (payload, payloadSize); session->SendData (payload, payloadSize);
} }

5
libi2pd/SSU2Session.h

@ -33,8 +33,7 @@ namespace transport
const int SSU2_RELAY_NONCE_EXPIRATION_TIMEOUT = 10; // in seconds const int SSU2_RELAY_NONCE_EXPIRATION_TIMEOUT = 10; // in seconds
const int SSU2_PEER_TEST_EXPIRATION_TIMEOUT = 60; // 60 seconds const int SSU2_PEER_TEST_EXPIRATION_TIMEOUT = 60; // 60 seconds
const size_t SSU2_MAX_PACKET_SIZE = 1500; const size_t SSU2_MAX_PACKET_SIZE = 1500;
const size_t SSU2_MTU = SSU2_MAX_PACKET_SIZE - IPV6_HEADER_SIZE - UDP_HEADER_SIZE; // TODO: ipv4 const size_t SSU2_MIN_PACKET_SIZE = 1280;
const size_t SSU2_MAX_PAYLOAD_SIZE = SSU2_MTU - 32;
const int SSU2_HANDSHAKE_RESEND_INTERVAL = 1; // in seconds const int SSU2_HANDSHAKE_RESEND_INTERVAL = 1; // in seconds
const int SSU2_RESEND_INTERVAL = 3; // in seconds const int SSU2_RESEND_INTERVAL = 3; // in seconds
const int SSU2_MAX_NUM_RESENDS = 5; const int SSU2_MAX_NUM_RESENDS = 5;
@ -153,7 +152,7 @@ namespace transport
{ {
struct Fragment struct Fragment
{ {
uint8_t buf[SSU2_MTU]; uint8_t buf[SSU2_MAX_PACKET_SIZE];
size_t len; size_t len;
bool isLast; bool isLast;
}; };

Loading…
Cancel
Save