Browse Source

fixed race condition

pull/97/head
orignal 10 years ago
parent
commit
92eb048adb
  1. 4
      Tunnel.cpp
  2. 1
      Tunnel.h
  3. 7
      TunnelPool.cpp

4
Tunnel.cpp

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

1
Tunnel.h

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

7
TunnelPool.cpp

@ -260,6 +260,8 @@ namespace tunnel @@ -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 @@ -267,10 +269,15 @@ namespace tunnel
InboundTunnel * inboundTunnel = GetNextInboundTunnel ();
if (!inboundTunnel)
inboundTunnel = tunnels.GetNextInboundTunnel ();
if (inboundTunnel)
{
LogPrint ("Re-creating destination outbound tunnel...");
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");
}
}
}

Loading…
Cancel
Save