|
|
|
@ -525,51 +525,6 @@ llarp_nodedb::select_random_exit(llarp::RouterContact &result)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
llarp_nodedb::select_random_hop(const llarp::RouterContact &prev,
|
|
|
|
|
llarp::RouterContact &result, size_t N)
|
|
|
|
|
{
|
|
|
|
|
llarp::util::Lock lock(access);
|
|
|
|
|
/// checking for "guard" status for N = 0 is done by caller inside of
|
|
|
|
|
/// pathbuilder's scope
|
|
|
|
|
size_t sz = entries.size();
|
|
|
|
|
if(sz < 3)
|
|
|
|
|
return false;
|
|
|
|
|
if(!N)
|
|
|
|
|
return false;
|
|
|
|
|
llarp_time_t now = llarp::time_now_ms();
|
|
|
|
|
|
|
|
|
|
auto itr = entries.begin();
|
|
|
|
|
size_t pos = llarp::randint() % sz;
|
|
|
|
|
std::advance(itr, pos);
|
|
|
|
|
auto start = itr;
|
|
|
|
|
while(itr == entries.end())
|
|
|
|
|
{
|
|
|
|
|
if(prev.pubkey != itr->second.rc.pubkey)
|
|
|
|
|
{
|
|
|
|
|
if(itr->second.rc.addrs.size() && !itr->second.rc.IsExpired(now))
|
|
|
|
|
{
|
|
|
|
|
result = itr->second.rc;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
itr++;
|
|
|
|
|
}
|
|
|
|
|
itr = entries.begin();
|
|
|
|
|
while(itr != start)
|
|
|
|
|
{
|
|
|
|
|
if(prev.pubkey != itr->second.rc.pubkey)
|
|
|
|
|
{
|
|
|
|
|
if(itr->second.rc.addrs.size() && !itr->second.rc.IsExpired(now))
|
|
|
|
|
{
|
|
|
|
|
result = itr->second.rc;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
++itr;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
llarp_nodedb::select_random_hop_excluding(
|
|
|
|
@ -583,17 +538,16 @@ llarp_nodedb::select_random_hop_excluding(
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
llarp_time_t now = llarp::time_now_ms();
|
|
|
|
|
|
|
|
|
|
auto itr = entries.begin();
|
|
|
|
|
size_t pos = llarp::randint() % sz;
|
|
|
|
|
auto itr = entries.begin();
|
|
|
|
|
const size_t pos = llarp::randint() % sz;
|
|
|
|
|
std::advance(itr, pos);
|
|
|
|
|
auto start = itr;
|
|
|
|
|
const auto start = itr;
|
|
|
|
|
while(itr == entries.end())
|
|
|
|
|
{
|
|
|
|
|
if(exclude.count(itr->first) == 0)
|
|
|
|
|
{
|
|
|
|
|
if(itr->second.rc.addrs.size() && !itr->second.rc.IsExpired(now))
|
|
|
|
|
if(itr->second.rc.IsPublicRouter())
|
|
|
|
|
{
|
|
|
|
|
result = itr->second.rc;
|
|
|
|
|
return true;
|
|
|
|
@ -606,7 +560,7 @@ llarp_nodedb::select_random_hop_excluding(
|
|
|
|
|
{
|
|
|
|
|
if(exclude.count(itr->first) == 0)
|
|
|
|
|
{
|
|
|
|
|
if(itr->second.rc.addrs.size() && !itr->second.rc.IsExpired(now))
|
|
|
|
|
if(itr->second.rc.IsPublicRouter())
|
|
|
|
|
{
|
|
|
|
|
result = itr->second.rc;
|
|
|
|
|
return true;
|
|
|
|
|