Browse Source

fixed race condition

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

6
Tunnel.cpp

@ -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

1
Tunnel.h

@ -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;

15
TunnelPool.cpp

@ -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");
} }
} }
} }

Loading…
Cancel
Save