From 8c47bf9dd3435bb171c7e91c4b55a1b6d45f6f56 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 7 Apr 2015 15:02:00 -0400 Subject: [PATCH] use shared_ptr for local LeaseSet --- Destination.cpp | 14 +++----------- Destination.h | 4 ++-- Garlic.h | 2 +- I2NPProtocol.cpp | 2 +- I2NPProtocol.h | 2 +- NetDb.cpp | 2 +- RouterContext.h | 2 +- 7 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index 15fb8a5b..7cd97d45 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -16,7 +16,7 @@ namespace client ClientDestination::ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic, const std::map * params): m_IsRunning (false), m_Thread (nullptr), m_Work (m_Service), - m_Keys (keys), m_LeaseSet (nullptr), m_IsPublic (isPublic), m_PublishReplyToken (0), + m_Keys (keys), m_IsPublic (isPublic), m_PublishReplyToken (0), m_DatagramDestination (nullptr), m_PublishConfirmationTimer (m_Service), m_CleanupTimer (m_Service) { i2p::crypto::GenerateElGamalKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); @@ -148,7 +148,7 @@ namespace client return nullptr; } - const i2p::data::LeaseSet * ClientDestination::GetLeaseSet () + std::shared_ptr ClientDestination::GetLeaseSet () { if (!m_Pool) return nullptr; if (!m_LeaseSet) @@ -158,15 +158,7 @@ namespace client void ClientDestination::UpdateLeaseSet () { - auto newLeaseSet = new i2p::data::LeaseSet (*m_Pool); - if (!m_LeaseSet) - m_LeaseSet = newLeaseSet; - else - { - // TODO: implement it better - *m_LeaseSet = *newLeaseSet; - delete newLeaseSet; - } + m_LeaseSet.reset (new i2p::data::LeaseSet (*m_Pool)); } bool ClientDestination::SubmitSessionKey (const uint8_t * key, const uint8_t * tag) diff --git a/Destination.h b/Destination.h index 2c51cc30..b5fcd520 100644 --- a/Destination.h +++ b/Destination.h @@ -88,7 +88,7 @@ namespace client const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; }; // implements GarlicDestination - const i2p::data::LeaseSet * GetLeaseSet (); + std::shared_ptr GetLeaseSet (); std::shared_ptr GetTunnelPool () const { return m_Pool; } void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from); @@ -129,7 +129,7 @@ namespace client std::map m_LeaseSetRequests; std::shared_ptr m_Pool; - i2p::data::LeaseSet * m_LeaseSet; + std::shared_ptr m_LeaseSet; bool m_IsPublic; uint32_t m_PublishReplyToken; std::set m_ExcludedFloodfills; // for publishing diff --git a/Garlic.h b/Garlic.h index 6f96d4e7..489e532b 100644 --- a/Garlic.h +++ b/Garlic.h @@ -137,7 +137,7 @@ namespace garlic virtual void ProcessDeliveryStatusMessage (I2NPMessage * msg); virtual void SetLeaseSetUpdated (); - virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO + virtual std::shared_ptr GetLeaseSet () = 0; // TODO virtual std::shared_ptr GetTunnelPool () const = 0; virtual void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from) = 0; diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 42c66f9a..369ad160 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -240,7 +240,7 @@ namespace i2p return m; } - I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet, uint32_t replyToken) + I2NPMessage * CreateDatabaseStoreMsg (std::shared_ptr leaseSet, uint32_t replyToken) { if (!leaseSet) return nullptr; I2NPMessage * m = NewI2NPShortMessage (); diff --git a/I2NPProtocol.h b/I2NPProtocol.h index 19597d52..7d4ee4e5 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -210,7 +210,7 @@ namespace tunnel I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, std::vector routers); I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr, uint32_t replyToken = 0); - I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet, uint32_t replyToken = 0); + I2NPMessage * CreateDatabaseStoreMsg (std::shared_ptr leaseSet, uint32_t replyToken = 0); bool HandleBuildRequestRecords (int num, uint8_t * records, uint8_t * clearText); void HandleVariableTunnelBuildMsg (uint32_t replyMsgID, uint8_t * buf, size_t len); diff --git a/NetDb.cpp b/NetDb.cpp index c8237865..9a0f1a0f 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -749,7 +749,7 @@ namespace data if (leaseSet) // we don't send back our LeaseSets { LogPrint ("Requested LeaseSet ", key, " found"); - replyMsg = CreateDatabaseStoreMsg (leaseSet.get ()); + replyMsg = CreateDatabaseStoreMsg (leaseSet); } } if (!replyMsg) diff --git a/RouterContext.h b/RouterContext.h index 81ef4867..9f6cd00b 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -72,7 +72,7 @@ namespace i2p void SetLeaseSetUpdated () {}; // implements GarlicDestination - const i2p::data::LeaseSet * GetLeaseSet () { return nullptr; }; + std::shared_ptr GetLeaseSet () { return nullptr; }; std::shared_ptr GetTunnelPool () const; void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from);