mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
use shared pointer for RI in requested destination
This commit is contained in:
parent
8a357ac46c
commit
d8b9968aed
20
NetDb.cpp
20
NetDb.cpp
|
@ -21,7 +21,7 @@ namespace i2p
|
||||||
{
|
{
|
||||||
namespace data
|
namespace data
|
||||||
{
|
{
|
||||||
I2NPMessage * RequestedDestination::CreateRequestMessage (const RouterInfo * router,
|
I2NPMessage * RequestedDestination::CreateRequestMessage (std::shared_ptr<const RouterInfo> router,
|
||||||
const i2p::tunnel::InboundTunnel * replyTunnel)
|
const i2p::tunnel::InboundTunnel * replyTunnel)
|
||||||
{
|
{
|
||||||
I2NPMessage * msg = i2p::CreateDatabaseLookupMsg (m_Destination,
|
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);
|
auto it = m_RouterInfos.find (ident);
|
||||||
if (it != m_RouterInfos.end ())
|
if (it != m_RouterInfos.end ())
|
||||||
return it->second.get ();
|
return it->second;
|
||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -611,7 +611,7 @@ namespace data
|
||||||
LogPrint ("Requested RouterInfo ", key, " found");
|
LogPrint ("Requested RouterInfo ", key, " found");
|
||||||
router->LoadBuffer ();
|
router->LoadBuffer ();
|
||||||
if (router->GetBuffer ())
|
if (router->GetBuffer ())
|
||||||
replyMsg = CreateDatabaseStoreMsg (router);
|
replyMsg = CreateDatabaseStoreMsg (router.get ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!replyMsg)
|
if (!replyMsg)
|
||||||
|
@ -633,7 +633,7 @@ namespace data
|
||||||
excludedRouters.insert (excluded);
|
excludedRouters.insert (excluded);
|
||||||
excluded += 32;
|
excluded += 32;
|
||||||
}
|
}
|
||||||
replyMsg = CreateDatabaseSearchReply (buf, GetClosestFloodfill (buf, excludedRouters));
|
replyMsg = CreateDatabaseSearchReply (buf, GetClosestFloodfill (buf, excludedRouters).get ());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
excluded += numExcluded*32; // we don't care about exluded
|
excluded += numExcluded*32; // we don't care about exluded
|
||||||
|
@ -697,9 +697,9 @@ namespace data
|
||||||
rnd.GenerateBlock (randomHash, 32);
|
rnd.GenerateBlock (randomHash, 32);
|
||||||
RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true, exploratoryPool);
|
RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true, exploratoryPool);
|
||||||
auto floodfill = GetClosestFloodfill (randomHash, dest->GetExcludedPeers ());
|
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)
|
if (throughTunnels)
|
||||||
{
|
{
|
||||||
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
||||||
|
@ -836,10 +836,10 @@ namespace data
|
||||||
if (msg) m_Queue.Put (msg);
|
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
|
const std::set<IdentHash>& excluded) const
|
||||||
{
|
{
|
||||||
RouterInfo * r = nullptr;
|
std::shared_ptr<const RouterInfo> r;
|
||||||
XORMetric minMetric;
|
XORMetric minMetric;
|
||||||
IdentHash destKey = CreateRoutingKey (destination);
|
IdentHash destKey = CreateRoutingKey (destination);
|
||||||
minMetric.SetMax ();
|
minMetric.SetMax ();
|
||||||
|
@ -852,7 +852,7 @@ namespace data
|
||||||
if (m < minMetric)
|
if (m < minMetric)
|
||||||
{
|
{
|
||||||
minMetric = m;
|
minMetric = m;
|
||||||
r = it.get ();
|
r = it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
NetDb.h
12
NetDb.h
|
@ -27,19 +27,19 @@ namespace data
|
||||||
RequestedDestination (const IdentHash& destination, bool isLeaseSet,
|
RequestedDestination (const IdentHash& destination, bool isLeaseSet,
|
||||||
bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr):
|
bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr):
|
||||||
m_Destination (destination), m_IsLeaseSet (isLeaseSet), m_IsExploratory (isExploratory),
|
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; };
|
const IdentHash& GetDestination () const { return m_Destination; };
|
||||||
int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); };
|
int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); };
|
||||||
const std::set<IdentHash>& GetExcludedPeers () { return m_ExcludedPeers; };
|
const std::set<IdentHash>& GetExcludedPeers () { return m_ExcludedPeers; };
|
||||||
void ClearExcludedPeers ();
|
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; };
|
i2p::tunnel::TunnelPool * GetTunnelPool () { return m_Pool; };
|
||||||
bool IsExploratory () const { return m_IsExploratory; };
|
bool IsExploratory () const { return m_IsExploratory; };
|
||||||
bool IsLeaseSet () const { return m_IsLeaseSet; };
|
bool IsLeaseSet () const { return m_IsLeaseSet; };
|
||||||
bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); };
|
bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); };
|
||||||
uint64_t GetCreationTime () const { return m_CreationTime; };
|
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);
|
I2NPMessage * CreateRequestMessage (const IdentHash& floodfill);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -48,7 +48,7 @@ namespace data
|
||||||
bool m_IsLeaseSet, m_IsExploratory;
|
bool m_IsLeaseSet, m_IsExploratory;
|
||||||
i2p::tunnel::TunnelPool * m_Pool;
|
i2p::tunnel::TunnelPool * m_Pool;
|
||||||
std::set<IdentHash> m_ExcludedPeers;
|
std::set<IdentHash> m_ExcludedPeers;
|
||||||
const RouterInfo * m_LastRouter;
|
std::shared_ptr<const RouterInfo> m_LastRouter;
|
||||||
uint64_t m_CreationTime;
|
uint64_t m_CreationTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ namespace data
|
||||||
|
|
||||||
void AddRouterInfo (const IdentHash& ident, 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, 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;
|
LeaseSet * FindLeaseSet (const IdentHash& destination) const;
|
||||||
|
|
||||||
void PublishLeaseSet (const LeaseSet * leaseSet, i2p::tunnel::TunnelPool * pool);
|
void PublishLeaseSet (const LeaseSet * leaseSet, i2p::tunnel::TunnelPool * pool);
|
||||||
|
@ -95,7 +95,7 @@ namespace data
|
||||||
void Run (); // exploratory thread
|
void Run (); // exploratory thread
|
||||||
void Explore (int numDestinations);
|
void Explore (int numDestinations);
|
||||||
void Publish ();
|
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 ();
|
void ManageLeaseSets ();
|
||||||
|
|
||||||
RequestedDestination * CreateRequestedDestination (const IdentHash& dest,
|
RequestedDestination * CreateRequestedDestination (const IdentHash& dest,
|
||||||
|
|
|
@ -277,10 +277,10 @@ namespace transport
|
||||||
session->SendI2NPMessage (msg);
|
session->SendI2NPMessage (msg);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RouterInfo * r = netdb.FindRouter (ident);
|
auto r = netdb.FindRouter (ident);
|
||||||
if (r)
|
if (r)
|
||||||
{
|
{
|
||||||
auto ssuSession = m_SSUServer ? m_SSUServer->FindSession (r) : nullptr;
|
auto ssuSession = m_SSUServer ? m_SSUServer->FindSession (r.get ()) : nullptr;
|
||||||
if (ssuSession)
|
if (ssuSession)
|
||||||
ssuSession->SendI2NPMessage (msg);
|
ssuSession->SendI2NPMessage (msg);
|
||||||
else
|
else
|
||||||
|
@ -297,7 +297,7 @@ namespace transport
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// then SSU
|
// then SSU
|
||||||
auto s = m_SSUServer ? m_SSUServer->GetSession (r) : nullptr;
|
auto s = m_SSUServer ? m_SSUServer->GetSession (r.get ()) : nullptr;
|
||||||
if (s)
|
if (s)
|
||||||
s->SendI2NPMessage (msg);
|
s->SendI2NPMessage (msg);
|
||||||
else
|
else
|
||||||
|
@ -323,7 +323,7 @@ namespace transport
|
||||||
void Transports::HandleResendTimer (const boost::system::error_code& ecode,
|
void Transports::HandleResendTimer (const boost::system::error_code& ecode,
|
||||||
boost::asio::deadline_timer * timer, const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg)
|
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)
|
if (r)
|
||||||
{
|
{
|
||||||
LogPrint ("Router found. Sending message");
|
LogPrint ("Router found. Sending message");
|
||||||
|
|
Loading…
Reference in a new issue