use shared pointer for RI in requested destination

pull/113/head
orignal 10 years ago
parent 8a357ac46c
commit d8b9968aed

@ -21,7 +21,7 @@ namespace i2p
{
namespace data
{
I2NPMessage * RequestedDestination::CreateRequestMessage (const RouterInfo * router,
I2NPMessage * RequestedDestination::CreateRequestMessage (std::shared_ptr<const RouterInfo> router,
const i2p::tunnel::InboundTunnel * replyTunnel)
{
I2NPMessage * msg = i2p::CreateDatabaseLookupMsg (m_Destination,
@ -209,11 +209,11 @@ namespace data
}
}
RouterInfo * NetDb::FindRouter (const IdentHash& ident) const
std::shared_ptr<RouterInfo> NetDb::FindRouter (const IdentHash& ident) const
{
auto it = m_RouterInfos.find (ident);
if (it != m_RouterInfos.end ())
return it->second.get ();
return it->second;
else
return nullptr;
}
@ -611,7 +611,7 @@ namespace data
LogPrint ("Requested RouterInfo ", key, " found");
router->LoadBuffer ();
if (router->GetBuffer ())
replyMsg = CreateDatabaseStoreMsg (router);
replyMsg = CreateDatabaseStoreMsg (router.get ());
}
}
if (!replyMsg)
@ -633,7 +633,7 @@ namespace data
excludedRouters.insert (excluded);
excluded += 32;
}
replyMsg = CreateDatabaseSearchReply (buf, GetClosestFloodfill (buf, excludedRouters));
replyMsg = CreateDatabaseSearchReply (buf, GetClosestFloodfill (buf, excludedRouters).get ());
}
else
excluded += numExcluded*32; // we don't care about exluded
@ -697,9 +697,9 @@ namespace data
rnd.GenerateBlock (randomHash, 32);
RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true, exploratoryPool);
auto floodfill = GetClosestFloodfill (randomHash, dest->GetExcludedPeers ());
if (floodfill && !floodfills.count (floodfill)) // request floodfill only once
if (floodfill && !floodfills.count (floodfill.get ())) // request floodfill only once
{
floodfills.insert (floodfill);
floodfills.insert (floodfill.get ());
if (throughTunnels)
{
msgs.push_back (i2p::tunnel::TunnelMessageBlock
@ -836,10 +836,10 @@ namespace data
if (msg) m_Queue.Put (msg);
}
const RouterInfo * NetDb::GetClosestFloodfill (const IdentHash& destination,
std::shared_ptr<const RouterInfo> NetDb::GetClosestFloodfill (const IdentHash& destination,
const std::set<IdentHash>& excluded) const
{
RouterInfo * r = nullptr;
std::shared_ptr<const RouterInfo> r;
XORMetric minMetric;
IdentHash destKey = CreateRoutingKey (destination);
minMetric.SetMax ();
@ -852,7 +852,7 @@ namespace data
if (m < minMetric)
{
minMetric = m;
r = it.get ();
r = it;
}
}
}

@ -27,19 +27,19 @@ namespace data
RequestedDestination (const IdentHash& destination, bool isLeaseSet,
bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr):
m_Destination (destination), m_IsLeaseSet (isLeaseSet), m_IsExploratory (isExploratory),
m_Pool (pool), m_LastRouter (nullptr), m_CreationTime (0) {};
m_Pool (pool), m_CreationTime (0) {};
const IdentHash& GetDestination () const { return m_Destination; };
int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); };
const std::set<IdentHash>& GetExcludedPeers () { return m_ExcludedPeers; };
void ClearExcludedPeers ();
const RouterInfo * GetLastRouter () const { return m_LastRouter; };
std::shared_ptr<const RouterInfo> GetLastRouter () const { return m_LastRouter; };
i2p::tunnel::TunnelPool * GetTunnelPool () { return m_Pool; };
bool IsExploratory () const { return m_IsExploratory; };
bool IsLeaseSet () const { return m_IsLeaseSet; };
bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); };
uint64_t GetCreationTime () const { return m_CreationTime; };
I2NPMessage * CreateRequestMessage (const RouterInfo * router, const i2p::tunnel::InboundTunnel * replyTunnel);
I2NPMessage * CreateRequestMessage (std::shared_ptr<const RouterInfo>, const i2p::tunnel::InboundTunnel * replyTunnel);
I2NPMessage * CreateRequestMessage (const IdentHash& floodfill);
private:
@ -48,7 +48,7 @@ namespace data
bool m_IsLeaseSet, m_IsExploratory;
i2p::tunnel::TunnelPool * m_Pool;
std::set<IdentHash> m_ExcludedPeers;
const RouterInfo * m_LastRouter;
std::shared_ptr<const RouterInfo> m_LastRouter;
uint64_t m_CreationTime;
};
@ -64,7 +64,7 @@ namespace data
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);
RouterInfo * FindRouter (const IdentHash& ident) const;
std::shared_ptr<RouterInfo> FindRouter (const IdentHash& ident) const;
LeaseSet * FindLeaseSet (const IdentHash& destination) const;
void PublishLeaseSet (const LeaseSet * leaseSet, i2p::tunnel::TunnelPool * pool);
@ -95,7 +95,7 @@ namespace data
void Run (); // exploratory thread
void Explore (int numDestinations);
void Publish ();
const RouterInfo * GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
std::shared_ptr<const RouterInfo> GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
void ManageLeaseSets ();
RequestedDestination * CreateRequestedDestination (const IdentHash& dest,

@ -277,10 +277,10 @@ namespace transport
session->SendI2NPMessage (msg);
else
{
RouterInfo * r = netdb.FindRouter (ident);
auto r = netdb.FindRouter (ident);
if (r)
{
auto ssuSession = m_SSUServer ? m_SSUServer->FindSession (r) : nullptr;
auto ssuSession = m_SSUServer ? m_SSUServer->FindSession (r.get ()) : nullptr;
if (ssuSession)
ssuSession->SendI2NPMessage (msg);
else
@ -297,7 +297,7 @@ namespace transport
else
{
// then SSU
auto s = m_SSUServer ? m_SSUServer->GetSession (r) : nullptr;
auto s = m_SSUServer ? m_SSUServer->GetSession (r.get ()) : nullptr;
if (s)
s->SendI2NPMessage (msg);
else
@ -323,7 +323,7 @@ namespace transport
void Transports::HandleResendTimer (const boost::system::error_code& ecode,
boost::asio::deadline_timer * timer, const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg)
{
RouterInfo * r = netdb.FindRouter (ident);
auto r = netdb.FindRouter (ident);
if (r)
{
LogPrint ("Router found. Sending message");

Loading…
Cancel
Save