Skip to content

Commit

Permalink
code dedup
Browse files Browse the repository at this point in the history
  • Loading branch information
majestrate committed Mar 11, 2020
1 parent 6047d57 commit 69126c6
Showing 1 changed file with 2 additions and 39 deletions.
41 changes: 2 additions & 39 deletions llarp/nodedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,45 +529,8 @@ 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;

auto itr = entries.begin();
const size_t pos = llarp::randint() % sz;
std::advance(itr, pos);
const auto start = itr;
while(itr == entries.end())
{
if(prev.pubkey != itr->second.rc.pubkey)
{
if(itr->second.rc.IsPublicRouter())
{
result = itr->second.rc;
return true;
}
}
itr++;
}
itr = entries.begin();
while(itr != start)
{
if(prev.pubkey != itr->second.rc.pubkey)
{
if(itr->second.rc.IsPublicRouter())
{
result = itr->second.rc;
return true;
}
}
++itr;
}
return false;
(void)N;
return select_random_hop_excluding(result, {prev.pubkey});
}

bool
Expand Down

0 comments on commit 69126c6

Please sign in to comment.