Browse Source

shared_ptr for GarlicRouting Session

pull/151/head
orignal 10 years ago
parent
commit
b269bda52b
  1. 15
      Garlic.cpp
  2. 10
      Garlic.h
  3. 4
      Streaming.cpp
  4. 2
      Streaming.h

15
Garlic.cpp

@ -197,7 +197,7 @@ namespace garlic @@ -197,7 +197,7 @@ namespace garlic
{
(*numCloves)++;
m_UnconfirmedTagsMsgs[msgID] = newTags;
m_Owner->DeliveryStatusSent (this, msgID);
m_Owner->DeliveryStatusSent (shared_from_this (), msgID);
}
else
LogPrint ("DeliveryStatus clove was not created");
@ -306,9 +306,6 @@ namespace garlic @@ -306,9 +306,6 @@ namespace garlic
GarlicDestination::~GarlicDestination ()
{
for (auto it: m_Sessions)
delete it.second;
m_Sessions.clear ();
}
void GarlicDestination::AddSessionKey (const uint8_t * key, const uint8_t * tag)
@ -503,23 +500,23 @@ namespace garlic @@ -503,23 +500,23 @@ namespace garlic
}
}
GarlicRoutingSession * GarlicDestination::GetRoutingSession (
std::shared_ptr<GarlicRoutingSession> GarlicDestination::GetRoutingSession (
const i2p::data::RoutingDestination& destination, int numTags)
{
auto it = m_Sessions.find (destination.GetIdentHash ());
GarlicRoutingSession * session = nullptr;
std::shared_ptr<GarlicRoutingSession> session;
if (it != m_Sessions.end ())
session = it->second;
if (!session)
{
session = new GarlicRoutingSession (this, &destination, numTags);
session = std::make_shared<GarlicRoutingSession> (this, &destination, numTags);
std::unique_lock<std::mutex> l(m_SessionsMutex);
m_Sessions[destination.GetIdentHash ()] = session;
}
return session;
}
void GarlicDestination::DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID)
void GarlicDestination::DeliveryStatusSent (std::shared_ptr<GarlicRoutingSession> session, uint32_t msgID)
{
m_CreatedSessions[msgID] = session;
}
@ -533,7 +530,7 @@ namespace garlic @@ -533,7 +530,7 @@ namespace garlic
{
it->second->TagsConfirmed (msgID);
m_CreatedSessions.erase (it);
LogPrint ("Garlic message ", msgID, " acknowledged");
LogPrint (eLogInfo, "Garlic message ", msgID, " acknowledged");
}
}
DeleteI2NPMessage (msg);

10
Garlic.h

@ -54,7 +54,7 @@ namespace garlic @@ -54,7 +54,7 @@ namespace garlic
};
class GarlicDestination;
class GarlicRoutingSession
class GarlicRoutingSession: public std::enable_shared_from_this<GarlicRoutingSession>
{
struct UnconfirmedTags
{
@ -105,13 +105,13 @@ namespace garlic @@ -105,13 +105,13 @@ namespace garlic
GarlicDestination (): m_LastTagsCleanupTime (0) {};
~GarlicDestination ();
GarlicRoutingSession * GetRoutingSession (const i2p::data::RoutingDestination& destination, int numTags);
std::shared_ptr<GarlicRoutingSession> GetRoutingSession (const i2p::data::RoutingDestination& destination, int numTags);
I2NPMessage * WrapMessage (const i2p::data::RoutingDestination& destination,
I2NPMessage * msg, bool attachLeaseSet = false);
void AddSessionKey (const uint8_t * key, const uint8_t * tag); // one tag
virtual bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag); // from different thread
void DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID);
void DeliveryStatusSent (std::shared_ptr<GarlicRoutingSession> session, uint32_t msgID);
virtual void ProcessGarlicMessage (I2NPMessage * msg);
virtual void ProcessDeliveryStatusMessage (I2NPMessage * msg);
@ -135,12 +135,12 @@ namespace garlic @@ -135,12 +135,12 @@ namespace garlic
// outgoing sessions
std::mutex m_SessionsMutex;
std::map<i2p::data::IdentHash, GarlicRoutingSession *> m_Sessions;
std::map<i2p::data::IdentHash, std::shared_ptr<GarlicRoutingSession> > m_Sessions;
// incoming
std::map<SessionTag, std::shared_ptr<i2p::crypto::CBCDecryption>> m_Tags;
uint32_t m_LastTagsCleanupTime;
// DeliveryStatus
std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session
std::map<uint32_t, std::shared_ptr<GarlicRoutingSession> > m_CreatedSessions; // msgID -> session
};
}
}

4
Streaming.cpp

@ -15,7 +15,7 @@ namespace stream @@ -15,7 +15,7 @@ namespace stream
const i2p::data::LeaseSet& remote, int port): m_Service (service), m_SendStreamID (0),
m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1), m_IsOpen (false),
m_IsReset (false), m_IsAckSendScheduled (false), m_LocalDestination (local),
m_RemoteLeaseSet (&remote), m_RoutingSession (nullptr), m_CurrentOutboundTunnel (nullptr),
m_RemoteLeaseSet (&remote), m_CurrentOutboundTunnel (nullptr),
m_ReceiveTimer (m_Service), m_ResendTimer (m_Service), m_AckSendTimer (m_Service),
m_NumSentBytes (0), m_NumReceivedBytes (0), m_Port (port)
{
@ -26,7 +26,7 @@ namespace stream @@ -26,7 +26,7 @@ namespace stream
Stream::Stream (boost::asio::io_service& service, StreamingDestination& local):
m_Service (service), m_SendStreamID (0), m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1),
m_IsOpen (false), m_IsReset (false), m_IsAckSendScheduled (false), m_LocalDestination (local),
m_RemoteLeaseSet (nullptr), m_RoutingSession (nullptr), m_CurrentOutboundTunnel (nullptr),
m_RemoteLeaseSet (nullptr), m_CurrentOutboundTunnel (nullptr),
m_ReceiveTimer (m_Service), m_ResendTimer (m_Service), m_AckSendTimer (m_Service),
m_NumSentBytes (0), m_NumReceivedBytes (0), m_Port (0)
{

2
Streaming.h

@ -142,7 +142,7 @@ namespace stream @@ -142,7 +142,7 @@ namespace stream
StreamingDestination& m_LocalDestination;
i2p::data::IdentityEx m_RemoteIdentity;
const i2p::data::LeaseSet * m_RemoteLeaseSet;
i2p::garlic::GarlicRoutingSession * m_RoutingSession;
std::shared_ptr<i2p::garlic::GarlicRoutingSession> m_RoutingSession;
i2p::data::Lease m_CurrentRemoteLease;
i2p::tunnel::OutboundTunnel * m_CurrentOutboundTunnel;
std::queue<Packet *> m_ReceiveQueue;

Loading…
Cancel
Save