diff --git a/Datagram.cpp b/Datagram.cpp index 410b9740..2378659a 100644 --- a/Datagram.cpp +++ b/Datagram.cpp @@ -17,7 +17,7 @@ namespace datagram { } - void DatagramDestination::SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::LeaseSet& remote) + void DatagramDestination::SendDatagramTo (const uint8_t * payload, size_t len, std::shared_ptr remote) { uint8_t buf[MAX_DATAGRAM_SIZE]; auto identityLen = m_Owner.GetIdentity ().ToBuffer (buf, MAX_DATAGRAM_SIZE); @@ -40,10 +40,10 @@ namespace datagram CreateDataMessage (buf, len + headerLen), remote)); } - void DatagramDestination::SendMsg (I2NPMessage * msg, const i2p::data::LeaseSet& remote) + void DatagramDestination::SendMsg (I2NPMessage * msg, std::shared_ptr remote) { auto outboundTunnel = m_Owner.GetTunnelPool ()->GetNextOutboundTunnel (); - auto leases = remote.GetNonExpiredLeases (); + auto leases = remote->GetNonExpiredLeases (); if (!leases.empty () && outboundTunnel) { std::vector msgs; diff --git a/Datagram.h b/Datagram.h index b3eaa9e5..279f5d96 100644 --- a/Datagram.h +++ b/Datagram.h @@ -2,6 +2,7 @@ #define DATAGRAM_H__ #include +#include #include #include "Identity.h" #include "LeaseSet.h" @@ -25,7 +26,7 @@ namespace datagram DatagramDestination (i2p::client::ClientDestination& owner); ~DatagramDestination () {}; - void SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::LeaseSet& remote); + void SendDatagramTo (const uint8_t * payload, size_t len, std::shared_ptr remote); void HandleDataMessagePayload (const uint8_t * buf, size_t len); void SetReceiver (const Receiver& receiver) { m_Receiver = receiver; }; @@ -34,7 +35,7 @@ namespace datagram private: I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len); - void SendMsg (I2NPMessage * msg, const i2p::data::LeaseSet& remote); + void SendMsg (I2NPMessage * msg, std::shared_ptr remote); void HandleDatagram (const uint8_t * buf, size_t len); private: diff --git a/Destination.cpp b/Destination.cpp index b122172e..6414a6b3 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -341,7 +341,7 @@ namespace client m_ExcludedFloodfills.insert (floodfill->GetIdentHash ()); LogPrint (eLogDebug, "Publish LeaseSet of ", GetIdentHash ().ToBase32 ()); m_PublishReplyToken = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (); - auto msg = WrapMessage (*floodfill, i2p::CreateDatabaseStoreMsg (m_LeaseSet, m_PublishReplyToken)); + auto msg = WrapMessage (floodfill, i2p::CreateDatabaseStoreMsg (m_LeaseSet, m_PublishReplyToken)); m_PublishConfirmationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_CONFIRMATION_TIMEOUT)); m_PublishConfirmationTimer.async_wait (std::bind (&ClientDestination::HandlePublishConfirmationTimer, this, std::placeholders::_1)); @@ -508,7 +508,7 @@ namespace client rnd.GenerateBlock (replyTag, 32); // random session tag AddSessionKey (replyKey, replyTag); - I2NPMessage * msg = WrapMessage (*nextFloodfill, + I2NPMessage * msg = WrapMessage (nextFloodfill, CreateLeaseSetDatabaseLookupMsg (dest, request->excluded, replyTunnel.get (), replyKey, replyTag)); outboundTunnel->SendTunnelDataMsg ( diff --git a/Garlic.cpp b/Garlic.cpp index 6b2dc700..1bd3a8da 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -15,7 +15,7 @@ namespace i2p namespace garlic { GarlicRoutingSession::GarlicRoutingSession (GarlicDestination * owner, - const i2p::data::RoutingDestination * destination, int numTags): + std::shared_ptr destination, int numTags): m_Owner (owner), m_Destination (destination), m_NumTags (numTags), m_LeaseSetUpdated (numTags > 0) { @@ -501,7 +501,7 @@ namespace garlic } } - I2NPMessage * GarlicDestination::WrapMessage (const i2p::data::RoutingDestination& destination, + I2NPMessage * GarlicDestination::WrapMessage (std::shared_ptr destination, I2NPMessage * msg, bool attachLeaseSet) { if (attachLeaseSet) // we should maintain this session @@ -511,23 +511,23 @@ namespace garlic } else // one time session { - GarlicRoutingSession session (this, &destination, 0); // don't use tag if no LeaseSet + GarlicRoutingSession session (this, destination, 0); // don't use tag if no LeaseSet return session.WrapSingleMessage (msg); } } std::shared_ptr GarlicDestination::GetRoutingSession ( - const i2p::data::RoutingDestination& destination, int numTags) + std::shared_ptr destination, int numTags) { - auto it = m_Sessions.find (destination.GetIdentHash ()); + auto it = m_Sessions.find (destination->GetIdentHash ()); std::shared_ptr session; if (it != m_Sessions.end ()) session = it->second; if (!session) { - session = std::make_shared (this, &destination, numTags); + session = std::make_shared (this, destination, numTags); std::unique_lock l(m_SessionsMutex); - m_Sessions[destination.GetIdentHash ()] = session; + m_Sessions[destination->GetIdentHash ()] = session; } return session; } diff --git a/Garlic.h b/Garlic.h index 523e57ef..69c6e237 100644 --- a/Garlic.h +++ b/Garlic.h @@ -67,7 +67,7 @@ namespace garlic public: - GarlicRoutingSession (GarlicDestination * owner, const i2p::data::RoutingDestination * destination, int numTags); + GarlicRoutingSession (GarlicDestination * owner, std::shared_ptr destination, int numTags); GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag); // one time encryption ~GarlicRoutingSession (); I2NPMessage * WrapSingleMessage (I2NPMessage * msg); @@ -88,7 +88,7 @@ namespace garlic private: GarlicDestination * m_Owner; - const i2p::data::RoutingDestination * m_Destination; + std::shared_ptr m_Destination; i2p::crypto::AESKey m_SessionKey; std::list m_SessionTags; int m_NumTags; @@ -106,10 +106,10 @@ namespace garlic GarlicDestination (): m_LastTagsCleanupTime (0) {}; ~GarlicDestination (); - std::shared_ptr GetRoutingSession (const i2p::data::RoutingDestination& destination, int numTags); + std::shared_ptr GetRoutingSession (std::shared_ptr destination, int numTags); void CleanupRoutingSessions (); void RemoveCreatedSession (uint32_t msgID); - I2NPMessage * WrapMessage (const i2p::data::RoutingDestination& destination, + I2NPMessage * WrapMessage (std::shared_ptr destination, I2NPMessage * msg, bool attachLeaseSet = false); void AddSessionKey (const uint8_t * key, const uint8_t * tag); // one tag diff --git a/SAM.cpp b/SAM.cpp index b85fc4ee..10169808 100644 --- a/SAM.cpp +++ b/SAM.cpp @@ -776,7 +776,7 @@ namespace client auto leaseSet = i2p::data::netdb.FindLeaseSet (dest.GetIdentHash ()); if (leaseSet) session->localDestination->GetDatagramDestination ()-> - SendDatagramTo ((uint8_t *)eol, payloadLen, *leaseSet); + SendDatagramTo ((uint8_t *)eol, payloadLen, leaseSet); else { LogPrint ("SAM datagram destination not found"); diff --git a/Streaming.cpp b/Streaming.cpp index 6e89fa64..0b20c0e3 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -593,7 +593,7 @@ namespace stream if (m_RemoteLeaseSet) { if (!m_RoutingSession) - m_RoutingSession = m_LocalDestination.GetOwner ().GetRoutingSession (*m_RemoteLeaseSet, 32); + m_RoutingSession = m_LocalDestination.GetOwner ().GetRoutingSession (m_RemoteLeaseSet, 32); auto leases = m_RemoteLeaseSet->GetNonExpiredLeases (); if (!leases.empty ()) {