mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
fixed race condition
This commit is contained in:
parent
0f3a68cd8e
commit
7fb93ca853
23
Tunnel.cpp
23
Tunnel.cpp
@ -243,6 +243,7 @@ namespace tunnel
|
||||
|
||||
Tunnel * Tunnels::GetPendingTunnel (uint32_t replyMsgID)
|
||||
{
|
||||
std::unique_lock<std::mutex> l(m_PendingTunnelsMutex);
|
||||
auto it = m_PendingTunnels.find(replyMsgID);
|
||||
if (it != m_PendingTunnels.end () && it->second->GetState () == eTunnelStatePending)
|
||||
{
|
||||
@ -299,6 +300,11 @@ namespace tunnel
|
||||
{
|
||||
if (pool)
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> l(m_PendingTunnelsMutex);
|
||||
for (auto it: m_PendingTunnels)
|
||||
if (it.second->GetTunnelPool () == pool) it.second->SetTunnelPool (nullptr);
|
||||
}
|
||||
std::unique_lock<std::mutex> l(m_PoolsMutex);
|
||||
m_Pools.erase (pool->GetIdentHash ());
|
||||
delete pool;
|
||||
@ -374,9 +380,19 @@ namespace tunnel
|
||||
}
|
||||
|
||||
void Tunnels::ManageTunnels ()
|
||||
{
|
||||
ManagePendingTunnels ();
|
||||
ManageInboundTunnels ();
|
||||
ManageOutboundTunnels ();
|
||||
ManageTransitTunnels ();
|
||||
ManageTunnelPools ();
|
||||
}
|
||||
|
||||
void Tunnels::ManagePendingTunnels ()
|
||||
{
|
||||
// check pending tunnel. delete failed or timeout
|
||||
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||
std::unique_lock<std::mutex> l(m_PendingTunnelsMutex);
|
||||
for (auto it = m_PendingTunnels.begin (); it != m_PendingTunnels.end ();)
|
||||
{
|
||||
auto tunnel = it->second;
|
||||
@ -405,12 +421,7 @@ namespace tunnel
|
||||
it = m_PendingTunnels.erase (it);
|
||||
}
|
||||
}
|
||||
|
||||
ManageInboundTunnels ();
|
||||
ManageOutboundTunnels ();
|
||||
ManageTransitTunnels ();
|
||||
ManageTunnelPools ();
|
||||
}
|
||||
}
|
||||
|
||||
void Tunnels::ManageOutboundTunnels ()
|
||||
{
|
||||
|
2
Tunnel.h
2
Tunnel.h
@ -139,6 +139,7 @@ namespace tunnel
|
||||
void ManageOutboundTunnels ();
|
||||
void ManageInboundTunnels ();
|
||||
void ManageTransitTunnels ();
|
||||
void ManagePendingTunnels ();
|
||||
void ManageTunnelPools ();
|
||||
|
||||
void CreateZeroHopsInboundTunnel ();
|
||||
@ -147,6 +148,7 @@ namespace tunnel
|
||||
|
||||
bool m_IsRunning;
|
||||
std::thread * m_Thread;
|
||||
std::mutex m_PendingTunnelsMutex;
|
||||
std::map<uint32_t, Tunnel *> m_PendingTunnels; // by replyMsgID
|
||||
std::mutex m_InboundTunnelsMutex;
|
||||
std::map<uint32_t, InboundTunnel *> m_InboundTunnels;
|
||||
|
@ -17,10 +17,16 @@ namespace tunnel
|
||||
|
||||
TunnelPool::~TunnelPool ()
|
||||
{
|
||||
for (auto it: m_InboundTunnels)
|
||||
it->SetTunnelPool (nullptr);
|
||||
for (auto it: m_OutboundTunnels)
|
||||
it->SetTunnelPool (nullptr);
|
||||
{
|
||||
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
|
||||
for (auto it: m_InboundTunnels)
|
||||
it->SetTunnelPool (nullptr);
|
||||
}
|
||||
{
|
||||
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
|
||||
for (auto it: m_OutboundTunnels)
|
||||
it->SetTunnelPool (nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void TunnelPool::TunnelCreated (InboundTunnel * createdTunnel)
|
||||
|
Loading…
Reference in New Issue
Block a user