diff --git a/Tunnel.cpp b/Tunnel.cpp index 1dbcd8fc..3cbd628d 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -301,6 +301,7 @@ namespace tunnel void Tunnels::AddTransitTunnel (TransitTunnel * tunnel) { + std::unique_lock l(m_TransitTunnelsMutex); m_TransitTunnels[tunnel->GetTunnelID ()] = tunnel; } @@ -490,7 +491,10 @@ namespace tunnel { LogPrint ("Transit tunnel ", it->second->GetTunnelID (), " expired"); auto tmp = it->second; - it = m_TransitTunnels.erase (it); + { + std::unique_lock l(m_TransitTunnelsMutex); + it = m_TransitTunnels.erase (it); + } delete tmp; } else diff --git a/Tunnel.h b/Tunnel.h index e1c0c253..a848e6b7 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -152,6 +152,7 @@ namespace tunnel std::map m_InboundTunnels; std::mutex m_OutboundTunnelsMutex; std::list m_OutboundTunnels; + std::mutex m_TransitTunnelsMutex; std::map m_TransitTunnels; std::map m_Pools; TunnelPool * m_ExploratoryPool; diff --git a/TunnelPool.cpp b/TunnelPool.cpp index e28a9b07..fc725238 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -260,6 +260,8 @@ namespace tunnel new TunnelConfig (hops, inboundTunnel->GetTunnelConfig ())); tunnel->SetTunnelPool (this); } + else + LogPrint ("Can't create outbound tunnel. No inbound tunnels found"); } void TunnelPool::RecreateOutboundTunnel (OutboundTunnel * tunnel) @@ -267,10 +269,15 @@ namespace tunnel InboundTunnel * inboundTunnel = GetNextInboundTunnel (); if (!inboundTunnel) inboundTunnel = tunnels.GetNextInboundTunnel (); - LogPrint ("Re-creating destination outbound tunnel..."); - auto * newTunnel = tunnels.CreateTunnel ( - tunnel->GetTunnelConfig ()->Clone (inboundTunnel->GetTunnelConfig ())); - newTunnel->SetTunnelPool (this); + if (inboundTunnel) + { + LogPrint ("Re-creating destination outbound tunnel..."); + auto * newTunnel = tunnels.CreateTunnel ( + tunnel->GetTunnelConfig ()->Clone (inboundTunnel->GetTunnelConfig ())); + newTunnel->SetTunnelPool (this); + } + else + LogPrint ("Can't re-create outbound tunnel. No inbound tunnels found"); } } }