mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-24 01:46:36 +02:00
always pick outbound tunnel before sending packet
This commit is contained in:
parent
3e25759ada
commit
30b25e9eeb
4 changed files with 9 additions and 27 deletions
|
@ -19,7 +19,7 @@ namespace stream
|
||||||
const i2p::data::LeaseSet& remote): m_Service (service), m_SendStreamID (0),
|
const i2p::data::LeaseSet& remote): m_Service (service), m_SendStreamID (0),
|
||||||
m_SequenceNumber (0), m_LastReceivedSequenceNumber (0), m_IsOpen (false),
|
m_SequenceNumber (0), m_LastReceivedSequenceNumber (0), m_IsOpen (false),
|
||||||
m_LeaseSetUpdated (true), m_LocalDestination (local), m_RemoteLeaseSet (remote),
|
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 ();
|
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
||||||
UpdateCurrentRemoteLease ();
|
UpdateCurrentRemoteLease ();
|
||||||
|
@ -75,9 +75,7 @@ namespace stream
|
||||||
// we have received duplicate. Most likely our outbound tunnel is dead
|
// we have received duplicate. Most likely our outbound tunnel is dead
|
||||||
LogPrint ("Duplicate message ", receivedSeqn, " received");
|
LogPrint ("Duplicate message ", receivedSeqn, " received");
|
||||||
UpdateCurrentRemoteLease (); // pick another lease
|
UpdateCurrentRemoteLease (); // pick another lease
|
||||||
m_OutboundTunnel = i2p::tunnel::tunnels.GetNextOutboundTunnel (); // pick another tunnel
|
SendQuickAck (); // resend ack for previous message again
|
||||||
if (m_OutboundTunnel)
|
|
||||||
SendQuickAck (); // resend ack for previous message again
|
|
||||||
delete packet; // packet dropped
|
delete packet; // packet dropped
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -292,16 +290,15 @@ namespace stream
|
||||||
|
|
||||||
I2NPMessage * msg = i2p::garlic::routing.WrapMessage (m_RemoteLeaseSet,
|
I2NPMessage * msg = i2p::garlic::routing.WrapMessage (m_RemoteLeaseSet,
|
||||||
CreateDataMessage (this, buf, len), leaseSet);
|
CreateDataMessage (this, buf, len), leaseSet);
|
||||||
if (!m_OutboundTunnel || m_OutboundTunnel->IsFailed ())
|
auto outboundTunnel = m_LocalDestination->GetTunnelPool ()->GetNextOutboundTunnel ();
|
||||||
m_OutboundTunnel = m_LocalDestination->GetTunnelPool ()->GetNextOutboundTunnel ();
|
if (outboundTunnel)
|
||||||
if (m_OutboundTunnel)
|
|
||||||
{
|
{
|
||||||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
if (ts >= m_CurrentRemoteLease.endDate)
|
if (ts >= m_CurrentRemoteLease.endDate)
|
||||||
UpdateCurrentRemoteLease ();
|
UpdateCurrentRemoteLease ();
|
||||||
if (ts < m_CurrentRemoteLease.endDate)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "LeaseSet.h"
|
#include "LeaseSet.h"
|
||||||
#include "I2NPProtocol.h"
|
#include "I2NPProtocol.h"
|
||||||
#include "Tunnel.h"
|
|
||||||
#include "TunnelPool.h"
|
#include "TunnelPool.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
|
@ -113,7 +112,6 @@ namespace stream
|
||||||
i2p::data::Lease m_CurrentRemoteLease;
|
i2p::data::Lease m_CurrentRemoteLease;
|
||||||
std::queue<Packet *> m_ReceiveQueue;
|
std::queue<Packet *> m_ReceiveQueue;
|
||||||
std::set<Packet *, PacketCmp> m_SavedPackets;
|
std::set<Packet *, PacketCmp> m_SavedPackets;
|
||||||
i2p::tunnel::OutboundTunnel * m_OutboundTunnel;
|
|
||||||
boost::asio::deadline_timer m_ReceiveTimer;
|
boost::asio::deadline_timer m_ReceiveTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace i2p
|
||||||
namespace tunnel
|
namespace tunnel
|
||||||
{
|
{
|
||||||
TunnelPool::TunnelPool (i2p::data::LocalDestination& localDestination, int numHops, int numTunnels):
|
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);
|
expiredTunnel->SetTunnelPool (nullptr);
|
||||||
m_OutboundTunnels.erase (expiredTunnel);
|
m_OutboundTunnels.erase (expiredTunnel);
|
||||||
}
|
}
|
||||||
if (expiredTunnel == m_LastOutboundTunnel)
|
|
||||||
m_LastOutboundTunnel = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<InboundTunnel *> TunnelPool::GetInboundTunnels (int num) const
|
std::vector<InboundTunnel *> TunnelPool::GetInboundTunnels (int num) const
|
||||||
|
@ -72,19 +70,7 @@ namespace tunnel
|
||||||
|
|
||||||
OutboundTunnel * TunnelPool::GetNextOutboundTunnel ()
|
OutboundTunnel * TunnelPool::GetNextOutboundTunnel ()
|
||||||
{
|
{
|
||||||
if (m_OutboundTunnels.empty ()) return nullptr;
|
return GetNextTunnel (m_OutboundTunnels);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InboundTunnel * TunnelPool::GetNextInboundTunnel ()
|
InboundTunnel * TunnelPool::GetNextInboundTunnel ()
|
||||||
|
@ -121,6 +107,8 @@ namespace tunnel
|
||||||
// both outbound and inbound tunnels considered as invalid
|
// both outbound and inbound tunnels considered as invalid
|
||||||
it.second.first->SetFailed (true);
|
it.second.first->SetFailed (true);
|
||||||
it.second.second->SetFailed (true);
|
it.second.second->SetFailed (true);
|
||||||
|
m_OutboundTunnels.erase (it.second.first);
|
||||||
|
m_InboundTunnels.erase (it.second.second);
|
||||||
}
|
}
|
||||||
m_Tests.clear ();
|
m_Tests.clear ();
|
||||||
auto it1 = m_OutboundTunnels.begin ();
|
auto it1 = m_OutboundTunnels.begin ();
|
||||||
|
|
|
@ -57,7 +57,6 @@ namespace tunnel
|
||||||
std::set<InboundTunnel *, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first
|
std::set<InboundTunnel *, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first
|
||||||
std::set<OutboundTunnel *, TunnelCreationTimeCmp> m_OutboundTunnels;
|
std::set<OutboundTunnel *, TunnelCreationTimeCmp> m_OutboundTunnels;
|
||||||
std::map<uint32_t, std::pair<OutboundTunnel *, InboundTunnel *> > m_Tests;
|
std::map<uint32_t, std::pair<OutboundTunnel *, InboundTunnel *> > m_Tests;
|
||||||
OutboundTunnel * m_LastOutboundTunnel;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue