This commit is contained in:
dr|z3d 2021-09-11 10:38:43 +00:00
commit 05f366bc28
3 changed files with 19 additions and 6 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2020, The PurpleI2P Project
* Copyright (c) 2013-2021, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -705,7 +705,7 @@ namespace tunnel
// let it die if the tunnel pool has been reconfigured and this is old
if (pool && tunnel->GetNumHops() == pool->GetNumOutboundHops())
{
tunnel->SetIsRecreated ();
tunnel->SetRecreated (true);
pool->RecreateOutboundTunnel (tunnel);
}
}
@ -759,7 +759,7 @@ namespace tunnel
// let it die if the tunnel pool was reconfigured and has different number of hops
if (pool && tunnel->GetNumHops() == pool->GetNumInboundHops())
{
tunnel->SetIsRecreated ();
tunnel->SetRecreated (true);
pool->RecreateInboundTunnel (tunnel);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2020, The PurpleI2P Project
* Copyright (c) 2013-2021, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -76,7 +76,7 @@ namespace tunnel
bool IsEstablished () const { return m_State == eTunnelStateEstablished; };
bool IsFailed () const { return m_State == eTunnelStateFailed; };
bool IsRecreated () const { return m_IsRecreated; };
void SetIsRecreated () { m_IsRecreated = true; };
void SetRecreated (bool recreated) { m_IsRecreated = recreated; };
int GetNumHops () const { return m_Hops.size (); };
virtual bool IsInbound() const = 0;
@ -111,7 +111,7 @@ namespace tunnel
std::vector<std::unique_ptr<TunnelHop> > m_Hops;
std::shared_ptr<TunnelPool> m_Pool; // pool, tunnel belongs to, or null
TunnelState m_State;
bool m_IsRecreated;
bool m_IsRecreated; // if tunnel is replaced by new, or new tunnel requested to replace
uint64_t m_Latency; // in milliseconds
};

View file

@ -113,6 +113,17 @@ namespace tunnel
if (!m_IsActive) return;
{
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
if (createdTunnel->IsRecreated ())
{
// find and mark old tunnel as expired
createdTunnel->SetRecreated (false);
for (auto& it: m_InboundTunnels)
if (it->IsRecreated () && it->GetNextIdentHash () == createdTunnel->GetNextIdentHash ())
{
it->SetState (eTunnelStateExpiring);
break;
}
}
m_InboundTunnels.insert (createdTunnel);
}
if (m_LocalDestination)
@ -577,6 +588,8 @@ namespace tunnel
auto newTunnel = tunnels.CreateInboundTunnel (config, shared_from_this(), outboundTunnel);
if (newTunnel->IsEstablished ()) // zero hops
TunnelCreated (newTunnel);
else
newTunnel->SetRecreated (true);
}
}