From 7ad86b2ba0f594645b6cf33c7299210f7f72415d Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 7 Jun 2026 15:01:58 -0400 Subject: [PATCH] shared_ptr for DatagramDestination --- libi2pd/Destination.cpp | 8 +++----- libi2pd/Destination.h | 6 +++--- libi2pd_client/UDPTunnel.h | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index dd112ba3..8f515f3e 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -979,8 +979,7 @@ namespace client m_StreamingMaxWindowSize (i2p::stream::MAX_WINDOW_SIZE), m_StreamingMaxResends (i2p::stream::MAX_NUM_RESEND_ATTEMPTS), m_IsStreamingAnswerPings (DEFAULT_ANSWER_PINGS), m_IsStreamingDontSign (DEFAULT_DONT_SIGN), - m_LastPort (0), m_DatagramDestination (nullptr), m_RefCounter (0), - m_LastPublishedTimestamp (0), m_ReadyChecker(service) + m_LastPort (0), m_RefCounter (0), m_LastPublishedTimestamp (0), m_ReadyChecker(service) { if (keys.IsOfflineSignature () && GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_LEASESET) SetLeaseSetType (i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2); // offline keys can be published with LS2 only @@ -1129,7 +1128,6 @@ namespace client if (m_DatagramDestination) { LogPrint(eLogDebug, "Destination: -> Stopping Datagram Destination"); - delete m_DatagramDestination; m_DatagramDestination = nullptr; } LeaseSetDestination::Stop (); @@ -1382,14 +1380,14 @@ namespace client return nullptr; } - i2p::datagram::DatagramDestination * ClientDestination::CreateDatagramDestination (bool gzip, + std::shared_ptr ClientDestination::CreateDatagramDestination (bool gzip, i2p::datagram::DatagramVersion version) { if (!m_DatagramDestination) { if (!GetNumRatchetInboundTags ()) SetNumRatchetInboundTags (i2p::garlic::ECIESX25519_MAX_NUM_GENERATED_TAGS); // set max tags if not specified - m_DatagramDestination = new i2p::datagram::DatagramDestination (GetSharedFromThis (), gzip, version); + m_DatagramDestination = std::make_shared (GetSharedFromThis (), gzip, version); } return m_DatagramDestination; } diff --git a/libi2pd/Destination.h b/libi2pd/Destination.h index ec28b91f..e4f2968d 100644 --- a/libi2pd/Destination.h +++ b/libi2pd/Destination.h @@ -285,8 +285,8 @@ namespace client int GetStreamingMaxResends () const { return m_StreamingMaxResends; } // datagram - i2p::datagram::DatagramDestination * GetDatagramDestination () const { return m_DatagramDestination; }; - i2p::datagram::DatagramDestination * CreateDatagramDestination (bool gzip = true, + std::shared_ptr GetDatagramDestination () const { return m_DatagramDestination; }; + std::shared_ptr CreateDatagramDestination (bool gzip = true, i2p::datagram::DatagramVersion version = i2p::datagram::eDatagramV1); // implements LocalDestination @@ -330,7 +330,7 @@ namespace client std::shared_ptr m_StreamingDestination; // default std::map > m_StreamingDestinationsByPorts; std::shared_ptr m_LastStreamingDestination; uint16_t m_LastPort; // for server tunnels - i2p::datagram::DatagramDestination * m_DatagramDestination; + std::shared_ptr m_DatagramDestination; int m_RefCounter; // how many clients(tunnels) use this destination uint64_t m_LastPublishedTimestamp; diff --git a/libi2pd_client/UDPTunnel.h b/libi2pd_client/UDPTunnel.h index 673793a1..b32cdd76 100644 --- a/libi2pd_client/UDPTunnel.h +++ b/libi2pd_client/UDPTunnel.h @@ -38,7 +38,7 @@ namespace client struct UDPConnection { - i2p::datagram::DatagramDestination * m_Destination; + std::shared_ptr m_Destination; std::weak_ptr m_LastDatagramSession; uint64_t m_LastRepliableDatagramTime; // milliseconds i2p::data::IdentHash Identity; @@ -52,7 +52,7 @@ namespace client bool m_IsSendingAllowed = true; bool m_IsFirstPacket = true; - UDPConnection (boost::asio::io_context& service, i2p::datagram::DatagramDestination * destination): + UDPConnection (boost::asio::io_context& service, std::shared_ptr destination): m_Destination (destination), m_LastRepliableDatagramTime (0), m_AckTimer (service) {}; void SetIdentity (const i2p::data::IdentHash& ident) { Identity = ident; isIdentity = true; };