From e67b72b837474825f641aefa27ab8ae71e34b74f Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 19 Jan 2026 08:42:20 -0500 Subject: [PATCH] store explicit peers instead pointer --- libi2pd/Destination.cpp | 19 +++++++------------ libi2pd/TunnelPool.cpp | 16 ++++++++-------- libi2pd/TunnelPool.h | 5 ++--- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index df476bab..458a29e5 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -41,7 +41,7 @@ namespace client int numTags = DEFAULT_TAGS_TO_SEND; bool isHighBandwidth = true; std::shared_ptr > explicitPeers; - std::vector trustedRouters; + std::string_view explicitPeersStr, trustedRoutersStr; try { if (params) @@ -61,13 +61,8 @@ namespace client ratchetsInboundTags = i2p::garlic::ECIESX25519_MIN_NUM_GENERATED_TAGS; SetNumRatchetInboundTags (ratchetsInboundTags); } - auto explicitPeersStr = (*params)[I2CP_PARAM_EXPLICIT_PEERS]; - if (!explicitPeersStr.empty ()) - explicitPeers = std::make_shared > (i2p::data::ExtractIdentHashes (explicitPeersStr)); - auto trustedRoutersStr = (*params)[I2CP_PARAM_TRUSTED_ROUTERS]; - if (!trustedRoutersStr.empty ()) - trustedRouters = i2p::data::ExtractIdentHashes (trustedRoutersStr); - + explicitPeersStr = (*params)[I2CP_PARAM_EXPLICIT_PEERS]; + trustedRoutersStr = (*params)[I2CP_PARAM_TRUSTED_ROUTERS]; m_Nickname = (*params)[I2CP_PARAM_INBOUND_NICKNAME]; if (m_Nickname.empty ()) // try outbound m_Nickname = (*params)[I2CP_PARAM_OUTBOUND_NICKNAME]; @@ -107,10 +102,10 @@ namespace client } SetNumTags (numTags); m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (inLen, outLen, inQty, outQty, inVar, outVar, isHighBandwidth); - if (explicitPeers) - m_Pool->SetExplicitPeers (explicitPeers); - if (!trustedRouters.empty ()) - m_Pool->SetTrustedRouters (trustedRouters); + if (!explicitPeersStr.empty ()) + m_Pool->SetExplicitPeers (i2p::data::ExtractIdentHashes (explicitPeersStr)); + if (!trustedRoutersStr.empty ()) + m_Pool->SetTrustedRouters (i2p::data::ExtractIdentHashes (trustedRoutersStr)); if(params) { int maxLatency = 0; diff --git a/libi2pd/TunnelPool.cpp b/libi2pd/TunnelPool.cpp index bfed6a7d..adb8f65f 100644 --- a/libi2pd/TunnelPool.cpp +++ b/libi2pd/TunnelPool.cpp @@ -67,12 +67,12 @@ namespace tunnel DetachTunnels (); } - void TunnelPool::SetExplicitPeers (std::shared_ptr > explicitPeers) + void TunnelPool::SetExplicitPeers (std::vector explicitPeers) { - m_ExplicitPeers = explicitPeers; - if (m_ExplicitPeers) + m_ExplicitPeers.swap (explicitPeers); + int size = m_ExplicitPeers.size (); + if (size > 0) { - int size = m_ExplicitPeers->size (); if (m_NumInboundHops > size) { m_NumInboundHops = size; @@ -633,7 +633,7 @@ namespace tunnel bool TunnelPool::SelectPeers (Path& path, bool isInbound) { // explicit peers in use - if (m_ExplicitPeers) return SelectExplicitPeers (path, isInbound); + if (!m_ExplicitPeers.empty ()) return SelectExplicitPeers (path, isInbound); // calculate num hops int numHops; if (isInbound) @@ -670,12 +670,12 @@ namespace tunnel bool TunnelPool::SelectExplicitPeers (Path& path, bool isInbound) { - if (!m_ExplicitPeers->size ()) return false; + if (m_ExplicitPeers.empty ()) return false; int numHops = isInbound ? m_NumInboundHops : m_NumOutboundHops; - if (numHops > (int)m_ExplicitPeers->size ()) numHops = m_ExplicitPeers->size (); + if (numHops > (int)m_ExplicitPeers.size ()) numHops = m_ExplicitPeers.size (); for (int i = 0; i < numHops; i++) { - auto& ident = (*m_ExplicitPeers)[i]; + auto& ident = m_ExplicitPeers[i]; auto r = i2p::data::netdb.FindRouter (ident); if (r) { diff --git a/libi2pd/TunnelPool.h b/libi2pd/TunnelPool.h index ef26f58d..5b602bd5 100644 --- a/libi2pd/TunnelPool.h +++ b/libi2pd/TunnelPool.h @@ -66,7 +66,7 @@ namespace tunnel std::shared_ptr GetLocalDestination () const { return m_LocalDestination; }; void SetLocalDestination (std::shared_ptr destination) { m_LocalDestination = destination; }; - void SetExplicitPeers (std::shared_ptr > explicitPeers); + void SetExplicitPeers (std::vector explicitPeers); void SetTrustedRouters (std::vector routers); void CreateTunnels (); @@ -138,8 +138,7 @@ namespace tunnel std::shared_ptr m_LocalDestination; int m_NumInboundHops, m_NumOutboundHops, m_NumInboundTunnels, m_NumOutboundTunnels, m_InboundVariance, m_OutboundVariance; - std::shared_ptr > m_ExplicitPeers; - std::vector m_TrustedRouters; + std::vector m_ExplicitPeers, m_TrustedRouters; mutable std::mutex m_InboundTunnelsMutex; std::set, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first mutable std::mutex m_OutboundTunnelsMutex;