Browse Source

use shared_ptr for LeaseSet request

pull/308/head
orignal 9 years ago
parent
commit
de6dd77046
  1. 16
      Destination.cpp
  2. 4
      Destination.h

16
Destination.cpp

@ -94,7 +94,8 @@ namespace client
if (m_IsRunning) if (m_IsRunning)
Stop (); Stop ();
for (auto it: m_LeaseSetRequests) for (auto it: m_LeaseSetRequests)
delete it.second; if (it.second->requestComplete) it.second->requestComplete (nullptr);
m_LeaseSetRequests.clear ();
if (m_Pool) if (m_Pool)
i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool); i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool);
if (m_DatagramDestination) if (m_DatagramDestination)
@ -299,7 +300,6 @@ namespace client
{ {
it1->second->requestTimeoutTimer.cancel (); it1->second->requestTimeoutTimer.cancel ();
if (it1->second->requestComplete) it1->second->requestComplete (leaseSet); if (it1->second->requestComplete) it1->second->requestComplete (leaseSet);
delete it1->second;
m_LeaseSetRequests.erase (it1); m_LeaseSetRequests.erase (it1);
} }
} }
@ -312,7 +312,7 @@ namespace client
auto it = m_LeaseSetRequests.find (key); auto it = m_LeaseSetRequests.find (key);
if (it != m_LeaseSetRequests.end ()) if (it != m_LeaseSetRequests.end ())
{ {
LeaseSetRequest * request = it->second; auto request = it->second;
bool found = false; bool found = false;
if (request->excluded.size () < MAX_NUM_FLOODFILLS_PER_REQUEST) if (request->excluded.size () < MAX_NUM_FLOODFILLS_PER_REQUEST)
{ {
@ -340,7 +340,6 @@ namespace client
if (!found) if (!found)
{ {
if (request->requestComplete) request->requestComplete (nullptr); if (request->requestComplete) request->requestComplete (nullptr);
delete request;
m_LeaseSetRequests.erase (key); m_LeaseSetRequests.erase (key);
} }
} }
@ -540,16 +539,15 @@ namespace client
auto floodfill = i2p::data::netdb.GetClosestFloodfill (dest, excluded); auto floodfill = i2p::data::netdb.GetClosestFloodfill (dest, excluded);
if (floodfill) if (floodfill)
{ {
LeaseSetRequest * request = new LeaseSetRequest (m_Service); auto request = std::make_shared<LeaseSetRequest> (m_Service);
request->requestComplete = requestComplete; request->requestComplete = requestComplete;
auto ret = m_LeaseSetRequests.insert (std::pair<i2p::data::IdentHash, LeaseSetRequest *>(dest,request)); auto ret = m_LeaseSetRequests.insert (std::pair<i2p::data::IdentHash, std::shared_ptr<LeaseSetRequest> >(dest,request));
if (ret.second) // inserted if (ret.second) // inserted
{ {
if (!SendLeaseSetRequest (dest, floodfill, request)) if (!SendLeaseSetRequest (dest, floodfill, request))
{ {
// request failed // request failed
if (request->requestComplete) request->requestComplete (nullptr); if (request->requestComplete) request->requestComplete (nullptr);
delete request;
m_LeaseSetRequests.erase (dest); m_LeaseSetRequests.erase (dest);
} }
} }
@ -558,7 +556,6 @@ namespace client
LogPrint (eLogError, "Request of ", dest.ToBase64 (), " is pending already"); LogPrint (eLogError, "Request of ", dest.ToBase64 (), " is pending already");
// TODO: queue up requests // TODO: queue up requests
if (request->requestComplete) request->requestComplete (nullptr); if (request->requestComplete) request->requestComplete (nullptr);
delete request;
} }
} }
else else
@ -566,7 +563,7 @@ namespace client
} }
bool ClientDestination::SendLeaseSetRequest (const i2p::data::IdentHash& dest, bool ClientDestination::SendLeaseSetRequest (const i2p::data::IdentHash& dest,
std::shared_ptr<const i2p::data::RouterInfo> nextFloodfill, LeaseSetRequest * request) std::shared_ptr<const i2p::data::RouterInfo> nextFloodfill, std::shared_ptr<LeaseSetRequest> request)
{ {
auto replyTunnel = m_Pool->GetNextInboundTunnel (); auto replyTunnel = m_Pool->GetNextInboundTunnel ();
if (!replyTunnel) LogPrint (eLogError, "No inbound tunnels found"); if (!replyTunnel) LogPrint (eLogError, "No inbound tunnels found");
@ -631,7 +628,6 @@ namespace client
if (done) if (done)
{ {
if (it->second->requestComplete) it->second->requestComplete (nullptr); if (it->second->requestComplete) it->second->requestComplete (nullptr);
delete it->second;
m_LeaseSetRequests.erase (it); m_LeaseSetRequests.erase (it);
} }
} }

4
Destination.h

@ -118,7 +118,7 @@ namespace client
void HandleDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg); void HandleDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg);
void RequestLeaseSet (const i2p::data::IdentHash& dest, RequestComplete requestComplete); void RequestLeaseSet (const i2p::data::IdentHash& dest, RequestComplete requestComplete);
bool SendLeaseSetRequest (const i2p::data::IdentHash& dest, std::shared_ptr<const i2p::data::RouterInfo> nextFloodfill, LeaseSetRequest * request); bool SendLeaseSetRequest (const i2p::data::IdentHash& dest, std::shared_ptr<const i2p::data::RouterInfo> nextFloodfill, std::shared_ptr<LeaseSetRequest> request);
void HandleRequestTimoutTimer (const boost::system::error_code& ecode, const i2p::data::IdentHash& dest); void HandleRequestTimoutTimer (const boost::system::error_code& ecode, const i2p::data::IdentHash& dest);
void HandleCleanupTimer (const boost::system::error_code& ecode); void HandleCleanupTimer (const boost::system::error_code& ecode);
void CleanupRemoteLeaseSets (); void CleanupRemoteLeaseSets ();
@ -132,7 +132,7 @@ namespace client
i2p::data::PrivateKeys m_Keys; i2p::data::PrivateKeys m_Keys;
uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256]; uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
std::map<i2p::data::IdentHash, std::shared_ptr<i2p::data::LeaseSet> > m_RemoteLeaseSets; std::map<i2p::data::IdentHash, std::shared_ptr<i2p::data::LeaseSet> > m_RemoteLeaseSets;
std::map<i2p::data::IdentHash, LeaseSetRequest *> m_LeaseSetRequests; std::map<i2p::data::IdentHash, std::shared_ptr<LeaseSetRequest> > m_LeaseSetRequests;
std::shared_ptr<i2p::tunnel::TunnelPool> m_Pool; std::shared_ptr<i2p::tunnel::TunnelPool> m_Pool;
std::shared_ptr<i2p::data::LeaseSet> m_LeaseSet; std::shared_ptr<i2p::data::LeaseSet> m_LeaseSet;

Loading…
Cancel
Save