Browse Source

bypass medium congestion(D) routers for client tunnels

debian
orignal 1 year ago
parent
commit
4ebc7c970a
  1. 4
      libi2pd/NetDb.cpp
  2. 24
      libi2pd/RouterInfo.cpp
  3. 2
      libi2pd/RouterInfo.h
  4. 5
      libi2pd/TunnelPool.cpp
  5. 2
      libi2pd/TunnelPool.h

4
libi2pd/NetDb.cpp

@ -1172,7 +1172,7 @@ namespace data
return !router->IsHidden () && router != compatibleWith && return !router->IsHidden () && router != compatibleWith &&
(reverse ? compatibleWith->IsReachableFrom (*router) : (reverse ? compatibleWith->IsReachableFrom (*router) :
router->IsReachableFrom (*compatibleWith)) && router->IsReachableFrom (*compatibleWith)) &&
router->IsECIES (); router->IsECIES () && !router->IsHighCongestion (false);
}); });
} }
@ -1206,7 +1206,7 @@ namespace data
router->IsReachableFrom (*compatibleWith)) && router->IsReachableFrom (*compatibleWith)) &&
(router->GetCaps () & RouterInfo::eHighBandwidth) && (router->GetCaps () & RouterInfo::eHighBandwidth) &&
router->GetVersion () >= NETDB_MIN_HIGHBANDWIDTH_VERSION && router->GetVersion () >= NETDB_MIN_HIGHBANDWIDTH_VERSION &&
router->IsECIES () && !router->IsHighCongestion (); router->IsECIES () && !router->IsHighCongestion (true);
}); });
} }

24
libi2pd/RouterInfo.cpp

@ -1113,13 +1113,25 @@ namespace data
m_Timestamp = i2p::util::GetMillisecondsSinceEpoch (); m_Timestamp = i2p::util::GetMillisecondsSinceEpoch ();
} }
bool RouterInfo::IsHighCongestion () const bool RouterInfo::IsHighCongestion (bool highBandwidth) const
{ {
if (m_Congestion == eLowCongestion || m_Congestion == eMediumCongestion) return false; switch (m_Congestion)
if (m_Congestion == eRejectAll) return true; {
if (m_Congestion == eHighCongestion) case eLowCongestion:
return (i2p::util::GetMillisecondsSinceEpoch () < m_Timestamp + HIGH_CONGESTION_INTERVAL*1000LL) ? true : false; return false;
return false; break;
case eMediumCongestion:
return highBandwidth;
break;
case eHighCongestion:
return i2p::util::GetMillisecondsSinceEpoch () < m_Timestamp + HIGH_CONGESTION_INTERVAL*1000LL;
break;
case eRejectAll:
return true;
break;
default:
return false;
}
} }
void LocalRouterInfo::CreateBuffer (const PrivateKeys& privateKeys) void LocalRouterInfo::CreateBuffer (const PrivateKeys& privateKeys)

2
libi2pd/RouterInfo.h

@ -250,7 +250,7 @@ namespace data
bool IsPublished (bool v4) const; bool IsPublished (bool v4) const;
bool IsSSU2PeerTesting (bool v4) const; bool IsSSU2PeerTesting (bool v4) const;
bool IsSSU2Introducer (bool v4) const; bool IsSSU2Introducer (bool v4) const;
bool IsHighCongestion () const; bool IsHighCongestion (bool highBandwidth) const;
uint8_t GetCaps () const { return m_Caps; }; uint8_t GetCaps () const { return m_Caps; };
void SetCaps (uint8_t caps) { m_Caps = caps; }; void SetCaps (uint8_t caps) { m_Caps = caps; };

5
libi2pd/TunnelPool.cpp

@ -753,14 +753,15 @@ namespace tunnel
return m_CustomPeerSelector != nullptr; return m_CustomPeerSelector != nullptr;
} }
bool TunnelPool::ValidatePeers (std::vector<std::shared_ptr<const i2p::data::IdentityEx> >& peers) bool TunnelPool::ValidatePeers (std::vector<std::shared_ptr<const i2p::data::IdentityEx> >& peers) const
{ {
bool highBandwidth = !IsExploratory ();
for (auto it: peers) for (auto it: peers)
{ {
auto r = i2p::data::netdb.FindRouter (it->GetIdentHash ()); auto r = i2p::data::netdb.FindRouter (it->GetIdentHash ());
if (r) if (r)
{ {
if (r->IsHighCongestion ()) return false; if (r->IsHighCongestion (highBandwidth)) return false;
it = r->GetIdentity (); // use identity from updated RouterInfo it = r->GetIdentity (); // use identity from updated RouterInfo
} }
} }

2
libi2pd/TunnelPool.h

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

Loading…
Cancel
Save