Browse Source

check routers' congestion before recreating a tunnel

debian
orignal 2 years ago
parent
commit
572694b141
  1. 31
      libi2pd/TunnelPool.cpp
  2. 1
      libi2pd/TunnelPool.h

31
libi2pd/TunnelPool.cpp

@ -637,8 +637,13 @@ namespace tunnel @@ -637,8 +637,13 @@ namespace tunnel
outboundTunnel = tunnels.GetNextOutboundTunnel ();
LogPrint (eLogDebug, "Tunnels: Re-creating destination inbound tunnel...");
std::shared_ptr<TunnelConfig> config;
if (m_NumInboundHops > 0 && tunnel->GetPeers().size())
config = std::make_shared<TunnelConfig>(tunnel->GetPeers (), tunnel->IsShortBuildMessage (), tunnel->GetFarEndTransports ());
if (m_NumInboundHops > 0)
{
auto peers = tunnel->GetPeers();
if (peers.size ()&& ValidatePeers (peers))
config = std::make_shared<TunnelConfig>(tunnel->GetPeers (),
tunnel->IsShortBuildMessage (), tunnel->GetFarEndTransports ());
}
if (!m_NumInboundHops || config)
{
auto newTunnel = tunnels.CreateInboundTunnel (config, shared_from_this(), outboundTunnel);
@ -702,10 +707,12 @@ namespace tunnel @@ -702,10 +707,12 @@ namespace tunnel
{
LogPrint (eLogDebug, "Tunnels: Re-creating destination outbound tunnel...");
std::shared_ptr<TunnelConfig> config;
if (m_NumOutboundHops > 0 && tunnel->GetPeers().size())
if (m_NumOutboundHops > 0)
{
config = std::make_shared<TunnelConfig>(tunnel->GetPeers (), inboundTunnel->GetNextTunnelID (),
inboundTunnel->GetNextIdentHash (), inboundTunnel->IsShortBuildMessage (), tunnel->GetFarEndTransports ());
auto peers = tunnel->GetPeers();
if (peers.size () && ValidatePeers (peers))
config = std::make_shared<TunnelConfig>(peers, inboundTunnel->GetNextTunnelID (),
inboundTunnel->GetNextIdentHash (), inboundTunnel->IsShortBuildMessage (), tunnel->GetFarEndTransports ());
}
if (!m_NumOutboundHops || config)
{
@ -746,6 +753,20 @@ namespace tunnel @@ -746,6 +753,20 @@ namespace tunnel
return m_CustomPeerSelector != nullptr;
}
bool TunnelPool::ValidatePeers (std::vector<std::shared_ptr<const i2p::data::IdentityEx> >& peers)
{
for (auto it: peers)
{
auto r = i2p::data::netdb.FindRouter (it->GetIdentHash ());
if (r)
{
if (r->IsHighCongestion ()) return false;
it = r->GetIdentity (); // use identity from updated RouterInfo
}
}
return true;
}
std::shared_ptr<InboundTunnel> TunnelPool::GetLowestLatencyInboundTunnel(std::shared_ptr<InboundTunnel> exclude) const
{
std::shared_ptr<InboundTunnel> tun = nullptr;

1
libi2pd/TunnelPool.h

@ -126,6 +126,7 @@ namespace tunnel @@ -126,6 +126,7 @@ namespace tunnel
typename TTunnels::value_type excluded, i2p::data::RouterInfo::CompatibleTransports compatible) const;
bool SelectPeers (Path& path, bool isInbound);
bool SelectExplicitPeers (Path& path, bool isInbound);
static bool ValidatePeers (std::vector<std::shared_ptr<const i2p::data::IdentityEx> >& peers);
private:

Loading…
Cancel
Save