return shared_ptr to RI

This commit is contained in:
orignal 2014-11-20 16:20:02 -05:00
parent 683c97d5c8
commit 0f4e4a7944
5 changed files with 21 additions and 21 deletions

View File

@ -778,37 +778,37 @@ namespace data
}
}
const RouterInfo * NetDb::GetRandomRouter () const
std::shared_ptr<const RouterInfo> NetDb::GetRandomRouter () const
{
return GetRandomRouter (
[](const RouterInfo * router)->bool
[](std::shared_ptr<const RouterInfo> router)->bool
{
return !router->IsHidden ();
});
}
const RouterInfo * NetDb::GetRandomRouter (const RouterInfo * compatibleWith) const
std::shared_ptr<const RouterInfo> NetDb::GetRandomRouter (const RouterInfo * compatibleWith) const
{
return GetRandomRouter (
[compatibleWith](const RouterInfo * router)->bool
[compatibleWith](std::shared_ptr<const RouterInfo> router)->bool
{
return !router->IsHidden () && router != compatibleWith &&
return !router->IsHidden () && router.get () != compatibleWith &&
router->IsCompatible (*compatibleWith);
});
}
const RouterInfo * NetDb::GetHighBandwidthRandomRouter (const RouterInfo * compatibleWith) const
std::shared_ptr<const RouterInfo> NetDb::GetHighBandwidthRandomRouter (const RouterInfo * compatibleWith) const
{
return GetRandomRouter (
[compatibleWith](const RouterInfo * router)->bool
[compatibleWith](std::shared_ptr<const RouterInfo> router)->bool
{
return !router->IsHidden () && router != compatibleWith &&
return !router->IsHidden () && router.get () != compatibleWith &&
router->IsCompatible (*compatibleWith) && (router->GetCaps () & RouterInfo::eHighBandwidth);
});
}
template<typename Filter>
const RouterInfo * NetDb::GetRandomRouter (Filter filter) const
std::shared_ptr<const RouterInfo> NetDb::GetRandomRouter (Filter filter) const
{
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
uint32_t ind = rnd.GenerateWord32 (0, m_RouterInfos.size () - 1);
@ -819,8 +819,8 @@ namespace data
{
if (i >= ind)
{
if (!it.second->IsUnreachable () && filter (it.second.get ()))
return it.second.get ();
if (!it.second->IsUnreachable () && filter (it.second))
return it.second;
}
else
i++;

View File

@ -75,9 +75,9 @@ namespace data
void HandleDatabaseSearchReplyMsg (I2NPMessage * msg);
void HandleDatabaseLookupMsg (I2NPMessage * msg);
const RouterInfo * GetRandomRouter () const;
const RouterInfo * GetRandomRouter (const RouterInfo * compatibleWith) const;
const RouterInfo * GetHighBandwidthRandomRouter (const RouterInfo * compatibleWith) const;
std::shared_ptr<const RouterInfo> GetRandomRouter () const;
std::shared_ptr<const RouterInfo> GetRandomRouter (const RouterInfo * compatibleWith) const;
std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (const RouterInfo * compatibleWith) const;
void SetUnreachable (const IdentHash& ident, bool unreachable);
void PostI2NPMsg (I2NPMessage * msg);
@ -104,7 +104,7 @@ namespace data
void DeleteRequestedDestination (RequestedDestination * dest);
template<typename Filter>
const RouterInfo * GetRandomRouter (Filter filter) const;
std::shared_ptr<const RouterInfo> GetRandomRouter (Filter filter) const;
private:

View File

@ -360,7 +360,7 @@ namespace transport
{
auto router = i2p::data::netdb.GetRandomRouter ();
if (router && router->IsSSU () && m_SSUServer)
m_SSUServer->GetSession (router, true); // peer test
m_SSUServer->GetSession (router.get (), true); // peer test
}
}

View File

@ -468,7 +468,7 @@ namespace tunnel
CreateTunnel<OutboundTunnel> (
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
{
i2p::data::netdb.GetRandomRouter ()
i2p::data::netdb.GetRandomRouter ().get ()
},
inboundTunnel->GetTunnelConfig ()));
}
@ -521,7 +521,7 @@ namespace tunnel
CreateTunnel<InboundTunnel> (
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
{
i2p::data::netdb.GetRandomRouter ()
i2p::data::netdb.GetRandomRouter ().get ()
}));
}
}

View File

@ -237,10 +237,10 @@ namespace tunnel
const i2p::data::RouterInfo * TunnelPool::SelectNextHop (const i2p::data::RouterInfo * prevHop) const
{
auto hop = m_NumHops >= 3 ? i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop) :
i2p::data::netdb.GetRandomRouter (prevHop);
auto hop = m_NumHops >= 3 ? i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop).get () :
i2p::data::netdb.GetRandomRouter (prevHop).get ();
if (!hop)
hop = i2p::data::netdb.GetRandomRouter ();
hop = i2p::data::netdb.GetRandomRouter ().get ();
return hop;
}