From b9e3931e80ab7c1ab42b528b92e159ff76189cb6 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 5 Feb 2015 18:53:43 -0500 Subject: [PATCH] use shared_ptr for inbound tunnels --- Destination.cpp | 2 +- Destination.h | 2 +- Garlic.cpp | 4 ++-- Garlic.h | 6 +++--- I2NPProtocol.cpp | 2 +- I2NPProtocol.h | 7 ++++--- NetDb.cpp | 2 +- NetDb.h | 2 +- RouterContext.cpp | 2 +- RouterContext.h | 2 +- Tunnel.cpp | 2 +- Tunnel.h | 2 +- 12 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index bc15bb78..0995352b 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -192,7 +192,7 @@ namespace client m_Service.post (std::bind (&ClientDestination::HandleDeliveryStatusMessage, this, msg)); } - void ClientDestination::HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from) + void ClientDestination::HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from) { uint8_t typeID = buf[I2NP_HEADER_TYPEID_OFFSET]; switch (typeID) diff --git a/Destination.h b/Destination.h index db7a3089..45c29bb0 100644 --- a/Destination.h +++ b/Destination.h @@ -86,7 +86,7 @@ namespace client // implements GarlicDestination const i2p::data::LeaseSet * GetLeaseSet (); - void HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from); + void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from); // override GarlicDestination bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag); diff --git a/Garlic.cpp b/Garlic.cpp index 1bd3a8da..53281fa2 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -400,7 +400,7 @@ namespace garlic } void GarlicDestination::HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr decryption, - i2p::tunnel::InboundTunnel * from) + std::shared_ptr from) { uint16_t tagCount = bufbe16toh (buf); buf += 2; len -= 2; @@ -439,7 +439,7 @@ namespace garlic HandleGarlicPayload (buf, payloadSize, from); } - void GarlicDestination::HandleGarlicPayload (uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from) + void GarlicDestination::HandleGarlicPayload (uint8_t * buf, size_t len, std::shared_ptr from) { int numCloves = buf[0]; LogPrint (numCloves," cloves"); diff --git a/Garlic.h b/Garlic.h index 69c6e237..43214e75 100644 --- a/Garlic.h +++ b/Garlic.h @@ -121,7 +121,7 @@ namespace garlic virtual void SetLeaseSetUpdated (); virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO - virtual void HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from) = 0; + virtual void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from) = 0; protected: @@ -131,8 +131,8 @@ namespace garlic private: void HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr decryption, - i2p::tunnel::InboundTunnel * from); - void HandleGarlicPayload (uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from); + std::shared_ptr from); + void HandleGarlicPayload (uint8_t * buf, size_t len, std::shared_ptr from); private: diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 0fb85566..7216e864 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -71,7 +71,7 @@ namespace i2p return msg; } - I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from) + I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len, std::shared_ptr from) { I2NPMessage * msg = NewI2NPMessage (); memcpy (msg->GetBuffer (), buf, len); diff --git a/I2NPProtocol.h b/I2NPProtocol.h index 86aacd76..de91df73 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -2,9 +2,10 @@ #define I2NP_PROTOCOL_H__ #include +#include #include +#include #include -#include #include "I2PEndian.h" #include "Identity.h" #include "RouterInfo.h" @@ -108,7 +109,7 @@ namespace tunnel { uint8_t * buf; size_t len, offset, maxLen; - i2p::tunnel::InboundTunnel * from; + std::shared_ptr from; I2NPMessage (): buf (nullptr),len (I2NP_HEADER_SIZE + 2), offset(2), maxLen (0), from (nullptr) {}; // reserve 2 bytes for NTCP header @@ -195,7 +196,7 @@ namespace tunnel void FillI2NPMessageHeader (I2NPMessage * msg, I2NPMessageType msgType, uint32_t replyMsgID = 0); void RenewI2NPMessageHeader (I2NPMessage * msg); I2NPMessage * CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, int len, uint32_t replyMsgID = 0); - I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from = nullptr); + I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len, std::shared_ptr from = nullptr); I2NPMessage * CreateDeliveryStatusMsg (uint32_t msgID); I2NPMessage * CreateRouterInfoDatabaseLookupMsg (const uint8_t * key, const uint8_t * from, diff --git a/NetDb.cpp b/NetDb.cpp index a35d50c6..0b68708d 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -239,7 +239,7 @@ namespace data } void NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, - i2p::tunnel::InboundTunnel * from) + std::shared_ptr from) { if (!from) // unsolicited LS must be received directly { diff --git a/NetDb.h b/NetDb.h index f7efbd2c..346ece28 100644 --- a/NetDb.h +++ b/NetDb.h @@ -67,7 +67,7 @@ namespace data void AddRouterInfo (const uint8_t * buf, int len); void AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len); - void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from); + void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, std::shared_ptr from); std::shared_ptr FindRouter (const IdentHash& ident) const; std::shared_ptr FindLeaseSet (const IdentHash& destination) const; diff --git a/RouterContext.cpp b/RouterContext.cpp index 2d42d3da..36cb06bf 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -215,7 +215,7 @@ namespace i2p fk.write ((char *)&keys, sizeof (keys)); } - void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from) + void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from) { i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from)); } diff --git a/RouterContext.h b/RouterContext.h index 10512d67..e483646c 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -54,7 +54,7 @@ namespace i2p // implements GarlicDestination const i2p::data::LeaseSet * GetLeaseSet () { return nullptr; }; - void HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from); + void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from); private: diff --git a/Tunnel.cpp b/Tunnel.cpp index 229a43b8..6ce8348a 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -160,7 +160,7 @@ namespace tunnel void InboundTunnel::HandleTunnelDataMsg (I2NPMessage * msg) { if (IsFailed ()) SetState (eTunnelStateEstablished); // incoming messages means a tunnel is alive - msg->from = this; + msg->from = shared_from_this (); EncryptTunnelMsg (msg); m_Endpoint.HandleDecryptedTunnelDataMsg (msg); } diff --git a/Tunnel.h b/Tunnel.h index 0db74277..83334b42 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -95,7 +95,7 @@ namespace tunnel TunnelGateway m_Gateway; }; - class InboundTunnel: public Tunnel + class InboundTunnel: public Tunnel, public std::enable_shared_from_this { public: