From 21b5f2c96ab80631c85f9f2e1097ad9f90bc3bd8 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 8 Jun 2016 14:14:19 -0400 Subject: [PATCH] fixed crash upon I2CP session disconnect --- I2CP.cpp | 15 ++++++++------- I2CP.h | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/I2CP.cpp b/I2CP.cpp index 5447a622..e0ab180a 100644 --- a/I2CP.cpp +++ b/I2CP.cpp @@ -23,7 +23,7 @@ namespace i2p namespace client { - I2CPDestination::I2CPDestination (I2CPSession& owner, std::shared_ptr identity, bool isPublic, const std::map& params): + I2CPDestination::I2CPDestination (std::shared_ptr owner, std::shared_ptr identity, bool isPublic, const std::map& params): LeaseSetDestination (isPublic, ¶ms), m_Owner (owner), m_Identity (identity) { } @@ -37,7 +37,7 @@ namespace client { uint32_t length = bufbe32toh (buf); if (length > len - 4) length = len - 4; - m_Owner.SendMessagePayloadMessage (buf + 4, length); + m_Owner->SendMessagePayloadMessage (buf + 4, length); } void I2CPDestination::CreateNewLeaseSet (std::vector > tunnels) @@ -46,9 +46,9 @@ namespace client m_LeaseSetExpirationTime = ls.GetExpirationTime (); uint8_t * leases = ls.GetLeases (); leases[-1] = tunnels.size (); - htobe16buf (leases - 3, m_Owner.GetSessionID ()); + htobe16buf (leases - 3, m_Owner->GetSessionID ()); size_t l = 2/*sessionID*/ + 1/*num leases*/ + i2p::data::LEASE_SIZE*tunnels.size (); - m_Owner.SendI2CPMessage (I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE, leases - 3, l); + m_Owner->SendI2CPMessage (I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE, leases - 3, l); } void I2CPDestination::LeaseSetCreated (const uint8_t * buf, size_t len) @@ -78,10 +78,10 @@ namespace client if (ls) { bool sent = s->SendMsg (msg, ls); - s->m_Owner.SendMessageStatusMessage (nonce, sent ? eI2CPMessageStatusGuaranteedSuccess : eI2CPMessageStatusGuaranteedFailure); + s->m_Owner->SendMessageStatusMessage (nonce, sent ? eI2CPMessageStatusGuaranteedSuccess : eI2CPMessageStatusGuaranteedFailure); } else - s->m_Owner.SendMessageStatusMessage (nonce, eI2CPMessageStatusNoLeaseSet); + s->m_Owner->SendMessageStatusMessage (nonce, eI2CPMessageStatusNoLeaseSet); }); } } @@ -134,6 +134,7 @@ namespace client void I2CPSession::Stop () { + Terminate (); } void I2CPSession::ReadProtocolByte () @@ -327,7 +328,7 @@ namespace client { bool isPublic = true; if (params[I2CP_PARAM_DONT_PUBLISH_LEASESET] == "true") isPublic = false; - m_Destination = std::make_shared(*this, identity, isPublic, params); + m_Destination = std::make_shared(shared_from_this (), identity, isPublic, params); m_Destination->Start (); SendSessionStatusMessage (1); // created LogPrint (eLogDebug, "I2CP: session ", m_SessionID, " created"); diff --git a/I2CP.h b/I2CP.h index 436b1ad6..62a9a729 100644 --- a/I2CP.h +++ b/I2CP.h @@ -63,7 +63,7 @@ namespace client { public: - I2CPDestination (I2CPSession& owner, std::shared_ptr identity, bool isPublic, const std::map& params); + I2CPDestination (std::shared_ptr owner, std::shared_ptr identity, bool isPublic, const std::map& params); void SetEncryptionPrivateKey (const uint8_t * key); void LeaseSetCreated (const uint8_t * buf, size_t len); // called from I2CPSession @@ -87,7 +87,7 @@ namespace client private: - I2CPSession& m_Owner; + std::shared_ptr m_Owner; std::shared_ptr m_Identity; uint8_t m_EncryptionPrivateKey[256]; uint64_t m_LeaseSetExpirationTime;