Browse Source

don't compare OBEP hash twice to check if it's a fresh tunnel

pull/2052/head
orignal 9 months ago
parent
commit
9a30068ae5
  1. 4
      libi2pd/Streaming.cpp
  2. 10
      libi2pd/TunnelPool.cpp
  3. 2
      libi2pd/TunnelPool.h

4
libi2pd/Streaming.cpp

@ -927,9 +927,7 @@ namespace stream
else if (!m_CurrentOutboundTunnel->IsEstablished ()) else if (!m_CurrentOutboundTunnel->IsEstablished ())
{ {
auto oldOutboundTunnel = m_CurrentOutboundTunnel; auto oldOutboundTunnel = m_CurrentOutboundTunnel;
m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ()->GetTunnelPool ()->GetNewOutboundTunnel (m_CurrentOutboundTunnel); std::tie(m_CurrentOutboundTunnel, freshTunnel) = m_LocalDestination.GetOwner ()->GetTunnelPool ()->GetNewOutboundTunnel (m_CurrentOutboundTunnel);
if (m_CurrentOutboundTunnel && oldOutboundTunnel->GetEndpointIdentHash() != m_CurrentOutboundTunnel->GetEndpointIdentHash())
freshTunnel = true;
} }
if (!m_CurrentOutboundTunnel) if (!m_CurrentOutboundTunnel)
{ {

10
libi2pd/TunnelPool.cpp

@ -263,10 +263,11 @@ namespace tunnel
return tunnel; return tunnel;
} }
std::shared_ptr<OutboundTunnel> TunnelPool::GetNewOutboundTunnel (std::shared_ptr<OutboundTunnel> old) const std::pair<std::shared_ptr<OutboundTunnel>, bool> TunnelPool::GetNewOutboundTunnel (std::shared_ptr<OutboundTunnel> old) const
{ {
if (old && old->IsEstablished ()) return old; if (old && old->IsEstablished ()) return std::make_pair(old, false);
std::shared_ptr<OutboundTunnel> tunnel; std::shared_ptr<OutboundTunnel> tunnel;
bool freshTunnel = false;
if (old) if (old)
{ {
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex); std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
@ -279,8 +280,11 @@ namespace tunnel
} }
if (!tunnel) if (!tunnel)
{
tunnel = GetNextOutboundTunnel (); tunnel = GetNextOutboundTunnel ();
return tunnel; freshTunnel = true;
}
return std::make_pair(tunnel, freshTunnel);
} }
void TunnelPool::CreateTunnels () void TunnelPool::CreateTunnels ()

2
libi2pd/TunnelPool.h

@ -81,7 +81,7 @@ namespace tunnel
i2p::data::RouterInfo::CompatibleTransports compatible = i2p::data::RouterInfo::eAllTransports) const; i2p::data::RouterInfo::CompatibleTransports compatible = i2p::data::RouterInfo::eAllTransports) const;
std::shared_ptr<InboundTunnel> GetNextInboundTunnel (std::shared_ptr<InboundTunnel> excluded = nullptr, std::shared_ptr<InboundTunnel> GetNextInboundTunnel (std::shared_ptr<InboundTunnel> excluded = nullptr,
i2p::data::RouterInfo::CompatibleTransports compatible = i2p::data::RouterInfo::eAllTransports) const; i2p::data::RouterInfo::CompatibleTransports compatible = i2p::data::RouterInfo::eAllTransports) const;
std::shared_ptr<OutboundTunnel> GetNewOutboundTunnel (std::shared_ptr<OutboundTunnel> old) const; std::pair<std::shared_ptr<OutboundTunnel>, bool> GetNewOutboundTunnel (std::shared_ptr<OutboundTunnel> old) const;
void ManageTunnels (uint64_t ts); void ManageTunnels (uint64_t ts);
void ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg); void ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg);
void ProcessDeliveryStatus (std::shared_ptr<I2NPMessage> msg); void ProcessDeliveryStatus (std::shared_ptr<I2NPMessage> msg);

Loading…
Cancel
Save