Merge pull request #2048 from majestrate/simplify-ons-ready-logic-2022-11-03

simplify llarp::service::Endpoint::ReadyToDoLookup()
pull/2047/head
majestrate 2 years ago committed by GitHub
commit 7325878afd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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.
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