mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 06:54:15 +00:00
generic GetRandomRputer
This commit is contained in:
parent
ec624c89b2
commit
08ff685de8
22
NetDb.cpp
22
NetDb.cpp
@ -786,6 +786,23 @@ namespace data
|
|||||||
}
|
}
|
||||||
|
|
||||||
const RouterInfo * NetDb::GetRandomRouter (const RouterInfo * compatibleWith) const
|
const RouterInfo * NetDb::GetRandomRouter (const RouterInfo * compatibleWith) const
|
||||||
|
{
|
||||||
|
if (compatibleWith)
|
||||||
|
return GetRandomRouter (
|
||||||
|
[compatibleWith](const RouterInfo * router)->bool
|
||||||
|
{
|
||||||
|
return !router->IsHidden () && router->IsCompatible (*compatibleWith);
|
||||||
|
});
|
||||||
|
else
|
||||||
|
return GetRandomRouter (
|
||||||
|
[](const RouterInfo * router)->bool
|
||||||
|
{
|
||||||
|
return !router->IsHidden ();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Filter>
|
||||||
|
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);
|
||||||
@ -796,8 +813,7 @@ namespace data
|
|||||||
{
|
{
|
||||||
if (i >= ind)
|
if (i >= ind)
|
||||||
{
|
{
|
||||||
if (!it.second->IsUnreachable () && !it.second->IsHidden () &&
|
if (!it.second->IsUnreachable () && filter (it.second))
|
||||||
(!compatibleWith || it.second->IsCompatible (*compatibleWith)))
|
|
||||||
return it.second;
|
return it.second;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -808,7 +824,7 @@ namespace data
|
|||||||
}
|
}
|
||||||
return nullptr; // seems we have too few routers
|
return nullptr; // seems we have too few routers
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDb::PostI2NPMsg (I2NPMessage * msg)
|
void NetDb::PostI2NPMsg (I2NPMessage * msg)
|
||||||
{
|
{
|
||||||
if (msg) m_Queue.Put (msg);
|
if (msg) m_Queue.Put (msg);
|
||||||
|
3
NetDb.h
3
NetDb.h
@ -105,6 +105,9 @@ namespace data
|
|||||||
bool isLeaseSet, bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr);
|
bool isLeaseSet, bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr);
|
||||||
bool DeleteRequestedDestination (const IdentHash& dest); // returns true if found
|
bool DeleteRequestedDestination (const IdentHash& dest); // returns true if found
|
||||||
void DeleteRequestedDestination (RequestedDestination * dest);
|
void DeleteRequestedDestination (RequestedDestination * dest);
|
||||||
|
|
||||||
|
template<typename Filter>
|
||||||
|
const RouterInfo * GetRandomRouter (Filter filter) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user