From 9abd383014ae33e89a17bd43cccc35bf010d98ed Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 13 Nov 2021 15:11:59 -0500 Subject: [PATCH] eliminate extra pointers for tunnel hops --- libi2pd/Tunnel.cpp | 19 +++++++++++-------- libi2pd/Tunnel.h | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libi2pd/Tunnel.cpp b/libi2pd/Tunnel.cpp index ad048bb8..24d2c668 100644 --- a/libi2pd/Tunnel.cpp +++ b/libi2pd/Tunnel.cpp @@ -156,6 +156,7 @@ namespace tunnel } bool established = true; + size_t numHops = 0; hop = m_Config->GetFirstHop (); while (hop) { @@ -168,18 +169,20 @@ namespace tunnel // if any of participants declined the tunnel is not established established = false; hop = hop->next; + numHops++; } if (established) { // create tunnel decryptions from layer and iv keys in reverse order + m_Hops.resize (numHops); hop = m_Config->GetLastHop (); + int i = 0; while (hop) { - auto tunnelHop = new TunnelHop; - tunnelHop->ident = hop->ident; - tunnelHop->decryption.SetKeys (hop->layerKey, hop->ivKey); - m_Hops.push_back (std::unique_ptr(tunnelHop)); + m_Hops[i].ident = hop->ident; + m_Hops[i].decryption.SetKeys (hop->layerKey, hop->ivKey); hop = hop->prev; + i++; } m_IsShortBuildMessage = m_Config->IsShort (); m_FarEndTransports = m_Config->GetFarEndTransports (); @@ -201,7 +204,7 @@ namespace tunnel uint8_t * outPayload = out->GetPayload () + 4; for (auto& it: m_Hops) { - it->decryption.Decrypt (inPayload, outPayload); + it.decryption.Decrypt (inPayload, outPayload); inPayload = outPayload; } } @@ -222,8 +225,8 @@ namespace tunnel { // hops are in inverted order std::vector > ret; - for (auto& it: m_Hops) - ret.push_back (it->ident); + for (const auto& it: m_Hops) + ret.push_back (it.ident); return ret; } @@ -239,7 +242,7 @@ namespace tunnel for (auto it = m_Hops.rbegin (); it != m_Hops.rend (); it++) { s << " ⇒ "; - s << i2p::data::GetIdentHashAbbreviation ((*it)->ident->GetIdentHash ()); + s << i2p::data::GetIdentHashAbbreviation ((*it).ident->GetIdentHash ()); } } diff --git a/libi2pd/Tunnel.h b/libi2pd/Tunnel.h index 3ab366c8..cfd54d26 100644 --- a/libi2pd/Tunnel.h +++ b/libi2pd/Tunnel.h @@ -114,7 +114,7 @@ namespace tunnel private: std::shared_ptr m_Config; - std::vector > m_Hops; + std::vector m_Hops; bool m_IsShortBuildMessage; std::shared_ptr m_Pool; // pool, tunnel belongs to, or null TunnelState m_State;