Browse Source

add constants for congestion levels

pull/2018/head
Vort 9 months ago
parent
commit
19e23b34da
  1. 4
      libi2pd/I2NPProtocol.cpp
  2. 4
      libi2pd/I2NPProtocol.h
  3. 6
      libi2pd/RouterContext.cpp
  4. 6
      libi2pd/Transports.cpp
  5. 2
      libi2pd/Tunnel.h

4
libi2pd/I2NPProtocol.cpp

@ -376,7 +376,7 @@ namespace i2p
if (!i2p::context.DecryptTunnelBuildRecord (record + BUILD_REQUEST_RECORD_ENCRYPTED_OFFSET, clearText)) return false; if (!i2p::context.DecryptTunnelBuildRecord (record + BUILD_REQUEST_RECORD_ENCRYPTED_OFFSET, clearText)) return false;
uint8_t retCode = 0; uint8_t retCode = 0;
// replace record to reply // replace record to reply
if (i2p::context.AcceptsTunnels () && i2p::context.GetCongestionLevel (false) < 100) if (i2p::context.AcceptsTunnels () && i2p::context.GetCongestionLevel (false) < CONGESTION_LEVEL_FULL)
{ {
auto transitTunnel = i2p::tunnel::CreateTransitTunnel ( auto transitTunnel = i2p::tunnel::CreateTransitTunnel (
bufbe32toh (clearText + ECIES_BUILD_REQUEST_RECORD_RECEIVE_TUNNEL_OFFSET), bufbe32toh (clearText + ECIES_BUILD_REQUEST_RECORD_RECEIVE_TUNNEL_OFFSET),
@ -586,7 +586,7 @@ namespace i2p
// check if we accept this tunnel // check if we accept this tunnel
std::shared_ptr<i2p::tunnel::TransitTunnel> transitTunnel; std::shared_ptr<i2p::tunnel::TransitTunnel> transitTunnel;
uint8_t retCode = 0; uint8_t retCode = 0;
if (!i2p::context.AcceptsTunnels () || i2p::context.GetCongestionLevel (false) >= 100) if (!i2p::context.AcceptsTunnels () || i2p::context.GetCongestionLevel (false) >= CONGESTION_LEVEL_FULL)
retCode = 30; retCode = 30;
if (!retCode) if (!retCode)
{ {

4
libi2pd/I2NPProtocol.h

@ -139,6 +139,10 @@ namespace tunnel
class TunnelPool; class TunnelPool;
} }
const int CONGESTION_LEVEL_MEDIUM = 70;
const int CONGESTION_LEVEL_HIGH = 90;
const int CONGESTION_LEVEL_FULL = 100;
const size_t I2NP_MAX_MESSAGE_SIZE = 62708; const size_t I2NP_MAX_MESSAGE_SIZE = 62708;
const size_t I2NP_MAX_SHORT_MESSAGE_SIZE = 4096; const size_t I2NP_MAX_SHORT_MESSAGE_SIZE = 4096;
const size_t I2NP_MAX_MEDIUM_MESSAGE_SIZE = 16384; const size_t I2NP_MAX_MEDIUM_MESSAGE_SIZE = 16384;

6
libi2pd/RouterContext.cpp

@ -1448,14 +1448,14 @@ namespace i2p
if (ecode != boost::asio::error::operation_aborted) if (ecode != boost::asio::error::operation_aborted)
{ {
auto c = i2p::data::RouterInfo::eLowCongestion; auto c = i2p::data::RouterInfo::eLowCongestion;
if (!AcceptsTunnels () || m_ShareRatio == 0) if (!AcceptsTunnels () || !m_ShareRatio)
c = i2p::data::RouterInfo::eRejectAll; c = i2p::data::RouterInfo::eRejectAll;
else else
{ {
int congestionLevel = GetCongestionLevel (true); int congestionLevel = GetCongestionLevel (true);
if (congestionLevel > 90) if (congestionLevel > CONGESTION_LEVEL_HIGH)
c = i2p::data::RouterInfo::eHighCongestion; c = i2p::data::RouterInfo::eHighCongestion;
else if (congestionLevel > 70) else if (congestionLevel > CONGESTION_LEVEL_MEDIUM)
c = i2p::data::RouterInfo::eMediumCongestion; c = i2p::data::RouterInfo::eMediumCongestion;
} }
if (m_RouterInfo.UpdateCongestion (c)) if (m_RouterInfo.UpdateCongestion (c))

6
libi2pd/Transports.cpp

@ -411,7 +411,7 @@ namespace transport
auto tbwLimit = i2p::context.GetTransitBandwidthLimit () * 1024; // convert to bytes auto tbwLimit = i2p::context.GetTransitBandwidthLimit () * 1024; // convert to bytes
if (tbwLimit == 0 || bwLimit == 0) if (tbwLimit == 0 || bwLimit == 0)
return 100; return CONGESTION_LEVEL_FULL;
uint32_t bw; uint32_t bw;
uint32_t tbw; uint32_t tbw;
@ -425,8 +425,8 @@ namespace transport
bw = std::max (m_InBandwidth15s, m_OutBandwidth15s); bw = std::max (m_InBandwidth15s, m_OutBandwidth15s);
tbw = m_TransitBandwidth; tbw = m_TransitBandwidth;
} }
auto bwCongestionLevel = 100 * bw / bwLimit; auto bwCongestionLevel = CONGESTION_LEVEL_FULL * bw / bwLimit;
auto tbwCongestionLevel = 100 * tbw / tbwLimit; auto tbwCongestionLevel = CONGESTION_LEVEL_FULL * tbw / tbwLimit;
return std::max (bwCongestionLevel, tbwCongestionLevel); return std::max (bwCongestionLevel, tbwCongestionLevel);
} }

2
libi2pd/Tunnel.h

@ -240,7 +240,7 @@ namespace tunnel
void SetMaxNumTransitTunnels (uint16_t maxNumTransitTunnels); void SetMaxNumTransitTunnels (uint16_t maxNumTransitTunnels);
uint16_t GetMaxNumTransitTunnels () const { return m_MaxNumTransitTunnels; }; uint16_t GetMaxNumTransitTunnels () const { return m_MaxNumTransitTunnels; };
int GetCongestionLevel() const { return 100 * m_TransitTunnels.size() / m_MaxNumTransitTunnels; } int GetCongestionLevel() const { return CONGESTION_LEVEL_FULL * m_TransitTunnels.size() / m_MaxNumTransitTunnels; }
private: private:

Loading…
Cancel
Save