mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
moved max num transit tunnels to Tunnels
This commit is contained in:
parent
5470a3a453
commit
24a14e3440
@ -179,7 +179,7 @@ namespace util
|
|||||||
uint16_t transitTunnels; i2p::config::GetOption("limits.transittunnels", transitTunnels);
|
uint16_t transitTunnels; i2p::config::GetOption("limits.transittunnels", transitTunnels);
|
||||||
if (isFloodfill && i2p::config::IsDefault ("limits.transittunnels"))
|
if (isFloodfill && i2p::config::IsDefault ("limits.transittunnels"))
|
||||||
transitTunnels *= 2; // double default number of transit tunnels for floodfill
|
transitTunnels *= 2; // double default number of transit tunnels for floodfill
|
||||||
SetMaxNumTransitTunnels (transitTunnels);
|
i2p::tunnel::tunnels.SetMaxNumTransitTunnels (transitTunnels);
|
||||||
|
|
||||||
/* this section also honors 'floodfill' flag, if set above */
|
/* this section also honors 'floodfill' flag, if set above */
|
||||||
std::string bandwidth; i2p::config::GetOption("bandwidth", bandwidth);
|
std::string bandwidth; i2p::config::GetOption("bandwidth", bandwidth);
|
||||||
|
@ -754,7 +754,7 @@ namespace http {
|
|||||||
s << " <a class=\"button" << (loglevel == eLogInfo ? " selected" : "") << "\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=info&token=" << token << "\"> info </a> \r\n";
|
s << " <a class=\"button" << (loglevel == eLogInfo ? " selected" : "") << "\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=info&token=" << token << "\"> info </a> \r\n";
|
||||||
s << " <a class=\"button" << (loglevel == eLogDebug ? " selected" : "") << "\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=debug&token=" << token << "\"> debug </a><br>\r\n<br>\r\n";
|
s << " <a class=\"button" << (loglevel == eLogDebug ? " selected" : "") << "\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=debug&token=" << token << "\"> debug </a><br>\r\n<br>\r\n";
|
||||||
|
|
||||||
uint16_t maxTunnels = GetMaxNumTransitTunnels ();
|
uint16_t maxTunnels = i2p::tunnel::tunnels.GetMaxNumTransitTunnels ();
|
||||||
s << "<b>" << tr("Transit tunnels limit") << "</b><br>\r\n";
|
s << "<b>" << tr("Transit tunnels limit") << "</b><br>\r\n";
|
||||||
s << "<form method=\"get\" action=\"" << webroot << "\">\r\n";
|
s << "<form method=\"get\" action=\"" << webroot << "\">\r\n";
|
||||||
s << " <input type=\"hidden\" name=\"cmd\" value=\"" << HTTP_COMMAND_LIMITTRANSIT << "\">\r\n";
|
s << " <input type=\"hidden\" name=\"cmd\" value=\"" << HTTP_COMMAND_LIMITTRANSIT << "\">\r\n";
|
||||||
@ -1314,7 +1314,7 @@ namespace http {
|
|||||||
{
|
{
|
||||||
uint32_t limit = std::stoul(params["limit"], nullptr);
|
uint32_t limit = std::stoul(params["limit"], nullptr);
|
||||||
if (limit > 0 && limit <= TRANSIT_TUNNELS_LIMIT)
|
if (limit > 0 && limit <= TRANSIT_TUNNELS_LIMIT)
|
||||||
SetMaxNumTransitTunnels (limit);
|
i2p::tunnel::tunnels.SetMaxNumTransitTunnels (limit);
|
||||||
else {
|
else {
|
||||||
s << "<b>" << tr("ERROR") << "</b>: " << tr("Transit tunnels count must not exceed %d", TRANSIT_TUNNELS_LIMIT) << "\r\n<br>\r\n<br>\r\n";
|
s << "<b>" << tr("ERROR") << "</b>: " << tr("Transit tunnels count must not exceed %d", TRANSIT_TUNNELS_LIMIT) << "\r\n<br>\r\n<br>\r\n";
|
||||||
s << "<a href=\"" << webroot << "?page=commands\">" << tr("Back to commands list") << "</a>\r\n<br>\r\n";
|
s << "<a href=\"" << webroot << "?page=commands\">" << tr("Back to commands list") << "</a>\r\n<br>\r\n";
|
||||||
|
@ -353,21 +353,6 @@ namespace i2p
|
|||||||
return !msg->GetPayload ()[DATABASE_STORE_TYPE_OFFSET]; // 0- RouterInfo
|
return !msg->GetPayload ()[DATABASE_STORE_TYPE_OFFSET]; // 0- RouterInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t g_MaxNumTransitTunnels = DEFAULT_MAX_NUM_TRANSIT_TUNNELS; // TODO:
|
|
||||||
void SetMaxNumTransitTunnels (uint16_t maxNumTransitTunnels)
|
|
||||||
{
|
|
||||||
if (maxNumTransitTunnels > 0 && g_MaxNumTransitTunnels != maxNumTransitTunnels)
|
|
||||||
{
|
|
||||||
LogPrint (eLogDebug, "I2NP: Max number of transit tunnels set to ", maxNumTransitTunnels);
|
|
||||||
g_MaxNumTransitTunnels = maxNumTransitTunnels;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t GetMaxNumTransitTunnels ()
|
|
||||||
{
|
|
||||||
return g_MaxNumTransitTunnels;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool HandleBuildRequestRecords (int num, uint8_t * records, uint8_t * clearText)
|
static bool HandleBuildRequestRecords (int num, uint8_t * records, uint8_t * clearText)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < num; i++)
|
for (int i = 0; i < num; i++)
|
||||||
@ -380,7 +365,7 @@ namespace i2p
|
|||||||
uint8_t retCode = 0;
|
uint8_t retCode = 0;
|
||||||
// replace record to reply
|
// replace record to reply
|
||||||
if (i2p::context.AcceptsTunnels () &&
|
if (i2p::context.AcceptsTunnels () &&
|
||||||
i2p::tunnel::tunnels.GetTransitTunnels ().size () <= g_MaxNumTransitTunnels &&
|
!i2p::tunnel::tunnels.IsTooManyTransitTunnels () &&
|
||||||
!i2p::transport::transports.IsBandwidthExceeded () &&
|
!i2p::transport::transports.IsBandwidthExceeded () &&
|
||||||
!i2p::transport::transports.IsTransitBandwidthExceeded ())
|
!i2p::transport::transports.IsTransitBandwidthExceeded ())
|
||||||
{
|
{
|
||||||
@ -577,7 +562,7 @@ namespace i2p
|
|||||||
// check if we accept this tunnel
|
// check if we accept this tunnel
|
||||||
uint8_t retCode = 0;
|
uint8_t retCode = 0;
|
||||||
if (!i2p::context.AcceptsTunnels () ||
|
if (!i2p::context.AcceptsTunnels () ||
|
||||||
i2p::tunnel::tunnels.GetTransitTunnels ().size () > g_MaxNumTransitTunnels ||
|
i2p::tunnel::tunnels.IsTooManyTransitTunnels () ||
|
||||||
i2p::transport::transports.IsBandwidthExceeded () ||
|
i2p::transport::transports.IsBandwidthExceeded () ||
|
||||||
i2p::transport::transports.IsTransitBandwidthExceeded ())
|
i2p::transport::transports.IsTransitBandwidthExceeded ())
|
||||||
retCode = 30;
|
retCode = 30;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2021, The PurpleI2P Project
|
* Copyright (c) 2013-2023, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@ -308,10 +308,6 @@ namespace tunnel
|
|||||||
|
|
||||||
std::vector<std::shared_ptr<I2NPMessage> > m_TunnelMsgs, m_TunnelGatewayMsgs;
|
std::vector<std::shared_ptr<I2NPMessage> > m_TunnelMsgs, m_TunnelGatewayMsgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint16_t DEFAULT_MAX_NUM_TRANSIT_TUNNELS = 5000;
|
|
||||||
void SetMaxNumTransitTunnels (uint16_t maxNumTransitTunnels);
|
|
||||||
uint16_t GetMaxNumTransitTunnels ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -331,7 +331,7 @@ namespace tunnel
|
|||||||
|
|
||||||
Tunnels tunnels;
|
Tunnels tunnels;
|
||||||
|
|
||||||
Tunnels::Tunnels (): m_IsRunning (false), m_Thread (nullptr),
|
Tunnels::Tunnels (): m_IsRunning (false), m_Thread (nullptr), m_MaxNumTransitTunnels (DEFAULT_MAX_NUM_TRANSIT_TUNNELS),
|
||||||
m_TotalNumSuccesiveTunnelCreations (0), m_TotalNumFailedTunnelCreations (0), // for normal avarage
|
m_TotalNumSuccesiveTunnelCreations (0), m_TotalNumFailedTunnelCreations (0), // for normal avarage
|
||||||
m_TunnelCreationSuccessRate (TCSR_START_VALUE), m_TunnelCreationAttemptsNum(0)
|
m_TunnelCreationSuccessRate (TCSR_START_VALUE), m_TunnelCreationAttemptsNum(0)
|
||||||
{
|
{
|
||||||
@ -970,5 +970,14 @@ namespace tunnel
|
|||||||
// TODO: locking
|
// TODO: locking
|
||||||
return m_OutboundTunnels.size();
|
return m_OutboundTunnels.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tunnels::SetMaxNumTransitTunnels (uint16_t maxNumTransitTunnels)
|
||||||
|
{
|
||||||
|
if (maxNumTransitTunnels > 0 && m_MaxNumTransitTunnels != maxNumTransitTunnels)
|
||||||
|
{
|
||||||
|
LogPrint (eLogDebug, "Tunnel: Max number of transit tunnels set to ", maxNumTransitTunnels);
|
||||||
|
m_MaxNumTransitTunnels = maxNumTransitTunnels;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ namespace tunnel
|
|||||||
const int MAX_NUM_RECORDS = 8;
|
const int MAX_NUM_RECORDS = 8;
|
||||||
const int HIGH_LATENCY_PER_HOP = 250; // in milliseconds
|
const int HIGH_LATENCY_PER_HOP = 250; // in milliseconds
|
||||||
const int MAX_TUNNEL_MSGS_BATCH_SIZE = 100; // handle messages without interrupt
|
const int MAX_TUNNEL_MSGS_BATCH_SIZE = 100; // handle messages without interrupt
|
||||||
|
const uint16_t DEFAULT_MAX_NUM_TRANSIT_TUNNELS = 5000;
|
||||||
const int TUNNEL_MANAGE_INTERVAL = 15; // in seconds
|
const int TUNNEL_MANAGE_INTERVAL = 15; // in seconds
|
||||||
const int TUNNEL_POOLS_MANAGE_INTERVAL = 5; // in seconds
|
const int TUNNEL_POOLS_MANAGE_INTERVAL = 5; // in seconds
|
||||||
const int TUNNEL_MEMORY_POOL_MANAGE_INTERVAL = 120; // in seconds
|
const int TUNNEL_MEMORY_POOL_MANAGE_INTERVAL = 120; // in seconds
|
||||||
@ -229,6 +230,10 @@ namespace tunnel
|
|||||||
|
|
||||||
std::shared_ptr<I2NPMessage> NewI2NPTunnelMessage (bool endpoint);
|
std::shared_ptr<I2NPMessage> NewI2NPTunnelMessage (bool endpoint);
|
||||||
|
|
||||||
|
void SetMaxNumTransitTunnels (uint16_t maxNumTransitTunnels);
|
||||||
|
uint16_t GetMaxNumTransitTunnels () const { return m_MaxNumTransitTunnels; };
|
||||||
|
bool IsTooManyTransitTunnels () const { return m_TransitTunnels.size () >= m_MaxNumTransitTunnels; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
template<class TTunnel>
|
template<class TTunnel>
|
||||||
@ -287,6 +292,7 @@ namespace tunnel
|
|||||||
i2p::util::Queue<std::shared_ptr<I2NPMessage> > m_Queue;
|
i2p::util::Queue<std::shared_ptr<I2NPMessage> > m_Queue;
|
||||||
i2p::util::MemoryPoolMt<I2NPMessageBuffer<I2NP_TUNNEL_ENPOINT_MESSAGE_SIZE> > m_I2NPTunnelEndpointMessagesMemoryPool;
|
i2p::util::MemoryPoolMt<I2NPMessageBuffer<I2NP_TUNNEL_ENPOINT_MESSAGE_SIZE> > m_I2NPTunnelEndpointMessagesMemoryPool;
|
||||||
i2p::util::MemoryPoolMt<I2NPMessageBuffer<I2NP_TUNNEL_MESSAGE_SIZE> > m_I2NPTunnelMessagesMemoryPool;
|
i2p::util::MemoryPoolMt<I2NPMessageBuffer<I2NP_TUNNEL_MESSAGE_SIZE> > m_I2NPTunnelMessagesMemoryPool;
|
||||||
|
uint16_t m_MaxNumTransitTunnels;
|
||||||
// count of tunnels for total TCSR algorithm
|
// count of tunnels for total TCSR algorithm
|
||||||
int m_TotalNumSuccesiveTunnelCreations, m_TotalNumFailedTunnelCreations;
|
int m_TotalNumSuccesiveTunnelCreations, m_TotalNumFailedTunnelCreations;
|
||||||
double m_TunnelCreationSuccessRate;
|
double m_TunnelCreationSuccessRate;
|
||||||
|
Loading…
Reference in New Issue
Block a user