always pick outbound tunnel before sending packet

This commit is contained in:
orignal 2014-07-08 22:09:58 -04:00
parent 3e25759ada
commit 30b25e9eeb
4 changed files with 9 additions and 27 deletions

View File

@ -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

View File

@ -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<Packet *> m_ReceiveQueue;
std::set<Packet *, PacketCmp> m_SavedPackets;
i2p::tunnel::OutboundTunnel * m_OutboundTunnel;
boost::asio::deadline_timer m_ReceiveTimer;
};

View File

@ -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<InboundTunnel *> 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 ();

View File

@ -57,7 +57,6 @@ namespace tunnel
std::set<InboundTunnel *, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first
std::set<OutboundTunnel *, TunnelCreationTimeCmp> m_OutboundTunnels;
std::map<uint32_t, std::pair<OutboundTunnel *, InboundTunnel *> > m_Tests;
OutboundTunnel * m_LastOutboundTunnel;
};
}
}