|
|
@ -257,9 +257,6 @@ namespace tunnel |
|
|
|
|
|
|
|
|
|
|
|
Tunnels::~Tunnels () |
|
|
|
Tunnels::~Tunnels () |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (auto& it : m_TransitTunnels) |
|
|
|
|
|
|
|
delete it.second; |
|
|
|
|
|
|
|
m_TransitTunnels.clear (); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<InboundTunnel> Tunnels::GetInboundTunnel (uint32_t tunnelID) |
|
|
|
std::shared_ptr<InboundTunnel> Tunnels::GetInboundTunnel (uint32_t tunnelID) |
|
|
@ -270,7 +267,7 @@ namespace tunnel |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TransitTunnel * Tunnels::GetTransitTunnel (uint32_t tunnelID) |
|
|
|
std::shared_ptr<TransitTunnel> Tunnels::GetTransitTunnel (uint32_t tunnelID) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto it = m_TransitTunnels.find(tunnelID); |
|
|
|
auto it = m_TransitTunnels.find(tunnelID); |
|
|
|
if (it != m_TransitTunnels.end ()) |
|
|
|
if (it != m_TransitTunnels.end ()) |
|
|
@ -363,14 +360,11 @@ namespace tunnel |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Tunnels::AddTransitTunnel (TransitTunnel * tunnel) |
|
|
|
void Tunnels::AddTransitTunnel (std::shared_ptr<TransitTunnel> tunnel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::unique_lock<std::mutex> l(m_TransitTunnelsMutex); |
|
|
|
std::unique_lock<std::mutex> l(m_TransitTunnelsMutex); |
|
|
|
if (!m_TransitTunnels.insert (std::make_pair (tunnel->GetTunnelID (), tunnel)).second) |
|
|
|
if (!m_TransitTunnels.insert (std::make_pair (tunnel->GetTunnelID (), tunnel)).second) |
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogError, "Tunnel: transit tunnel with id ", tunnel->GetTunnelID (), " already exists"); |
|
|
|
LogPrint (eLogError, "Tunnel: transit tunnel with id ", tunnel->GetTunnelID (), " already exists"); |
|
|
|
delete tunnel; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Tunnels::Start () |
|
|
|
void Tunnels::Start () |
|
|
@ -404,10 +398,10 @@ namespace tunnel |
|
|
|
if (msg) |
|
|
|
if (msg) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint32_t prevTunnelID = 0, tunnelID = 0; |
|
|
|
uint32_t prevTunnelID = 0, tunnelID = 0; |
|
|
|
TunnelBase * prevTunnel = nullptr; |
|
|
|
std::shared_ptr<TunnelBase> prevTunnel; |
|
|
|
do |
|
|
|
do |
|
|
|
{ |
|
|
|
{ |
|
|
|
TunnelBase * tunnel = nullptr; |
|
|
|
std::shared_ptr<TunnelBase> tunnel; |
|
|
|
uint8_t typeID = msg->GetTypeID (); |
|
|
|
uint8_t typeID = msg->GetTypeID (); |
|
|
|
switch (typeID) |
|
|
|
switch (typeID) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -421,7 +415,7 @@ namespace tunnel |
|
|
|
prevTunnel->FlushTunnelDataMsgs (); |
|
|
|
prevTunnel->FlushTunnelDataMsgs (); |
|
|
|
|
|
|
|
|
|
|
|
if (!tunnel && typeID == eI2NPTunnelData) |
|
|
|
if (!tunnel && typeID == eI2NPTunnelData) |
|
|
|
tunnel = GetInboundTunnel (tunnelID).get (); |
|
|
|
tunnel = GetInboundTunnel (tunnelID); |
|
|
|
if (!tunnel) |
|
|
|
if (!tunnel) |
|
|
|
tunnel = GetTransitTunnel (tunnelID); |
|
|
|
tunnel = GetTransitTunnel (tunnelID); |
|
|
|
if (tunnel) |
|
|
|
if (tunnel) |
|
|
@ -471,7 +465,7 @@ namespace tunnel |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Tunnels::HandleTunnelGatewayMsg (TunnelBase * tunnel, std::shared_ptr<I2NPMessage> msg) |
|
|
|
void Tunnels::HandleTunnelGatewayMsg (std::shared_ptr<TunnelBase> tunnel, std::shared_ptr<I2NPMessage> msg) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!tunnel) |
|
|
|
if (!tunnel) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -690,7 +684,6 @@ namespace tunnel |
|
|
|
std::unique_lock<std::mutex> l(m_TransitTunnelsMutex); |
|
|
|
std::unique_lock<std::mutex> l(m_TransitTunnelsMutex); |
|
|
|
it = m_TransitTunnels.erase (it); |
|
|
|
it = m_TransitTunnels.erase (it); |
|
|
|
} |
|
|
|
} |
|
|
|
delete tmp; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
it++; |
|
|
|
it++; |
|
|
|