Browse Source

add constants for congestion levels

pull/2018/head
Vort 10 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 @@ -376,7 +376,7 @@ namespace i2p
if (!i2p::context.DecryptTunnelBuildRecord (record + BUILD_REQUEST_RECORD_ENCRYPTED_OFFSET, clearText)) return false;
uint8_t retCode = 0;
// 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 (
bufbe32toh (clearText + ECIES_BUILD_REQUEST_RECORD_RECEIVE_TUNNEL_OFFSET),
@ -586,7 +586,7 @@ namespace i2p @@ -586,7 +586,7 @@ namespace i2p
// check if we accept this tunnel
std::shared_ptr<i2p::tunnel::TransitTunnel> transitTunnel;
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;
if (!retCode)
{

4
libi2pd/I2NPProtocol.h

@ -139,6 +139,10 @@ namespace tunnel @@ -139,6 +139,10 @@ namespace tunnel
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_SHORT_MESSAGE_SIZE = 4096;
const size_t I2NP_MAX_MEDIUM_MESSAGE_SIZE = 16384;

6
libi2pd/RouterContext.cpp

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

6
libi2pd/Transports.cpp

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

2
libi2pd/Tunnel.h

@ -240,7 +240,7 @@ namespace tunnel @@ -240,7 +240,7 @@ namespace tunnel
void SetMaxNumTransitTunnels (uint16_t 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:

Loading…
Cancel
Save