Browse Source

ilimit umner of simultaneous tunnel build requests per pool

pull/1833/head
orignal 2 years ago
parent
commit
cb139226df
  1. 2
      libi2pd/Tunnel.cpp
  2. 2
      libi2pd/Tunnel.h
  3. 22
      libi2pd/TunnelPool.cpp
  4. 1
      libi2pd/TunnelPool.h

2
libi2pd/Tunnel.cpp

@ -516,7 +516,7 @@ namespace tunnel @@ -516,7 +516,7 @@ namespace tunnel
LogPrint (eLogWarning, "Tunnel: Unexpected message type ", (int) typeID);
}
msg = (numMsgs <= MAX_NUM_TUNNEL_MSGS_AT_THE_TIME) ? m_Queue.Get () : nullptr;
msg = (numMsgs <= MAX_TUNNEL_MSGS_BATCH_SIZE) ? m_Queue.Get () : nullptr;
if (msg)
{
prevTunnelID = tunnelID;

2
libi2pd/Tunnel.h

@ -40,7 +40,7 @@ namespace tunnel @@ -40,7 +40,7 @@ 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 MAX_TUNNEL_MSGS_BATCH_SIZE = 100; // handle messages without interrupt
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

22
libi2pd/TunnelPool.cpp

@ -282,9 +282,14 @@ namespace tunnel @@ -282,9 +282,14 @@ namespace tunnel
for (const auto& it : m_OutboundTunnels)
if (it->IsEstablished ()) num++;
}
for (int i = num; i < m_NumOutboundTunnels; i++)
CreateOutboundTunnel ();
num = m_NumOutboundTunnels - num;
if (num > 0)
{
if (num > TUNNEL_POOL_MAX_NUM_BUILD_REQUESTS) num = TUNNEL_POOL_MAX_NUM_BUILD_REQUESTS;
for (int i = 0; i < num; i++)
CreateOutboundTunnel ();
}
num = 0;
{
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
@ -300,9 +305,14 @@ namespace tunnel @@ -300,9 +305,14 @@ namespace tunnel
if (num >= m_NumInboundTunnels) break;
}
}
for (int i = num; i < m_NumInboundTunnels; i++)
CreateInboundTunnel ();
num = m_NumInboundTunnels - num;
if (num > 0)
{
if (num > TUNNEL_POOL_MAX_NUM_BUILD_REQUESTS) num = TUNNEL_POOL_MAX_NUM_BUILD_REQUESTS;
for (int i = 0; i < num; i++)
CreateInboundTunnel ();
}
if (num < m_NumInboundTunnels && m_NumInboundHops <= 0 && m_LocalDestination) // zero hops IB
m_LocalDestination->SetLeaseSetUpdated (); // update LeaseSet immediately
}

1
libi2pd/TunnelPool.h

@ -30,6 +30,7 @@ namespace tunnel @@ -30,6 +30,7 @@ namespace tunnel
const int TUNNEL_POOL_MANAGE_INTERVAL = 10; // in seconds
const int TUNNEL_POOL_MAX_INBOUND_TUNNELS_QUANTITY = 16;
const int TUNNEL_POOL_MAX_OUTBOUND_TUNNELS_QUANTITY = 16;
const int TUNNEL_POOL_MAX_NUM_BUILD_REQUESTS = 2;
class Tunnel;
class InboundTunnel;

Loading…
Cancel
Save