mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
Merge pull request #2018 from Vort/congestion_consts
add constants for congestion levels
This commit is contained in:
commit
cb8fbb0135
@ -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
|
||||
// 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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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…
Reference in New Issue
Block a user