path and intro selection fixups:

* include stricter router profiling checks in path::Builder hop slection algorithm
* make intro selection function nicer by returning a std::optional instead of a bool with an "out" variable
pull/1658/head
Jeff Becker 3 years ago
parent 174e1b247b
commit 503db46eca
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -240,6 +240,9 @@ namespace llarp
if (BuildCooldownHit(rc.pubkey))
return;
if (m_router->routerProfiling().IsBadForPath(rc.pubkey))
return;
found = rc;
}
},
@ -251,7 +254,7 @@ namespace llarp
Builder::GetHopsForBuild()
{
auto filter = [r = m_router](const auto& rc) -> bool {
return not r->routerProfiling().IsBadForPath(rc.pubkey);
return not r->routerProfiling().IsBadForPath(rc.pubkey, 1);
};
if (const auto maybe = m_router->nodedb()->GetRandom(filter))
{
@ -368,7 +371,7 @@ namespace llarp
hopsSet.insert(endpointRC);
hopsSet.insert(hops.begin(), hops.end());
if (r->routerProfiling().IsBadForPath(rc.pubkey))
if (r->routerProfiling().IsBadForPath(rc.pubkey, 1))
return false;
for (const auto& hop : hopsSet)
{

@ -96,9 +96,10 @@ namespace llarp
}
Path_ptr
PathSet::GetEstablishedPathClosestTo(RouterID id, PathRole roles) const
PathSet::GetEstablishedPathClosestTo(
RouterID id, std::unordered_set<RouterID> excluding, PathRole roles) const
{
Lock_t l(m_PathsMutex);
Lock_t l{m_PathsMutex};
Path_ptr path = nullptr;
AlignedBuffer<32> dist;
AlignedBuffer<32> to = id;
@ -109,6 +110,8 @@ namespace llarp
continue;
if (!item.second->SupportsAnyRoles(roles))
continue;
if (excluding.count(item.second->Endpoint()))
continue;
AlignedBuffer<32> localDist = item.second->Endpoint() ^ to;
if (localDist < dist)
{
@ -280,44 +283,24 @@ namespace llarp
return itr->second;
}
bool
std::optional<std::set<service::Introduction>>
PathSet::GetCurrentIntroductionsWithFilter(
std::set<service::Introduction>& intros,
std::function<bool(const service::Introduction&)> filter) const
{
intros.clear();
size_t count = 0;
Lock_t l(m_PathsMutex);
std::set<service::Introduction> intros;
Lock_t l{m_PathsMutex};
auto itr = m_Paths.begin();
while (itr != m_Paths.end())
{
if (itr->second->IsReady() && filter(itr->second->intro))
if (itr->second->IsReady() and filter(itr->second->intro))
{
intros.insert(itr->second->intro);
++count;
}
++itr;
}
return count > 0;
}
bool
PathSet::GetCurrentIntroductions(std::set<service::Introduction>& intros) const
{
intros.clear();
size_t count = 0;
Lock_t l(m_PathsMutex);
auto itr = m_Paths.begin();
while (itr != m_Paths.end())
{
if (itr->second->IsReady())
{
intros.insert(itr->second->intro);
++count;
}
++itr;
}
return count > 0;
if (intros.empty())
return std::nullopt;
return intros;
}
void

@ -13,6 +13,7 @@
#include <list>
#include <map>
#include <tuple>
#include <unordered_set>
namespace std
{
@ -235,7 +236,10 @@ namespace llarp
}
Path_ptr
GetEstablishedPathClosestTo(RouterID router, PathRole roles = ePathRoleAny) const;
GetEstablishedPathClosestTo(
RouterID router,
std::unordered_set<RouterID> excluding = {},
PathRole roles = ePathRoleAny) const;
Path_ptr
PickEstablishedPath(PathRole roles = ePathRoleAny) const;
@ -258,14 +262,10 @@ namespace llarp
Path_ptr
GetByEndpointWithID(RouterID router, PathID_t id) const;
bool
std::optional<std::set<service::Introduction>>
GetCurrentIntroductionsWithFilter(
std::set<service::Introduction>& intros,
std::function<bool(const service::Introduction&)> filter) const;
bool
GetCurrentIntroductions(std::set<service::Introduction>& intros) const;
virtual bool
PublishIntroSet(const service::EncryptedIntroSet&, AbstractRouter*)
{

Loading…
Cancel
Save