1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-22 04:04:16 +00:00

fixed race condition

This commit is contained in:
orignal 2014-09-14 07:50:01 -04:00
parent 5c2785cfca
commit 92eb048adb
3 changed files with 17 additions and 5 deletions

View File

@ -301,6 +301,7 @@ namespace tunnel
void Tunnels::AddTransitTunnel (TransitTunnel * tunnel) void Tunnels::AddTransitTunnel (TransitTunnel * tunnel)
{ {
std::unique_lock<std::mutex> l(m_TransitTunnelsMutex);
m_TransitTunnels[tunnel->GetTunnelID ()] = tunnel; m_TransitTunnels[tunnel->GetTunnelID ()] = tunnel;
} }
@ -490,7 +491,10 @@ namespace tunnel
{ {
LogPrint ("Transit tunnel ", it->second->GetTunnelID (), " expired"); LogPrint ("Transit tunnel ", it->second->GetTunnelID (), " expired");
auto tmp = it->second; auto tmp = it->second;
it = m_TransitTunnels.erase (it); {
std::unique_lock<std::mutex> l(m_TransitTunnelsMutex);
it = m_TransitTunnels.erase (it);
}
delete tmp; delete tmp;
} }
else else

View File

@ -152,6 +152,7 @@ namespace tunnel
std::map<uint32_t, InboundTunnel *> m_InboundTunnels; std::map<uint32_t, InboundTunnel *> m_InboundTunnels;
std::mutex m_OutboundTunnelsMutex; std::mutex m_OutboundTunnelsMutex;
std::list<OutboundTunnel *> m_OutboundTunnels; std::list<OutboundTunnel *> m_OutboundTunnels;
std::mutex m_TransitTunnelsMutex;
std::map<uint32_t, TransitTunnel *> m_TransitTunnels; std::map<uint32_t, TransitTunnel *> m_TransitTunnels;
std::map<i2p::data::IdentHash, TunnelPool *> m_Pools; std::map<i2p::data::IdentHash, TunnelPool *> m_Pools;
TunnelPool * m_ExploratoryPool; TunnelPool * m_ExploratoryPool;

View File

@ -260,6 +260,8 @@ namespace tunnel
new TunnelConfig (hops, inboundTunnel->GetTunnelConfig ())); new TunnelConfig (hops, inboundTunnel->GetTunnelConfig ()));
tunnel->SetTunnelPool (this); tunnel->SetTunnelPool (this);
} }
else
LogPrint ("Can't create outbound tunnel. No inbound tunnels found");
} }
void TunnelPool::RecreateOutboundTunnel (OutboundTunnel * tunnel) void TunnelPool::RecreateOutboundTunnel (OutboundTunnel * tunnel)
@ -267,10 +269,15 @@ namespace tunnel
InboundTunnel * inboundTunnel = GetNextInboundTunnel (); InboundTunnel * inboundTunnel = GetNextInboundTunnel ();
if (!inboundTunnel) if (!inboundTunnel)
inboundTunnel = tunnels.GetNextInboundTunnel (); inboundTunnel = tunnels.GetNextInboundTunnel ();
LogPrint ("Re-creating destination outbound tunnel..."); if (inboundTunnel)
auto * newTunnel = tunnels.CreateTunnel<OutboundTunnel> ( {
tunnel->GetTunnelConfig ()->Clone (inboundTunnel->GetTunnelConfig ())); LogPrint ("Re-creating destination outbound tunnel...");
newTunnel->SetTunnelPool (this); auto * newTunnel = tunnels.CreateTunnel<OutboundTunnel> (
tunnel->GetTunnelConfig ()->Clone (inboundTunnel->GetTunnelConfig ()));
newTunnel->SetTunnelPool (this);
}
else
LogPrint ("Can't re-create outbound tunnel. No inbound tunnels found");
} }
} }
} }