|
|
@ -396,22 +396,25 @@ namespace tunnel |
|
|
|
void Tunnels::ManageOutboundTunnels () |
|
|
|
void Tunnels::ManageOutboundTunnels () |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch (); |
|
|
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch (); |
|
|
|
for (auto it = m_OutboundTunnels.begin (); it != m_OutboundTunnels.end ();) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ts > (*it)->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) |
|
|
|
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex); |
|
|
|
|
|
|
|
for (auto it = m_OutboundTunnels.begin (); it != m_OutboundTunnels.end ();) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Tunnel ", (*it)->GetTunnelID (), " expired"); |
|
|
|
if (ts > (*it)->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) |
|
|
|
auto pool = (*it)->GetTunnelPool (); |
|
|
|
{ |
|
|
|
if (pool) |
|
|
|
LogPrint ("Tunnel ", (*it)->GetTunnelID (), " expired"); |
|
|
|
pool->TunnelExpired (*it); |
|
|
|
auto pool = (*it)->GetTunnelPool (); |
|
|
|
delete *it; |
|
|
|
if (pool) |
|
|
|
it = m_OutboundTunnels.erase (it); |
|
|
|
pool->TunnelExpired (*it); |
|
|
|
} |
|
|
|
delete *it; |
|
|
|
else |
|
|
|
it = m_OutboundTunnels.erase (it); |
|
|
|
{ |
|
|
|
} |
|
|
|
if ((*it)->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > (*it)->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) |
|
|
|
else |
|
|
|
(*it)->SetState (eTunnelStateExpiring); |
|
|
|
{ |
|
|
|
it++; |
|
|
|
if ((*it)->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > (*it)->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) |
|
|
|
|
|
|
|
(*it)->SetState (eTunnelStateExpiring); |
|
|
|
|
|
|
|
it++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -433,22 +436,25 @@ namespace tunnel |
|
|
|
void Tunnels::ManageInboundTunnels () |
|
|
|
void Tunnels::ManageInboundTunnels () |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch (); |
|
|
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch (); |
|
|
|
for (auto it = m_InboundTunnels.begin (); it != m_InboundTunnels.end ();) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ts > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) |
|
|
|
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex); |
|
|
|
|
|
|
|
for (auto it = m_InboundTunnels.begin (); it != m_InboundTunnels.end ();) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Tunnel ", it->second->GetTunnelID (), " expired"); |
|
|
|
if (ts > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) |
|
|
|
auto pool = it->second->GetTunnelPool (); |
|
|
|
{ |
|
|
|
if (pool) |
|
|
|
LogPrint ("Tunnel ", it->second->GetTunnelID (), " expired"); |
|
|
|
pool->TunnelExpired (it->second); |
|
|
|
auto pool = it->second->GetTunnelPool (); |
|
|
|
delete it->second; |
|
|
|
if (pool) |
|
|
|
it = m_InboundTunnels.erase (it); |
|
|
|
pool->TunnelExpired (it->second); |
|
|
|
} |
|
|
|
delete it->second; |
|
|
|
else |
|
|
|
it = m_InboundTunnels.erase (it); |
|
|
|
{ |
|
|
|
} |
|
|
|
if (it->second->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) |
|
|
|
else |
|
|
|
it->second->SetState (eTunnelStateExpiring); |
|
|
|
{ |
|
|
|
it++; |
|
|
|
if (it->second->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) |
|
|
|
|
|
|
|
it->second->SetState (eTunnelStateExpiring); |
|
|
|
|
|
|
|
it++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -516,6 +522,7 @@ namespace tunnel |
|
|
|
|
|
|
|
|
|
|
|
void Tunnels::AddOutboundTunnel (OutboundTunnel * newTunnel) |
|
|
|
void Tunnels::AddOutboundTunnel (OutboundTunnel * newTunnel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex); |
|
|
|
m_OutboundTunnels.push_back (newTunnel); |
|
|
|
m_OutboundTunnels.push_back (newTunnel); |
|
|
|
auto pool = newTunnel->GetTunnelPool (); |
|
|
|
auto pool = newTunnel->GetTunnelPool (); |
|
|
|
if (pool) |
|
|
|
if (pool) |
|
|
@ -524,6 +531,7 @@ namespace tunnel |
|
|
|
|
|
|
|
|
|
|
|
void Tunnels::AddInboundTunnel (InboundTunnel * newTunnel) |
|
|
|
void Tunnels::AddInboundTunnel (InboundTunnel * newTunnel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex); |
|
|
|
m_InboundTunnels[newTunnel->GetTunnelID ()] = newTunnel; |
|
|
|
m_InboundTunnels[newTunnel->GetTunnelID ()] = newTunnel; |
|
|
|
auto pool = newTunnel->GetTunnelPool (); |
|
|
|
auto pool = newTunnel->GetTunnelPool (); |
|
|
|
if (!pool) |
|
|
|
if (!pool) |
|
|
|