mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 02:44:15 +00:00
don't include old tunnel to LeaseSet if recreated
This commit is contained in:
parent
ad036de69d
commit
5e2e1a1e3d
@ -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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@ -692,7 +692,7 @@ namespace tunnel
|
|||||||
// let it die if the tunnel pool has been reconfigured and this is old
|
// let it die if the tunnel pool has been reconfigured and this is old
|
||||||
if (pool && tunnel->GetNumHops() == pool->GetNumOutboundHops())
|
if (pool && tunnel->GetNumHops() == pool->GetNumOutboundHops())
|
||||||
{
|
{
|
||||||
tunnel->SetIsRecreated ();
|
tunnel->SetRecreated (true);
|
||||||
pool->RecreateOutboundTunnel (tunnel);
|
pool->RecreateOutboundTunnel (tunnel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -746,7 +746,7 @@ namespace tunnel
|
|||||||
// let it die if the tunnel pool was reconfigured and has different number of hops
|
// let it die if the tunnel pool was reconfigured and has different number of hops
|
||||||
if (pool && tunnel->GetNumHops() == pool->GetNumInboundHops())
|
if (pool && tunnel->GetNumHops() == pool->GetNumInboundHops())
|
||||||
{
|
{
|
||||||
tunnel->SetIsRecreated ();
|
tunnel->SetRecreated (true);
|
||||||
pool->RecreateInboundTunnel (tunnel);
|
pool->RecreateInboundTunnel (tunnel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
* 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 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; };
|
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 (); };
|
int GetNumHops () const { return m_Hops.size (); };
|
||||||
virtual bool IsInbound() const = 0;
|
virtual bool IsInbound() const = 0;
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ namespace tunnel
|
|||||||
std::vector<std::unique_ptr<TunnelHop> > m_Hops;
|
std::vector<std::unique_ptr<TunnelHop> > m_Hops;
|
||||||
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;
|
bool m_IsRecreated; // if tunnel is replaced by new, or new tunnel requested to replace
|
||||||
uint64_t m_Latency; // in milliseconds
|
uint64_t m_Latency; // in milliseconds
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -113,6 +113,17 @@ namespace tunnel
|
|||||||
if (!m_IsActive) return;
|
if (!m_IsActive) return;
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
|
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);
|
m_InboundTunnels.insert (createdTunnel);
|
||||||
}
|
}
|
||||||
if (m_LocalDestination)
|
if (m_LocalDestination)
|
||||||
@ -577,6 +588,8 @@ namespace tunnel
|
|||||||
auto newTunnel = tunnels.CreateInboundTunnel (config, shared_from_this(), outboundTunnel);
|
auto newTunnel = tunnels.CreateInboundTunnel (config, shared_from_this(), outboundTunnel);
|
||||||
if (newTunnel->IsEstablished ()) // zero hops
|
if (newTunnel->IsEstablished ()) // zero hops
|
||||||
TunnelCreated (newTunnel);
|
TunnelCreated (newTunnel);
|
||||||
|
else
|
||||||
|
newTunnel->SetRecreated (true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user