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

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

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

Loading…
Cancel
Save