Browse Source

MTU for ipv6

pull/106/head
orignal 10 years ago
parent
commit
d84a7ebc7e
  1. 3
      SSU.h
  2. 10
      SSUData.cpp
  3. 11
      SSUData.h

3
SSU.h

@ -72,6 +72,7 @@ namespace transport
void WaitForIntroduction (); void WaitForIntroduction ();
void Close (); void Close ();
boost::asio::ip::udp::endpoint& GetRemoteEndpoint () { return m_RemoteEndpoint; }; boost::asio::ip::udp::endpoint& GetRemoteEndpoint () { return m_RemoteEndpoint; };
bool IsV6 () const { return m_RemoteEndpoint.address ().is_v6 (); };
void SendI2NPMessage (I2NPMessage * msg); void SendI2NPMessage (I2NPMessage * msg);
void SendPeerTest (); // Alice void SendPeerTest (); // Alice
@ -188,7 +189,7 @@ namespace transport
boost::asio::ip::udp::endpoint m_SenderEndpoint; boost::asio::ip::udp::endpoint m_SenderEndpoint;
boost::asio::deadline_timer m_IntroducersUpdateTimer; boost::asio::deadline_timer m_IntroducersUpdateTimer;
std::list<boost::asio::ip::udp::endpoint> m_Introducers; // introducers we are connected to std::list<boost::asio::ip::udp::endpoint> m_Introducers; // introducers we are connected to
uint8_t m_ReceiveBuffer[2*SSU_MTU]; uint8_t m_ReceiveBuffer[2*SSU_MTU_V4];
std::map<boost::asio::ip::udp::endpoint, SSUSession *> m_Sessions; std::map<boost::asio::ip::udp::endpoint, SSUSession *> m_Sessions;
std::map<uint32_t, boost::asio::ip::udp::endpoint> m_Relays; // we are introducer std::map<uint32_t, boost::asio::ip::udp::endpoint> m_Relays; // we are introducer

10
SSUData.cpp

@ -13,7 +13,8 @@ namespace transport
SSUData::SSUData (SSUSession& session): SSUData::SSUData (SSUSession& session):
m_Session (session), m_ResendTimer (session.m_Server.GetService ()) m_Session (session), m_ResendTimer (session.m_Server.GetService ())
{ {
m_PacketSize = SSU_MAX_PACKET_SIZE; m_MaxPacketSize = session.IsV6 () ? SSU_V6_MAX_PACKET_SIZE : SSU_V4_MAX_PACKET_SIZE;
m_PacketSize = m_MaxPacketSize;
auto remoteRouter = session.GetRemoteRouter (); auto remoteRouter = session.GetRemoteRouter ();
if (remoteRouter) if (remoteRouter)
AdjustPacketSize (*remoteRouter); AdjustPacketSize (*remoteRouter);
@ -36,19 +37,22 @@ namespace transport
auto ssuAddress = remoteRouter.GetSSUAddress (); auto ssuAddress = remoteRouter.GetSSUAddress ();
if (ssuAddress && ssuAddress->mtu) if (ssuAddress && ssuAddress->mtu)
{ {
if (m_Session.IsV6 ())
m_PacketSize = ssuAddress->mtu - IPV6_HEADER_SIZE - UDP_HEADER_SIZE;
else
m_PacketSize = ssuAddress->mtu - IPV4_HEADER_SIZE - UDP_HEADER_SIZE; m_PacketSize = ssuAddress->mtu - IPV4_HEADER_SIZE - UDP_HEADER_SIZE;
if (m_PacketSize > 0) if (m_PacketSize > 0)
{ {
// make sure packet size multiple of 16 // make sure packet size multiple of 16
m_PacketSize >>= 4; m_PacketSize >>= 4;
m_PacketSize <<= 4; m_PacketSize <<= 4;
if (m_PacketSize > (int)SSU_MAX_PACKET_SIZE) m_PacketSize = SSU_MAX_PACKET_SIZE; if (m_PacketSize > m_MaxPacketSize) m_PacketSize = m_MaxPacketSize;
LogPrint ("MTU=", ssuAddress->mtu, " packet size=", m_PacketSize); LogPrint ("MTU=", ssuAddress->mtu, " packet size=", m_PacketSize);
} }
else else
{ {
LogPrint (eLogWarning, "Unexpected MTU ", ssuAddress->mtu); LogPrint (eLogWarning, "Unexpected MTU ", ssuAddress->mtu);
m_PacketSize = SSU_MAX_PACKET_SIZE; m_PacketSize = m_MaxPacketSize;
} }
} }
} }

11
SSUData.h

@ -16,10 +16,13 @@ namespace i2p
namespace transport namespace transport
{ {
const size_t SSU_MTU = 1484; const size_t SSU_MTU_V4 = 1484;
const size_t SSU_MTU_V6 = 1472;
const size_t IPV4_HEADER_SIZE = 20; const size_t IPV4_HEADER_SIZE = 20;
const size_t IPV6_HEADER_SIZE = 40;
const size_t UDP_HEADER_SIZE = 8; const size_t UDP_HEADER_SIZE = 8;
const size_t SSU_MAX_PACKET_SIZE = SSU_MTU - IPV4_HEADER_SIZE - UDP_HEADER_SIZE; // 1456 const size_t SSU_V4_MAX_PACKET_SIZE = SSU_MTU_V4 - IPV4_HEADER_SIZE - UDP_HEADER_SIZE; // 1456
const size_t SSU_V6_MAX_PACKET_SIZE = SSU_MTU_V6 - IPV6_HEADER_SIZE - UDP_HEADER_SIZE; // 1424
const int RESEND_INTERVAL = 3; // in seconds const int RESEND_INTERVAL = 3; // in seconds
const int MAX_NUM_RESENDS = 5; const int MAX_NUM_RESENDS = 5;
// data flags // data flags
@ -35,7 +38,7 @@ namespace transport
int fragmentNum; int fragmentNum;
size_t len; size_t len;
bool isLast; bool isLast;
uint8_t buf[SSU_MAX_PACKET_SIZE + 18]; uint8_t buf[SSU_V4_MAX_PACKET_SIZE + 18]; // use biggest
Fragment () = default; Fragment () = default;
Fragment (int n, const uint8_t * b, int l, bool last): Fragment (int n, const uint8_t * b, int l, bool last):
@ -102,7 +105,7 @@ namespace transport
std::map<uint32_t, SentMessage *> m_SentMessages; std::map<uint32_t, SentMessage *> m_SentMessages;
std::set<uint32_t> m_ReceivedMessages; std::set<uint32_t> m_ReceivedMessages;
boost::asio::deadline_timer m_ResendTimer; boost::asio::deadline_timer m_ResendTimer;
int m_PacketSize; int m_MaxPacketSize, m_PacketSize;
}; };
} }
} }

Loading…
Cancel
Save