Browse Source

limit number of message to handle at the time

pull/1833/head
orignal 2 years ago
parent
commit
84d6028454
  1. 10
      libi2pd/Tunnel.cpp
  2. 6
      libi2pd/Tunnel.h

10
libi2pd/Tunnel.cpp

@ -472,6 +472,7 @@ namespace tunnel @@ -472,6 +472,7 @@ namespace tunnel
auto msg = m_Queue.GetNextWithTimeout (1000); // 1 sec
if (msg)
{
int numMsgs = 0;
uint32_t prevTunnelID = 0, tunnelID = 0;
std::shared_ptr<TunnelBase> prevTunnel;
do
@ -515,11 +516,12 @@ namespace tunnel @@ -515,11 +516,12 @@ namespace tunnel
LogPrint (eLogWarning, "Tunnel: Unexpected message type ", (int) typeID);
}
msg = m_Queue.Get ();
msg = (numMsgs <= MAX_NUM_TUNNEL_MSGS_AT_THE_TIME) ? m_Queue.Get () : nullptr;
if (msg)
{
prevTunnelID = tunnelID;
prevTunnel = tunnel;
numMsgs++;
}
else if (tunnel)
tunnel->FlushTunnelDataMsgs ();
@ -530,17 +532,17 @@ namespace tunnel @@ -530,17 +532,17 @@ namespace tunnel
if (i2p::transport::transports.IsOnline())
{
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
if (ts - lastTs >= 15) // manage tunnels every 15 seconds
if (ts - lastTs >= TUNNEL_MANAGE_INTERVAL) // manage tunnels every 15 seconds
{
ManageTunnels ();
lastTs = ts;
}
if (ts - lastPoolsTs >= 5) // manage pools every 5 seconds
if (ts - lastPoolsTs >= TUNNEL_POOLS_MANAGE_INTERVAL) // manage pools every 5 seconds
{
ManageTunnelPools (ts);
lastPoolsTs = ts;
}
if (ts - lastMemoryPoolTs >= 120) // manage memory pool every 2 minutes
if (ts - lastMemoryPoolTs >= TUNNEL_MEMORY_POOL_MANAGE_INTERVAL) // manage memory pool every 2 minutes
{
m_I2NPTunnelEndpointMessagesMemoryPool.CleanUpMt ();
m_I2NPTunnelMessagesMemoryPool.CleanUpMt ();

6
libi2pd/Tunnel.h

@ -40,7 +40,11 @@ namespace tunnel @@ -40,7 +40,11 @@ namespace tunnel
const int STANDARD_NUM_RECORDS = 4; // in VariableTunnelBuild message
const int MAX_NUM_RECORDS = 8;
const int HIGH_LATENCY_PER_HOP = 250; // in milliseconds
const int MAX_NUM_TUNNEL_MSGS_AT_THE_TIME = 100; // handle message without break
const int TUNNEL_MANAGE_INTERVAL = 15; // in seconds
const int TUNNEL_POOLS_MANAGE_INTERVAL = 5; // in seconds
const int TUNNEL_MEMORY_POOL_MANAGE_INTERVAL = 120; // in seconds
const size_t I2NP_TUNNEL_MESSAGE_SIZE = TUNNEL_DATA_MSG_SIZE + I2NP_HEADER_SIZE + 34; // reserved for alignment and NTCP 16 + 6 + 12
const size_t I2NP_TUNNEL_ENPOINT_MESSAGE_SIZE = 2*TUNNEL_DATA_MSG_SIZE + I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE + 28; // reserved for alignment and NTCP 16 + 6 + 6

Loading…
Cancel
Save