mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
Merge pull request #2048 from Vort/stream_resends
Reset stream RTO if outbound tunnel was changed
This commit is contained in:
commit
04bccedd9b
2 changed files with 35 additions and 26 deletions
|
@ -916,20 +916,32 @@ namespace stream
|
||||||
UpdateCurrentRemoteLease (true);
|
UpdateCurrentRemoteLease (true);
|
||||||
if (m_CurrentRemoteLease && ts < m_CurrentRemoteLease->endDate + i2p::data::LEASE_ENDDATE_THRESHOLD)
|
if (m_CurrentRemoteLease && ts < m_CurrentRemoteLease->endDate + i2p::data::LEASE_ENDDATE_THRESHOLD)
|
||||||
{
|
{
|
||||||
|
bool freshTunnel = false;
|
||||||
if (!m_CurrentOutboundTunnel)
|
if (!m_CurrentOutboundTunnel)
|
||||||
{
|
{
|
||||||
auto leaseRouter = i2p::data::netdb.FindRouter (m_CurrentRemoteLease->tunnelGateway);
|
auto leaseRouter = i2p::data::netdb.FindRouter (m_CurrentRemoteLease->tunnelGateway);
|
||||||
m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ()->GetTunnelPool ()->GetNextOutboundTunnel (nullptr,
|
m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ()->GetTunnelPool ()->GetNextOutboundTunnel (nullptr,
|
||||||
leaseRouter ? leaseRouter->GetCompatibleTransports (false) : (i2p::data::RouterInfo::CompatibleTransports)i2p::data::RouterInfo::eAllTransports);
|
leaseRouter ? leaseRouter->GetCompatibleTransports (false) : (i2p::data::RouterInfo::CompatibleTransports)i2p::data::RouterInfo::eAllTransports);
|
||||||
|
freshTunnel = true;
|
||||||
}
|
}
|
||||||
else if (!m_CurrentOutboundTunnel->IsEstablished ())
|
else if (!m_CurrentOutboundTunnel->IsEstablished ())
|
||||||
|
{
|
||||||
|
auto oldOutboundTunnel = m_CurrentOutboundTunnel;
|
||||||
m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ()->GetTunnelPool ()->GetNewOutboundTunnel (m_CurrentOutboundTunnel);
|
m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ()->GetTunnelPool ()->GetNewOutboundTunnel (m_CurrentOutboundTunnel);
|
||||||
|
if (m_CurrentOutboundTunnel && oldOutboundTunnel->GetEndpointIdentHash() != m_CurrentOutboundTunnel->GetEndpointIdentHash())
|
||||||
|
freshTunnel = true;
|
||||||
|
}
|
||||||
if (!m_CurrentOutboundTunnel)
|
if (!m_CurrentOutboundTunnel)
|
||||||
{
|
{
|
||||||
LogPrint (eLogError, "Streaming: No outbound tunnels in the pool, sSID=", m_SendStreamID);
|
LogPrint (eLogError, "Streaming: No outbound tunnels in the pool, sSID=", m_SendStreamID);
|
||||||
m_CurrentRemoteLease = nullptr;
|
m_CurrentRemoteLease = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (freshTunnel)
|
||||||
|
{
|
||||||
|
m_RTO = INITIAL_RTO;
|
||||||
|
m_TunnelsChangeSequenceNumber = m_SequenceNumber; // should be determined more precisely
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
||||||
for (const auto& it: packets)
|
for (const auto& it: packets)
|
||||||
|
@ -1024,34 +1036,31 @@ namespace stream
|
||||||
if (packets.size () > 0)
|
if (packets.size () > 0)
|
||||||
{
|
{
|
||||||
m_NumResendAttempts++;
|
m_NumResendAttempts++;
|
||||||
if (m_RTO != INITIAL_RTO)
|
if (m_NumResendAttempts == 1 && m_RTO != INITIAL_RTO)
|
||||||
m_RTO *= 2;
|
|
||||||
switch (m_NumResendAttempts)
|
|
||||||
{
|
{
|
||||||
case 1: // congestion avoidance
|
// congestion avoidance
|
||||||
|
m_RTO *= 2;
|
||||||
m_WindowSize -= (m_WindowSize + WINDOW_SIZE_DROP_FRACTION) / WINDOW_SIZE_DROP_FRACTION; // adjustment >= 1
|
m_WindowSize -= (m_WindowSize + WINDOW_SIZE_DROP_FRACTION) / WINDOW_SIZE_DROP_FRACTION; // adjustment >= 1
|
||||||
if (m_WindowSize < MIN_WINDOW_SIZE) m_WindowSize = MIN_WINDOW_SIZE;
|
if (m_WindowSize < MIN_WINDOW_SIZE) m_WindowSize = MIN_WINDOW_SIZE;
|
||||||
break;
|
}
|
||||||
case 2:
|
else
|
||||||
|
{
|
||||||
m_TunnelsChangeSequenceNumber = m_SequenceNumber;
|
m_TunnelsChangeSequenceNumber = m_SequenceNumber;
|
||||||
m_RTO = INITIAL_RTO; // drop RTO to initial upon tunnels pair change first time
|
m_RTO = INITIAL_RTO; // drop RTO to initial upon tunnels pair change
|
||||||
#if (__cplusplus >= 201703L) // C++ 17 or higher
|
|
||||||
[[fallthrough]];
|
|
||||||
#endif
|
|
||||||
// no break here
|
|
||||||
case 4:
|
|
||||||
if (m_RoutingSession) m_RoutingSession->SetSharedRoutingPath (nullptr);
|
if (m_RoutingSession) m_RoutingSession->SetSharedRoutingPath (nullptr);
|
||||||
UpdateCurrentRemoteLease (); // pick another lease
|
if (m_NumResendAttempts & 1)
|
||||||
LogPrint (eLogWarning, "Streaming: Another remote lease has been selected for stream with rSID=", m_RecvStreamID, ", sSID=", m_SendStreamID);
|
{
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
// pick another outbound tunnel
|
// pick another outbound tunnel
|
||||||
m_TunnelsChangeSequenceNumber = m_SequenceNumber;
|
|
||||||
if (m_RoutingSession) m_RoutingSession->SetSharedRoutingPath (nullptr);
|
|
||||||
m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ()->GetTunnelPool ()->GetNextOutboundTunnel (m_CurrentOutboundTunnel);
|
m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ()->GetTunnelPool ()->GetNextOutboundTunnel (m_CurrentOutboundTunnel);
|
||||||
LogPrint (eLogWarning, "Streaming: Another outbound tunnel has been selected for stream with sSID=", m_SendStreamID);
|
LogPrint (eLogWarning, "Streaming: Resend #", m_NumResendAttempts,
|
||||||
break;
|
", another outbound tunnel has been selected for stream with sSID=", m_SendStreamID);
|
||||||
default: ;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateCurrentRemoteLease (); // pick another lease
|
||||||
|
LogPrint (eLogWarning, "Streaming: Resend #", m_NumResendAttempts,
|
||||||
|
", another remote lease has been selected for stream with rSID=", m_RecvStreamID, ", sSID=", m_SendStreamID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SendPackets (packets);
|
SendPackets (packets);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace stream
|
||||||
const size_t STREAMING_MTU_RATCHETS = 1812;
|
const size_t STREAMING_MTU_RATCHETS = 1812;
|
||||||
const size_t MAX_PACKET_SIZE = 4096;
|
const size_t MAX_PACKET_SIZE = 4096;
|
||||||
const size_t COMPRESSION_THRESHOLD_SIZE = 66;
|
const size_t COMPRESSION_THRESHOLD_SIZE = 66;
|
||||||
const int MAX_NUM_RESEND_ATTEMPTS = 6;
|
const int MAX_NUM_RESEND_ATTEMPTS = 9;
|
||||||
const int WINDOW_SIZE = 6; // in messages
|
const int WINDOW_SIZE = 6; // in messages
|
||||||
const int MIN_WINDOW_SIZE = 1;
|
const int MIN_WINDOW_SIZE = 1;
|
||||||
const int MAX_WINDOW_SIZE = 128;
|
const int MAX_WINDOW_SIZE = 128;
|
||||||
|
|
Loading…
Add table
Reference in a new issue