Browse Source

limit number of resent packets. Resend interval variance

pull/1791/head
orignal 2 years ago
parent
commit
4634bff9f0
  1. 14
      libi2pd/SSU2.cpp
  2. 7
      libi2pd/SSU2.h
  3. 10
      libi2pd/SSU2Session.cpp
  4. 2
      libi2pd/SSU2Session.h

14
libi2pd/SSU2.cpp

@ -86,6 +86,7 @@ namespace transport @@ -86,6 +86,7 @@ namespace transport
if (found)
m_ReceiveService.Start ();
ScheduleTermination ();
ScheduleResend (false);
}
}
@ -749,9 +750,10 @@ namespace transport @@ -749,9 +750,10 @@ namespace transport
}
}
void SSU2Server::ScheduleResend ()
void SSU2Server::ScheduleResend (bool more)
{
m_ResendTimer.expires_from_now (boost::posix_time::milliseconds(SSU2_RESEND_CHECK_TIMEOUT));
m_ResendTimer.expires_from_now (boost::posix_time::milliseconds (more ? SSU2_RESEND_CHECK_MORE_TIMEOUT :
(SSU2_RESEND_CHECK_TIMEOUT + rand () % SSU2_RESEND_CHECK_TIMEOUT_VARIANCE)));
m_ResendTimer.async_wait (std::bind (&SSU2Server::HandleResendTimer,
this, std::placeholders::_1));
}
@ -760,12 +762,16 @@ namespace transport @@ -760,12 +762,16 @@ namespace transport
{
if (ecode != boost::asio::error::operation_aborted)
{
size_t resentPacketsNum = 0;
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
for (auto it: m_Sessions)
it.second->Resend (ts);
{
resentPacketsNum += it.second->Resend (ts);
if (resentPacketsNum > SSU2_MAX_RESEND_PACKETS) break;
}
for (auto it: m_PendingOutgoingSessions)
it.second->Resend (ts);
ScheduleResend ();
ScheduleResend (resentPacketsNum > SSU2_MAX_RESEND_PACKETS);
}
}

7
libi2pd/SSU2.h

@ -18,7 +18,10 @@ namespace i2p @@ -18,7 +18,10 @@ namespace i2p
namespace transport
{
const int SSU2_TERMINATION_CHECK_TIMEOUT = 30; // in seconds
const int SSU2_RESEND_CHECK_TIMEOUT = 500; // in milliseconds
const int SSU2_RESEND_CHECK_TIMEOUT = 400; // in milliseconds
const int SSU2_RESEND_CHECK_TIMEOUT_VARIANCE = 100; // in milliseconds
const int SSU2_RESEND_CHECK_MORE_TIMEOUT = 10; // in milliseconds
const size_t SSU2_MAX_RESEND_PACKETS = 128; // packets to resend at the time
const size_t SSU2_SOCKET_RECEIVE_BUFFER_SIZE = 0x1FFFF; // 128K
const size_t SSU2_SOCKET_SEND_BUFFER_SIZE = 0x1FFFF; // 128K
const size_t SSU2_MAX_NUM_INTRODUCERS = 3;
@ -104,7 +107,7 @@ namespace transport @@ -104,7 +107,7 @@ namespace transport
void ScheduleTermination ();
void HandleTerminationTimer (const boost::system::error_code& ecode);
void ScheduleResend ();
void ScheduleResend (bool more);
void HandleResendTimer (const boost::system::error_code& ecode);
void ConnectThroughIntroducer (std::shared_ptr<SSU2Session> session);

10
libi2pd/SSU2Session.cpp

@ -434,7 +434,7 @@ namespace transport @@ -434,7 +434,7 @@ namespace transport
return ackBlockSent;
}
void SSU2Session::Resend (uint64_t ts)
size_t SSU2Session::Resend (uint64_t ts)
{
// resend handshake packet
if (m_SentHandshakePacket && ts >= m_SentHandshakePacket->sendTime + SSU2_HANDSHAKE_RESEND_INTERVAL)
@ -442,10 +442,10 @@ namespace transport @@ -442,10 +442,10 @@ namespace transport
LogPrint (eLogDebug, "SSU2: Resending ", (int)m_State);
ResendHandshakePacket ();
m_SentHandshakePacket->sendTime = ts;
return;
return 0;
}
// resend data packets
if (m_SentPackets.empty ()) return;
if (m_SentPackets.empty ()) return 0;
std::map<uint32_t, std::shared_ptr<SSU2SentPacket> > resentPackets;
for (auto it = m_SentPackets.begin (); it != m_SentPackets.end (); )
if (ts >= it->second->sendTime + it->second->numResends*m_RTO)
@ -456,7 +456,7 @@ namespace transport @@ -456,7 +456,7 @@ namespace transport
m_SentPackets.clear ();
m_SendQueue.clear ();
RequestTermination (eSSU2TerminationReasonTimeout);
return;
return resentPackets.size ();
}
else
{
@ -478,7 +478,9 @@ namespace transport @@ -478,7 +478,9 @@ namespace transport
#endif
m_WindowSize >>= 1; // /2
if (m_WindowSize < SSU2_MIN_WINDOW_SIZE) m_WindowSize = SSU2_MIN_WINDOW_SIZE;
return resentPackets.size ();
}
return 0;
}
void SSU2Session::ResendHandshakePacket ()

2
libi2pd/SSU2Session.h

@ -243,7 +243,7 @@ namespace transport @@ -243,7 +243,7 @@ namespace transport
void SendLocalRouterInfo (bool update) override;
void SendI2NPMessages (const std::vector<std::shared_ptr<I2NPMessage> >& msgs) override;
uint32_t GetRelayTag () const override { return m_RelayTag; };
void Resend (uint64_t ts);
size_t Resend (uint64_t ts); // return number or resent packets
bool IsEstablished () const { return m_State == eSSU2SessionStateEstablished; };
uint64_t GetConnID () const { return m_SourceConnID; };
SSU2SessionState GetState () const { return m_State; };

Loading…
Cancel
Save