Skip to content

Commit

Permalink
add additional case (#1180)
Browse files Browse the repository at this point in the history
* add additional case for if we are near the end and all elements are in the exlcude set

* fix stop condition in second loop
  • Loading branch information
majestrate authored Mar 11, 2020
1 parent c19c83a commit 3f4b2a5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion llarp/nodedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,16 @@ llarp_nodedb::select_random_hop_excluding(
}

const size_t pos = llarp::randint() % sz;
for(auto itr = std::next(entries.begin(), pos); itr != entries.end(); ++itr)
const auto start = std::next(entries.begin(), pos);
for(auto itr = start; itr != entries.end(); ++itr)
{
if(exclude.count(itr->first) == 0 and itr->second.rc.IsPublicRouter())
{
result = itr->second.rc;
return true;
}
}
for(auto itr = entries.begin(); itr != start; ++itr)
{
if(exclude.count(itr->first) == 0 and itr->second.rc.IsPublicRouter())
{
Expand Down

0 comments on commit 3f4b2a5

Please sign in to comment.