fix dumb as shit path building that causes premature termiantion because of duplicate hops

pull/391/head
Jeff Becker 5 years ago
parent 232a7ff010
commit 5d3833ef1a
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -67,6 +67,11 @@ namespace llarp
{
return db->Get(m_ExitRouter, cur);
}
else if(hop == numHops - 2)
{
return db->select_random_hop_excluding(cur,
{prev.pubkey, m_ExitRouter});
}
else
return path::Builder::SelectHop(db, prev, cur, hop, roles);
}

@ -228,6 +228,8 @@ namespace llarp
bool
Session::IsTimedOut(llarp_time_t now) const
{
if(state == eConnecting)
return false;
if(state == eClose)
return true;
if(now <= lastActive)

@ -468,3 +468,47 @@ llarp_nodedb::select_random_hop(const llarp::RouterContact &prev,
}
return false;
}
bool
llarp_nodedb::select_random_hop_excluding(
llarp::RouterContact &result, const std::set< llarp::RouterID > &exclude)
{
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;
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(exclude.count(itr->first) == 0)
{
if(itr->second.addrs.size() && !itr->second.IsExpired(now))
{
result = itr->second;
return true;
}
}
itr++;
}
itr = entries.begin();
while(itr != start)
{
if(exclude.count(itr->first) == 0)
{
if(itr->second.addrs.size() && !itr->second.IsExpired(now))
{
result = itr->second;
return true;
}
}
++itr;
}
return false;
}

@ -9,6 +9,8 @@
#include <absl/base/thread_annotations.h>
#include <set>
/**
* nodedb.hpp
*
@ -113,6 +115,11 @@ struct llarp_nodedb
llarp::RouterContact &result, size_t N)
LOCKS_EXCLUDED(access);
bool
select_random_hop_excluding(llarp::RouterContact &result,
const std::set< llarp::RouterID > &exclude)
LOCKS_EXCLUDED(access);
static bool
ensure_dir(const char *dir);
};

@ -450,6 +450,15 @@ namespace llarp
return hops[0].rc.pubkey;
}
std::string
Path::HopsString() const
{
std::stringstream ss;
for(const auto& hop : hops)
ss << RouterID(hop.rc.pubkey) << " -> ";
return ss.str();
}
void
Path::EnterState(PathStatus st, llarp_time_t now)
{

@ -362,6 +362,9 @@ namespace llarp
return _status;
}
std::string
HopsString() const;
llarp_time_t
LastRemoteActivityAt() const override
{

@ -213,11 +213,15 @@ namespace llarp
size_t tries = 10;
do
{
cur.Clear();
--tries;
if(db->select_random_hop(prev, cur, hop))
return true;
} while(router->routerProfiling().IsBad(cur.pubkey) && tries > 0);
return false;
{
if(!router->routerProfiling().IsBad(cur.pubkey))
return true;
}
} while(tries > 0);
return tries > 0;
}
bool

@ -292,7 +292,7 @@ namespace llarp
void
PathSet::HandlePathBuildTimeout(Path* p)
{
LogInfo("path build for ", p->Name(), " has timed out");
LogInfo("path build ", p->HopsString(), " timed out");
}
bool

@ -70,7 +70,7 @@ namespace llarp
bool
RouterProfile::IsGood(uint64_t chances) const
{
if(connectTimeoutCount > 3)
if(connectTimeoutCount > chances)
return connectTimeoutCount <= connectGoodCount
&& (pathSuccessCount * chances) >= pathFailCount;
else

@ -131,6 +131,12 @@ namespace llarp
&& netID == other.netID;
}
bool
operator<(const RouterContact &other) const
{
return pubkey < other.pubkey;
}
bool
operator!=(const RouterContact &other) const
{

@ -1854,6 +1854,11 @@ namespace llarp
return false;
}
}
else if(hop == numHops - 2)
{
return db->select_random_hop_excluding(
cur, {prev.pubkey, m_NextIntro.router});
}
(void)roles;
return path::Builder::SelectHop(db, prev, cur, hop, roles);
}

Loading…
Cancel
Save