Skip to content

Commit

Permalink
drop window size only when lease changes
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Sep 16, 2024
1 parent d4c1a1c commit 13b2fc3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
40 changes: 27 additions & 13 deletions libi2pd/Streaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,15 @@ namespace stream
numPackets = (passedTime + m_PacketACKIntervalRem) / m_PacketACKInterval;
m_PacketACKIntervalRem = (passedTime + m_PacketACKIntervalRem) - (numPackets * m_PacketACKInterval);
if (m_LastConfirmedReceivedSequenceNumber + numPackets < m_LastReceivedSequenceNumber)
{
lastReceivedSeqn = m_LastConfirmedReceivedSequenceNumber + numPackets;
if (!m_IsAckSendScheduled)
{
auto ackTimeout = m_RTT/10;
if (ackTimeout > m_AckDelay) ackTimeout = m_AckDelay;
ScheduleAck (ackTimeout);
}
}
if (numPackets == 0) return;
// for limit inbound speed
if (!m_SavedPackets.empty ())
Expand Down Expand Up @@ -1396,6 +1404,7 @@ namespace stream

void Stream::UpdateCurrentRemoteLease (bool expired)
{
bool isLeaseChanged = true;
if (!m_RemoteLeaseSet || m_RemoteLeaseSet->IsExpired ())
{
auto remoteLeaseSet = m_LocalDestination.GetOwner ()->FindLeaseSet (m_RemoteIdentity->GetIdentHash ());
Expand Down Expand Up @@ -1451,14 +1460,16 @@ namespace stream
break;
}
}
if (!updated)
if (!updated && leases.size () > 1)
{
uint32_t i = m_LocalDestination.GetRandom () % leases.size ();
if (m_CurrentRemoteLease && leases[i]->tunnelID == m_CurrentRemoteLease->tunnelID)
// make sure we don't select previous
i = (i + 1) % leases.size (); // if so, pick next
m_CurrentRemoteLease = leases[i];
}
else
isLeaseChanged = false;
}
else
{
Expand All @@ -1473,20 +1484,23 @@ namespace stream
LogPrint (eLogWarning, "Streaming: Remote LeaseSet not found");
m_CurrentRemoteLease = nullptr;
}
// drop window to initial upon RemoteLease change
m_RTO = INITIAL_RTO;
if (m_WindowSize > INITIAL_WINDOW_SIZE)
if (isLeaseChanged)
{
m_WindowDropTargetSize = std::max (m_WindowSize/2, (float)INITIAL_WINDOW_SIZE);
m_IsWinDropped = true;
// drop window to initial upon RemoteLease change
m_RTO = INITIAL_RTO;
if (m_WindowSize > INITIAL_WINDOW_SIZE)
{
m_WindowDropTargetSize = std::max (m_WindowSize/2, (float)INITIAL_WINDOW_SIZE);
m_IsWinDropped = true;
}
else
m_WindowSize = INITIAL_WINDOW_SIZE;
m_LastWindowDropSize = 0;
m_WindowIncCounter = 0;
m_IsFirstRttSample = true;
m_IsFirstACK = true;
UpdatePacingTime ();
}
else
m_WindowSize = INITIAL_WINDOW_SIZE;
m_LastWindowDropSize = 0;
m_WindowIncCounter = 0;
m_IsFirstRttSample = true;
m_IsFirstACK = true;
UpdatePacingTime ();
}

void Stream::ResetRoutingPath ()
Expand Down
2 changes: 1 addition & 1 deletion libi2pd/Streaming.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace stream
const int INITIAL_WINDOW_SIZE = 10;
const int MIN_WINDOW_SIZE = 2;
const int MAX_WINDOW_SIZE = 512;
const double RTT_EWMA_ALPHA = 0.5;
const double RTT_EWMA_ALPHA = 0.25;
const double SLOWRTT_EWMA_ALPHA = 0.05;
const double PREV_SPEED_KEEP_TIME_COEFF = 0.35; // 0.1 - 1 // how long will the window size stay around the previous drop level, less is longer
const int MIN_RTO = 20; // in milliseconds
Expand Down

0 comments on commit 13b2fc3

Please sign in to comment.