mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-10 11:28:27 +01:00
recreate tunnel after 9.5 minutes
This commit is contained in:
parent
fcb56db224
commit
3987d5e5a0
3 changed files with 29 additions and 11 deletions
33
Tunnel.cpp
33
Tunnel.cpp
|
@ -18,7 +18,7 @@ namespace tunnel
|
||||||
{
|
{
|
||||||
|
|
||||||
Tunnel::Tunnel (TunnelConfig * config):
|
Tunnel::Tunnel (TunnelConfig * config):
|
||||||
m_Config (config), m_Pool (nullptr), m_State (eTunnelStatePending)
|
m_Config (config), m_Pool (nullptr), m_State (eTunnelStatePending), m_IsRecreated (false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,12 +542,17 @@ namespace tunnel
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (tunnel->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
if (tunnel->IsEstablished ())
|
||||||
{
|
{
|
||||||
tunnel->SetState (eTunnelStateExpiring);
|
if (!tunnel->IsRecreated () && ts + TUNNEL_RECREATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
||||||
auto pool = tunnel->GetTunnelPool ();
|
{
|
||||||
if (pool)
|
tunnel->SetIsRecreated ();
|
||||||
pool->RecreateOutboundTunnel (tunnel);
|
auto pool = tunnel->GetTunnelPool ();
|
||||||
|
if (pool)
|
||||||
|
pool->RecreateOutboundTunnel (tunnel);
|
||||||
|
}
|
||||||
|
if (ts + TUNNEL_EXPIRATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
||||||
|
tunnel->SetState (eTunnelStateExpiring);
|
||||||
}
|
}
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
@ -585,12 +590,18 @@ namespace tunnel
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (tunnel->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
if (tunnel->IsEstablished ())
|
||||||
{
|
{
|
||||||
tunnel->SetState (eTunnelStateExpiring);
|
if (!tunnel->IsRecreated () && ts + TUNNEL_RECREATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
||||||
auto pool = tunnel->GetTunnelPool ();
|
{
|
||||||
if (pool)
|
tunnel->SetIsRecreated ();
|
||||||
pool->RecreateInboundTunnel (tunnel);
|
auto pool = tunnel->GetTunnelPool ();
|
||||||
|
if (pool)
|
||||||
|
pool->RecreateInboundTunnel (tunnel);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ts + TUNNEL_EXPIRATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
||||||
|
tunnel->SetState (eTunnelStateExpiring);
|
||||||
}
|
}
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
4
Tunnel.h
4
Tunnel.h
|
@ -24,6 +24,7 @@ namespace tunnel
|
||||||
{
|
{
|
||||||
const int TUNNEL_EXPIRATION_TIMEOUT = 660; // 11 minutes
|
const int TUNNEL_EXPIRATION_TIMEOUT = 660; // 11 minutes
|
||||||
const int TUNNEL_EXPIRATION_THRESHOLD = 60; // 1 minute
|
const int TUNNEL_EXPIRATION_THRESHOLD = 60; // 1 minute
|
||||||
|
const int TUNNEL_RECREATION_THRESHOLD = 90; // 1.5 minutes
|
||||||
const int TUNNEL_CREATION_TIMEOUT = 30; // 30 seconds
|
const int TUNNEL_CREATION_TIMEOUT = 30; // 30 seconds
|
||||||
const int STANDARD_NUM_RECORDS = 5; // in VariableTunnelBuild message
|
const int STANDARD_NUM_RECORDS = 5; // in VariableTunnelBuild message
|
||||||
|
|
||||||
|
@ -54,6 +55,8 @@ namespace tunnel
|
||||||
void SetState (TunnelState state) { m_State = state; };
|
void SetState (TunnelState state) { m_State = state; };
|
||||||
bool IsEstablished () const { return m_State == eTunnelStateEstablished; };
|
bool IsEstablished () const { return m_State == eTunnelStateEstablished; };
|
||||||
bool IsFailed () const { return m_State == eTunnelStateFailed; };
|
bool IsFailed () const { return m_State == eTunnelStateFailed; };
|
||||||
|
bool IsRecreated () const { return m_IsRecreated; };
|
||||||
|
void SetIsRecreated () { m_IsRecreated = true; };
|
||||||
|
|
||||||
std::shared_ptr<TunnelPool> GetTunnelPool () const { return m_Pool; };
|
std::shared_ptr<TunnelPool> GetTunnelPool () const { return m_Pool; };
|
||||||
void SetTunnelPool (std::shared_ptr<TunnelPool> pool) { m_Pool = pool; };
|
void SetTunnelPool (std::shared_ptr<TunnelPool> pool) { m_Pool = pool; };
|
||||||
|
@ -71,6 +74,7 @@ namespace tunnel
|
||||||
TunnelConfig * m_Config;
|
TunnelConfig * m_Config;
|
||||||
std::shared_ptr<TunnelPool> m_Pool; // pool, tunnel belongs to, or null
|
std::shared_ptr<TunnelPool> m_Pool; // pool, tunnel belongs to, or null
|
||||||
TunnelState m_State;
|
TunnelState m_State;
|
||||||
|
bool m_IsRecreated;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OutboundTunnel: public Tunnel
|
class OutboundTunnel: public Tunnel
|
||||||
|
|
|
@ -140,7 +140,10 @@ namespace tunnel
|
||||||
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
|
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
|
||||||
for (auto it: m_OutboundTunnels)
|
for (auto it: m_OutboundTunnels)
|
||||||
if (it->IsEstablished () && old->GetEndpointRouter ()->GetIdentHash () == it->GetEndpointRouter ()->GetIdentHash ())
|
if (it->IsEstablished () && old->GetEndpointRouter ()->GetIdentHash () == it->GetEndpointRouter ()->GetIdentHash ())
|
||||||
|
{
|
||||||
tunnel = it;
|
tunnel = it;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tunnel)
|
if (!tunnel)
|
||||||
|
|
Loading…
Add table
Reference in a new issue