llarp::service::Endpoint::ReadyToDoLookup()

previously we had a checking style function that passes in an optional
defaulting to nullopt as a micro optimzation, this makes the code
unnessarily obtuse.

simplify this by splitting up into 2 functions,
one for getting the unique endpoints and one for checking if the
number of them is above the minimum.

add overload for ReadyToDoLookup() that checks against constant but
can do more in the future if desired to reduce the burden on future contributors.
pull/2048/head
Jeff Becker 2 years ago
parent 9dfb4a389c
commit e5efe793ca
No known key found for this signature in database
GPG Key ID: 025C02EE3A092F2D

@ -40,16 +40,10 @@
#include <uvw.hpp>
#include <variant>
namespace
{
constexpr size_t MIN_ENDPOINTS_FOR_LNS_LOOKUP = 2;
} // namespace
namespace llarp
{
namespace service
{
static auto logcat = log::Cat("endpoint");
Endpoint::Endpoint(AbstractRouter* r, Context* parent)
@ -317,7 +311,7 @@ namespace llarp
auto obj = path::Builder::ExtractStatus();
obj["exitMap"] = m_ExitMap.ExtractStatus();
obj["identity"] = m_Identity.pub.Addr().ToString();
obj["networkReady"] = ReadyToDoLookup();
obj["networkReady"] = ReadyForNetwork();
util::StatusObject authCodes;
for (const auto& [service, info] : m_RemoteAuthInfos)
@ -958,20 +952,28 @@ namespace llarp
return not m_ExitMap.Empty();
}
path::Path::UniqueEndpointSet_t
Endpoint::GetUniqueEndpointsForLookup() const
{
path::Path::UniqueEndpointSet_t paths;
ForEachPath([&paths](auto path) {
if (path and path->IsReady())
paths.insert(path);
});
return paths;
}
bool
Endpoint::ReadyToDoLookup(std::optional<uint64_t> numPaths) const
Endpoint::ReadyForNetwork() const
{
if (not numPaths)
{
path::Path::UniqueEndpointSet_t paths;
ForEachPath([&paths](auto path) {
if (path and path->IsReady())
paths.insert(path);
});
numPaths = paths.size();
}
return IsReady() and ReadyToDoLookup(GetUniqueEndpointsForLookup().size());
}
return numPaths >= MIN_ENDPOINTS_FOR_LNS_LOOKUP;
bool
Endpoint::ReadyToDoLookup(size_t num_paths) const
{
// Currently just checks the number of paths, but could do more checks in the future. (jason)
return num_paths >= MIN_ENDPOINTS_FOR_LNS_LOOKUP;
}
void
@ -992,12 +994,7 @@ namespace llarp
return;
}
LogInfo(Name(), " looking up LNS name: ", name);
path::Path::UniqueEndpointSet_t paths;
ForEachPath([&paths](auto path) {
if (path and path->IsReady())
paths.insert(path);
});
auto paths = GetUniqueEndpointsForLookup();
// not enough paths
if (not ReadyToDoLookup(paths.size()))
{

@ -48,13 +48,16 @@ namespace llarp
struct OutboundContext;
/// minimum interval for publishing introsets
static constexpr auto IntrosetPublishInterval = path::intro_path_spread / 2;
inline constexpr auto IntrosetPublishInterval = path::intro_path_spread / 2;
/// how agressively should we retry publishing introset on failure
static constexpr auto IntrosetPublishRetryCooldown = 1s;
inline constexpr auto IntrosetPublishRetryCooldown = 1s;
/// how aggressively should we retry looking up introsets
static constexpr auto IntrosetLookupCooldown = 250ms;
inline constexpr auto IntrosetLookupCooldown = 250ms;
/// number of unique snodes we want to talk to do to ons lookups
inline constexpr size_t MIN_ENDPOINTS_FOR_LNS_LOOKUP = 2;
struct Endpoint : public path::Builder,
public ILookupHolder,
@ -64,7 +67,9 @@ namespace llarp
Endpoint(AbstractRouter* r, Context* parent);
~Endpoint() override;
/// return true if we are ready to recv packets from the void
/// return true if we are ready to recv packets from the void.
/// really should be ReadyForInboundTraffic() but the diff is HUGE and we need to rewrite this
/// component anyways.
bool
IsReady() const;
@ -521,10 +526,16 @@ namespace llarp
return false;
}
/// return true if we are ready to do outbound and inbound traffic
bool
ReadyToDoLookup(std::optional<uint64_t> numPaths = std::nullopt) const;
ReadyForNetwork() const;
protected:
bool
ReadyToDoLookup(size_t num_paths) const;
path::Path::UniqueEndpointSet_t
GetUniqueEndpointsForLookup() const;
IDataHandler* m_DataHandler = nullptr;
Identity m_Identity;
net::IPRangeMap<service::Address> m_ExitMap;

Loading…
Cancel
Save