Browse Source

check MTU of remote router

pull/97/head
orignal 10 years ago
parent
commit
37e4bc8e5b
  1. 25
      SSUData.cpp
  2. 7
      SSUData.h

25
SSUData.cpp

@ -12,6 +12,29 @@ namespace ssu @@ -12,6 +12,29 @@ namespace ssu
SSUData::SSUData (SSUSession& session):
m_Session (session), m_ResendTimer (session.m_Server.GetService ())
{
m_PacketSize = SSU_MAX_PACKET_SIZE;
auto remoteRouter = session.GetRemoteRouter ();
if (remoteRouter)
{
auto ssuAddress = remoteRouter->GetSSUAddress ();
if (ssuAddress && ssuAddress->mtu)
{
m_PacketSize = ssuAddress->mtu - IPV4_HEADER_SIZE - UDP_HEADER_SIZE;
if (m_PacketSize > 0)
{
// make sure packet size multiple of 16
m_PacketSize >>= 4;
m_PacketSize <<= 4;
if (m_PacketSize > (int)SSU_MAX_PACKET_SIZE) m_PacketSize = SSU_MAX_PACKET_SIZE;
LogPrint ("MTU=", ssuAddress->mtu, " packet size=", m_PacketSize);
}
else
{
LogPrint ("Unexpected MTU ", ssuAddress->mtu);
m_PacketSize = SSU_MAX_PACKET_SIZE;
}
}
}
}
SSUData::~SSUData ()
@ -245,7 +268,7 @@ namespace ssu @@ -245,7 +268,7 @@ namespace ssu
sentMessage->numResends = 0;
auto& fragments = sentMessage->fragments;
msgID = htobe32 (msgID);
size_t payloadSize = SSU_PACKET_SIZE - sizeof (SSUHeader) - 9; // 9 = flag + #frg(1) + messageID(4) + frag info (3)
size_t payloadSize = m_PacketSize - sizeof (SSUHeader) - 9; // 9 = flag + #frg(1) + messageID(4) + frag info (3)
size_t len = msg->GetLength ();
uint8_t * msgBuf = msg->GetSSUHeader ();

7
SSUData.h

@ -15,7 +15,9 @@ namespace ssu @@ -15,7 +15,9 @@ namespace ssu
{
const size_t SSU_MTU = 1484;
const size_t SSU_PACKET_SIZE = SSU_MTU - 20 - 8; // 20 - IPv4 header, 8 - UDP
const size_t IPV4_HEADER_SIZE = 20;
const size_t UDP_HEADER_SIZE = 8;
const size_t SSU_MAX_PACKET_SIZE = SSU_MTU - IPV4_HEADER_SIZE - UDP_HEADER_SIZE; // 1456
const int RESEND_INTERVAL = 3; // in seconds
const int MAX_NUM_RESENDS = 5;
// data flags
@ -31,7 +33,7 @@ namespace ssu @@ -31,7 +33,7 @@ namespace ssu
int fragmentNum;
size_t len;
bool isLast;
uint8_t buf[SSU_PACKET_SIZE + 18];
uint8_t buf[SSU_MAX_PACKET_SIZE + 18];
Fragment () = default;
Fragment (int n, const uint8_t * b, int l, bool last):
@ -93,6 +95,7 @@ namespace ssu @@ -93,6 +95,7 @@ namespace ssu
std::map<uint32_t, IncompleteMessage *> m_IncomleteMessages;
std::map<uint32_t, SentMessage *> m_SentMessages;
boost::asio::deadline_timer m_ResendTimer;
int m_PacketSize;
};
}
}

Loading…
Cancel
Save