Browse Source

return shared_ptr to RI

pull/113/head
orignal 10 years ago
parent
commit
0f4e4a7944
  1. 22
      NetDb.cpp
  2. 8
      NetDb.h
  3. 2
      Transports.cpp
  4. 4
      Tunnel.cpp
  5. 6
      TunnelPool.cpp

22
NetDb.cpp

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

8
NetDb.h

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

2
Transports.cpp

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

4
Tunnel.cpp

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

6
TunnelPool.cpp

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

Loading…
Cancel
Save