mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-27 11:17:49 +02:00
initial ntcp soft/hard limits
This commit is contained in:
parent
bc11181d5e
commit
6441c9d5d8
4 changed files with 59 additions and 14 deletions
|
@ -167,8 +167,19 @@ namespace transport
|
|||
|
||||
boost::asio::io_service& GetService () { return m_Service; };
|
||||
|
||||
void SetSessionLimits(uint16_t softLimit, uint16_t hardLimit) { m_SoftLimit = softLimit; m_HardLimit = hardLimit; }
|
||||
bool ShouldLimit() const { return ShouldHardLimit() || ShouldSoftLimit(); }
|
||||
private:
|
||||
|
||||
/** @brief return true for hard limit */
|
||||
bool ShouldHardLimit() const { return m_HardLimit && m_NTCPSessions.size() >= m_HardLimit; }
|
||||
|
||||
/** @brief return true for probabalistic soft backoff */
|
||||
bool ShouldSoftLimit() const
|
||||
{
|
||||
auto sessions = m_NTCPSessions.size();
|
||||
return sessions && m_SoftLimit && m_SoftLimit < sessions && ( rand() % sessions ) <= m_SoftLimit;
|
||||
}
|
||||
void Run ();
|
||||
void HandleAccept (std::shared_ptr<NTCPSession> conn, const boost::system::error_code& error);
|
||||
void HandleAcceptV6 (std::shared_ptr<NTCPSession> conn, const boost::system::error_code& error);
|
||||
|
@ -198,6 +209,8 @@ namespace transport
|
|||
uint16_t m_ProxyPort;
|
||||
boost::asio::ip::tcp::resolver m_Resolver;
|
||||
boost::asio::ip::tcp::endpoint * m_ProxyEndpoint;
|
||||
|
||||
uint16_t m_SoftLimit, m_HardLimit;
|
||||
public:
|
||||
|
||||
// for HTTP/I2PControl
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue