mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-23 17:34:21 +00:00
don't build tunnels for all pools at the time
This commit is contained in:
parent
af20b13c7a
commit
44ca315c75
@ -474,7 +474,7 @@ namespace tunnel
|
|||||||
{
|
{
|
||||||
std::this_thread::sleep_for (std::chrono::seconds(1)); // wait for other parts are ready
|
std::this_thread::sleep_for (std::chrono::seconds(1)); // wait for other parts are ready
|
||||||
|
|
||||||
uint64_t lastTs = 0;
|
uint64_t lastTs = 0, lastPoolsTs = 0;
|
||||||
while (m_IsRunning)
|
while (m_IsRunning)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -535,12 +535,20 @@ namespace tunnel
|
|||||||
while (msg);
|
while (msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
if (i2p::transport::transports.IsOnline())
|
||||||
if (ts - lastTs >= 15 && i2p::transport::transports.IsOnline()) // manage tunnels every 15 seconds
|
|
||||||
{
|
{
|
||||||
ManageTunnels ();
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
lastTs = ts;
|
if (ts - lastTs >= 15) // manage tunnels every 15 seconds
|
||||||
}
|
{
|
||||||
|
ManageTunnels ();
|
||||||
|
lastTs = ts;
|
||||||
|
}
|
||||||
|
if (ts - lastPoolsTs >= 5) // manage pools every 5 seconds
|
||||||
|
{
|
||||||
|
ManageTunnelPools (ts);
|
||||||
|
lastPoolsTs = ts;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception& ex)
|
catch (std::exception& ex)
|
||||||
{
|
{
|
||||||
@ -582,7 +590,6 @@ namespace tunnel
|
|||||||
ManageInboundTunnels ();
|
ManageInboundTunnels ();
|
||||||
ManageOutboundTunnels ();
|
ManageOutboundTunnels ();
|
||||||
ManageTransitTunnels ();
|
ManageTransitTunnels ();
|
||||||
ManageTunnelPools ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tunnels::ManagePendingTunnels ()
|
void Tunnels::ManagePendingTunnels ()
|
||||||
@ -794,16 +801,13 @@ namespace tunnel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tunnels::ManageTunnelPools ()
|
void Tunnels::ManageTunnelPools (uint64_t ts)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> l(m_PoolsMutex);
|
std::unique_lock<std::mutex> l(m_PoolsMutex);
|
||||||
for (auto& pool : m_Pools)
|
for (auto& pool : m_Pools)
|
||||||
{
|
{
|
||||||
if (pool && pool->IsActive ())
|
if (pool && pool->IsActive ())
|
||||||
{
|
pool->ManageTunnels (ts);
|
||||||
pool->CreateTunnels ();
|
|
||||||
pool->TestTunnels ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ namespace tunnel
|
|||||||
void ManagePendingTunnels ();
|
void ManagePendingTunnels ();
|
||||||
template<class PendingTunnels>
|
template<class PendingTunnels>
|
||||||
void ManagePendingTunnels (PendingTunnels& pendingTunnels);
|
void ManagePendingTunnels (PendingTunnels& pendingTunnels);
|
||||||
void ManageTunnelPools ();
|
void ManageTunnelPools (uint64_t ts);
|
||||||
|
|
||||||
std::shared_ptr<ZeroHopsInboundTunnel> CreateZeroHopsInboundTunnel ();
|
std::shared_ptr<ZeroHopsInboundTunnel> CreateZeroHopsInboundTunnel ();
|
||||||
std::shared_ptr<ZeroHopsOutboundTunnel> CreateZeroHopsOutboundTunnel ();
|
std::shared_ptr<ZeroHopsOutboundTunnel> CreateZeroHopsOutboundTunnel ();
|
||||||
@ -249,7 +249,7 @@ namespace tunnel
|
|||||||
std::list<std::shared_ptr<TunnelPool>> m_Pools;
|
std::list<std::shared_ptr<TunnelPool>> m_Pools;
|
||||||
std::shared_ptr<TunnelPool> m_ExploratoryPool;
|
std::shared_ptr<TunnelPool> m_ExploratoryPool;
|
||||||
i2p::util::Queue<std::shared_ptr<I2NPMessage> > m_Queue;
|
i2p::util::Queue<std::shared_ptr<I2NPMessage> > m_Queue;
|
||||||
|
|
||||||
// some stats
|
// some stats
|
||||||
int m_NumSuccesiveTunnelCreations, m_NumFailedTunnelCreations;
|
int m_NumSuccesiveTunnelCreations, m_NumFailedTunnelCreations;
|
||||||
|
|
||||||
|
@ -26,9 +26,10 @@ namespace tunnel
|
|||||||
{
|
{
|
||||||
TunnelPool::TunnelPool (int numInboundHops, int numOutboundHops, int numInboundTunnels, int numOutboundTunnels):
|
TunnelPool::TunnelPool (int numInboundHops, int numOutboundHops, int numInboundTunnels, int numOutboundTunnels):
|
||||||
m_NumInboundHops (numInboundHops), m_NumOutboundHops (numOutboundHops),
|
m_NumInboundHops (numInboundHops), m_NumOutboundHops (numOutboundHops),
|
||||||
m_NumInboundTunnels (numInboundTunnels), m_NumOutboundTunnels (numOutboundTunnels), m_IsActive (true),
|
m_NumInboundTunnels (numInboundTunnels), m_NumOutboundTunnels (numOutboundTunnels),
|
||||||
m_CustomPeerSelector(nullptr)
|
m_IsActive (true), m_CustomPeerSelector(nullptr)
|
||||||
{
|
{
|
||||||
|
m_NextManageTime = i2p::util::GetSecondsSinceEpoch () + rand () % TUNNEL_POOL_MANAGE_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
TunnelPool::~TunnelPool ()
|
TunnelPool::~TunnelPool ()
|
||||||
@ -321,6 +322,16 @@ namespace tunnel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TunnelPool::ManageTunnels (uint64_t ts)
|
||||||
|
{
|
||||||
|
if (ts > m_NextManageTime)
|
||||||
|
{
|
||||||
|
CreateTunnels ();
|
||||||
|
TestTunnels ();
|
||||||
|
m_NextManageTime = ts + TUNNEL_POOL_MANAGE_INTERVAL + (rand () % TUNNEL_POOL_MANAGE_INTERVAL)/2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TunnelPool::ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg)
|
void TunnelPool::ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg)
|
||||||
{
|
{
|
||||||
if (m_LocalDestination)
|
if (m_LocalDestination)
|
||||||
|
@ -27,6 +27,8 @@ namespace i2p
|
|||||||
{
|
{
|
||||||
namespace tunnel
|
namespace tunnel
|
||||||
{
|
{
|
||||||
|
const int TUNNEL_POOL_MANAGE_INTERVAL = 10; // in seconds
|
||||||
|
|
||||||
class Tunnel;
|
class Tunnel;
|
||||||
class InboundTunnel;
|
class InboundTunnel;
|
||||||
class OutboundTunnel;
|
class OutboundTunnel;
|
||||||
@ -69,6 +71,7 @@ namespace tunnel
|
|||||||
std::shared_ptr<InboundTunnel> GetNextInboundTunnel (std::shared_ptr<InboundTunnel> excluded = nullptr) const;
|
std::shared_ptr<InboundTunnel> GetNextInboundTunnel (std::shared_ptr<InboundTunnel> excluded = nullptr) const;
|
||||||
std::shared_ptr<OutboundTunnel> GetNewOutboundTunnel (std::shared_ptr<OutboundTunnel> old) const;
|
std::shared_ptr<OutboundTunnel> GetNewOutboundTunnel (std::shared_ptr<OutboundTunnel> old) const;
|
||||||
void TestTunnels ();
|
void TestTunnels ();
|
||||||
|
void ManageTunnels (uint64_t ts);
|
||||||
void ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg);
|
void ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg);
|
||||||
void ProcessDeliveryStatus (std::shared_ptr<I2NPMessage> msg);
|
void ProcessDeliveryStatus (std::shared_ptr<I2NPMessage> msg);
|
||||||
|
|
||||||
@ -123,6 +126,7 @@ namespace tunnel
|
|||||||
mutable std::mutex m_TestsMutex;
|
mutable std::mutex m_TestsMutex;
|
||||||
std::map<uint32_t, std::pair<std::shared_ptr<OutboundTunnel>, std::shared_ptr<InboundTunnel> > > m_Tests;
|
std::map<uint32_t, std::pair<std::shared_ptr<OutboundTunnel>, std::shared_ptr<InboundTunnel> > > m_Tests;
|
||||||
bool m_IsActive;
|
bool m_IsActive;
|
||||||
|
uint64_t m_NextManageTime; // in seconds
|
||||||
std::mutex m_CustomPeerSelectorMutex;
|
std::mutex m_CustomPeerSelectorMutex;
|
||||||
ITunnelPeerSelector * m_CustomPeerSelector;
|
ITunnelPeerSelector * m_CustomPeerSelector;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user