Browse Source

Merge pull request #2044 from Vort/stream_resend_rtt

exclude resent stream packets from RTT calculations
pull/2047/head
orignal 8 months ago committed by GitHub
parent
commit
edaf162f9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 16
      libi2pd/Streaming.cpp
  2. 3
      libi2pd/Streaming.h

16
libi2pd/Streaming.cpp

@ -427,16 +427,17 @@ namespace stream
} }
} }
auto sentPacket = *it; auto sentPacket = *it;
uint64_t rtt = ts - sentPacket->sendTime; int64_t rtt = (int64_t)ts - (int64_t)sentPacket->sendTime;
if(ts < sentPacket->sendTime) if (rtt < 0)
{
LogPrint (eLogError, "Streaming: Packet ", seqn, "sent from the future, sendTime=", sentPacket->sendTime); LogPrint (eLogError, "Streaming: Packet ", seqn, "sent from the future, sendTime=", sentPacket->sendTime);
rtt = 1; bool rttUpdated = true;
} if (!seqn)
if (seqn) m_RTT = rtt < 0 ? 1 : rtt;
else if (!sentPacket->resent && rtt >= 0)
m_RTT = RTT_EWMA_ALPHA * rtt + (1.0 - RTT_EWMA_ALPHA) * m_RTT; m_RTT = RTT_EWMA_ALPHA * rtt + (1.0 - RTT_EWMA_ALPHA) * m_RTT;
else else
m_RTT = rtt; rttUpdated = false;
if (rttUpdated)
m_RTO = m_RTT * 1.5; // TODO: implement it better m_RTO = m_RTT * 1.5; // TODO: implement it better
LogPrint (eLogDebug, "Streaming: Packet ", seqn, " acknowledged rtt=", rtt, " sentTime=", sentPacket->sendTime); LogPrint (eLogDebug, "Streaming: Packet ", seqn, " acknowledged rtt=", rtt, " sentTime=", sentPacket->sendTime);
m_SentPackets.erase (it++); m_SentPackets.erase (it++);
@ -989,6 +990,7 @@ namespace stream
{ {
if (ts >= it->sendTime + m_RTO) if (ts >= it->sendTime + m_RTO)
{ {
it->resent = true;
it->sendTime = ts; it->sendTime = ts;
packets.push_back (it); packets.push_back (it);
} }

3
libi2pd/Streaming.h

@ -71,8 +71,9 @@ namespace stream
size_t len, offset; size_t len, offset;
uint8_t buf[MAX_PACKET_SIZE]; uint8_t buf[MAX_PACKET_SIZE];
uint64_t sendTime; uint64_t sendTime;
bool resent;
Packet (): len (0), offset (0), sendTime (0) {}; Packet (): len (0), offset (0), sendTime (0), resent (false) {};
uint8_t * GetBuffer () { return buf + offset; }; uint8_t * GetBuffer () { return buf + offset; };
size_t GetLength () const { return len - offset; }; size_t GetLength () const { return len - offset; };

Loading…
Cancel
Save