diff --git a/Streaming.cpp b/Streaming.cpp index 7b6ef7c6..7d7d38f3 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -19,7 +19,7 @@ namespace stream const i2p::data::LeaseSet& remote): m_Service (service), m_SendStreamID (0), m_SequenceNumber (0), m_LastReceivedSequenceNumber (0), m_IsOpen (false), m_LeaseSetUpdated (true), m_LocalDestination (local), m_RemoteLeaseSet (remote), - m_OutboundTunnel (nullptr), m_ReceiveTimer (m_Service) + m_ReceiveTimer (m_Service) { m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (); UpdateCurrentRemoteLease (); @@ -75,9 +75,7 @@ namespace stream // we have received duplicate. Most likely our outbound tunnel is dead LogPrint ("Duplicate message ", receivedSeqn, " received"); UpdateCurrentRemoteLease (); // pick another lease - m_OutboundTunnel = i2p::tunnel::tunnels.GetNextOutboundTunnel (); // pick another tunnel - if (m_OutboundTunnel) - SendQuickAck (); // resend ack for previous message again + SendQuickAck (); // resend ack for previous message again delete packet; // packet dropped } else @@ -292,16 +290,15 @@ namespace stream I2NPMessage * msg = i2p::garlic::routing.WrapMessage (m_RemoteLeaseSet, CreateDataMessage (this, buf, len), leaseSet); - if (!m_OutboundTunnel || m_OutboundTunnel->IsFailed ()) - m_OutboundTunnel = m_LocalDestination->GetTunnelPool ()->GetNextOutboundTunnel (); - if (m_OutboundTunnel) + auto outboundTunnel = m_LocalDestination->GetTunnelPool ()->GetNextOutboundTunnel (); + if (outboundTunnel) { auto ts = i2p::util::GetMillisecondsSinceEpoch (); if (ts >= m_CurrentRemoteLease.endDate) UpdateCurrentRemoteLease (); if (ts < m_CurrentRemoteLease.endDate) { - m_OutboundTunnel->SendTunnelDataMsg (m_CurrentRemoteLease.tunnelGateway, m_CurrentRemoteLease.tunnelID, msg); + outboundTunnel->SendTunnelDataMsg (m_CurrentRemoteLease.tunnelGateway, m_CurrentRemoteLease.tunnelID, msg); return true; } else diff --git a/Streaming.h b/Streaming.h index 5a0ed383..5b7fa413 100644 --- a/Streaming.h +++ b/Streaming.h @@ -14,7 +14,6 @@ #include "Identity.h" #include "LeaseSet.h" #include "I2NPProtocol.h" -#include "Tunnel.h" #include "TunnelPool.h" namespace i2p @@ -113,7 +112,6 @@ namespace stream i2p::data::Lease m_CurrentRemoteLease; std::queue m_ReceiveQueue; std::set m_SavedPackets; - i2p::tunnel::OutboundTunnel * m_OutboundTunnel; boost::asio::deadline_timer m_ReceiveTimer; }; diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 1b6fa8cb..7b1ff0fa 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -11,7 +11,7 @@ namespace i2p namespace tunnel { TunnelPool::TunnelPool (i2p::data::LocalDestination& localDestination, int numHops, int numTunnels): - m_LocalDestination (localDestination), m_NumHops (numHops), m_NumTunnels (numTunnels), m_LastOutboundTunnel (nullptr) + m_LocalDestination (localDestination), m_NumHops (numHops), m_NumTunnels (numTunnels) { } @@ -50,8 +50,6 @@ namespace tunnel expiredTunnel->SetTunnelPool (nullptr); m_OutboundTunnels.erase (expiredTunnel); } - if (expiredTunnel == m_LastOutboundTunnel) - m_LastOutboundTunnel = nullptr; } std::vector TunnelPool::GetInboundTunnels (int num) const @@ -72,19 +70,7 @@ namespace tunnel OutboundTunnel * TunnelPool::GetNextOutboundTunnel () { - if (m_OutboundTunnels.empty ()) return nullptr; - auto tunnel = *m_OutboundTunnels.begin (); - if (m_LastOutboundTunnel && tunnel == m_LastOutboundTunnel) - { - for (auto it: m_OutboundTunnels) - if (it != m_LastOutboundTunnel && !it->IsFailed ()) - { - tunnel = it; - break; - } - } - m_LastOutboundTunnel = tunnel; - return tunnel; + return GetNextTunnel (m_OutboundTunnels); } InboundTunnel * TunnelPool::GetNextInboundTunnel () @@ -121,6 +107,8 @@ namespace tunnel // both outbound and inbound tunnels considered as invalid it.second.first->SetFailed (true); it.second.second->SetFailed (true); + m_OutboundTunnels.erase (it.second.first); + m_InboundTunnels.erase (it.second.second); } m_Tests.clear (); auto it1 = m_OutboundTunnels.begin (); diff --git a/TunnelPool.h b/TunnelPool.h index 27848bfb..3132769d 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -57,7 +57,6 @@ namespace tunnel std::set m_InboundTunnels; // recent tunnel appears first std::set m_OutboundTunnels; std::map > m_Tests; - OutboundTunnel * m_LastOutboundTunnel; }; } }