From 4c7d52ac20cb09dabb25c9cd32a8ec71e0879738 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 27 Oct 2020 16:27:14 -0400 Subject: [PATCH] more aggressive path building. (#1423) * more aggressive path building. * do more than one in parallel path builds at a time * correct last commit's logic * rename numPaths -> numDesiredPaths to clarify intent * revert string change as it will break a lot * don't prematurly short circuit on snode builds Co-authored-by: Thomas Winget --- llarp/exit/session.cpp | 10 +++++----- llarp/path/pathbuilder.cpp | 2 +- llarp/path/pathbuilder.hpp | 2 +- llarp/path/pathset.cpp | 6 +++--- llarp/path/pathset.hpp | 6 +++--- llarp/service/endpoint.cpp | 11 +++-------- llarp/service/outbound_context.cpp | 6 ++---- 7 files changed, 18 insertions(+), 25 deletions(-) diff --git a/llarp/exit/session.cpp b/llarp/exit/session.cpp index 6d1e7ae1b..3a075698e 100644 --- a/llarp/exit/session.cpp +++ b/llarp/exit/session.cpp @@ -58,7 +58,7 @@ namespace llarp { if (BuildCooldownHit(now)) return false; - const size_t expect = (1 + (numPaths / 2)); + const size_t expect = (1 + (numDesiredPaths / 2)); // check 30 seconds into the future and see if we need more paths const llarp_time_t future = now + 30s + buildIntervalLimit; return NumPathsExistingAt(future) < expect; @@ -250,7 +250,7 @@ namespace llarp bool BaseSession::IsReady() const { - const size_t expect = (1 + (numPaths / 2)); + const size_t expect = (1 + (numDesiredPaths / 2)); return AvailablePaths(llarp::path::ePathRoleExit) >= expect; } @@ -265,9 +265,9 @@ namespace llarp { if (BuildCooldownHit(now)) return false; - if (!IsReady()) - return NumInStatus(path::ePathBuilding) < numPaths; - return path::Builder::UrgentBuild(now); + if (IsReady() and NumInStatus(path::ePathBuilding) < numDesiredPaths) + return path::Builder::UrgentBuild(now); + return false; } bool diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 7a5e8deb8..07bfddf76 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -191,7 +191,7 @@ namespace llarp { util::StatusObject obj{{"buildStats", m_BuildStats.ExtractStatus()}, {"numHops", uint64_t(numHops)}, - {"numPaths", uint64_t(numPaths)}}; + {"numPaths", uint64_t(numDesiredPaths)}}; std::transform( m_Paths.begin(), m_Paths.end(), diff --git a/llarp/path/pathbuilder.hpp b/llarp/path/pathbuilder.hpp index 7deb4ee61..af8b16068 100644 --- a/llarp/path/pathbuilder.hpp +++ b/llarp/path/pathbuilder.hpp @@ -44,7 +44,7 @@ namespace llarp llarp_time_t buildIntervalLimit = MIN_PATH_BUILD_INTERVAL; /// construct - Builder(AbstractRouter* p_router, size_t numPaths, size_t numHops); + Builder(AbstractRouter* p_router, size_t numDesiredPaths, size_t numHops); virtual ~Builder() = default; diff --git a/llarp/path/pathset.cpp b/llarp/path/pathset.cpp index 3a21e5c90..b13845825 100644 --- a/llarp/path/pathset.cpp +++ b/llarp/path/pathset.cpp @@ -11,7 +11,7 @@ namespace llarp { namespace path { - PathSet::PathSet(size_t num) : numPaths(num) + PathSet::PathSet(size_t num) : numDesiredPaths(num) {} bool @@ -19,10 +19,10 @@ namespace llarp { (void)now; const auto building = NumInStatus(ePathBuilding); - if (building >= numPaths) + if (building >= numDesiredPaths) return false; const auto established = NumInStatus(ePathEstablished); - return established < numPaths; + return established < numDesiredPaths; } bool diff --git a/llarp/path/pathset.hpp b/llarp/path/pathset.hpp index 5612d598d..0d62f3e9f 100644 --- a/llarp/path/pathset.hpp +++ b/llarp/path/pathset.hpp @@ -97,8 +97,8 @@ namespace llarp /// maximum number of paths a path set can maintain static constexpr size_t max_paths = 32; /// construct - /// @params numPaths the number of paths to maintain - PathSet(size_t numPaths); + /// @params numDesiredPaths the number of paths to maintain + PathSet(size_t numDesiredPaths); /// get a shared_ptr of ourself virtual PathSet_ptr @@ -296,7 +296,7 @@ namespace llarp void DownstreamFlush(AbstractRouter* r); - size_t numPaths; + size_t numDesiredPaths; protected: BuildStats m_BuildStats; diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 5ae57934e..5e7d19583 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -52,7 +52,7 @@ namespace llarp Endpoint::Configure(const NetworkConfig& conf, [[maybe_unused]] const DnsConfig& dnsConf) { if (conf.m_Paths.has_value()) - numPaths = *conf.m_Paths; + numDesiredPaths = *conf.m_Paths; if (conf.m_Hops.has_value()) numHops = *conf.m_Hops; @@ -1231,7 +1231,7 @@ namespace llarp return HandleInboundPacket(tag, pkt.ConstBuffer(), eProtocolTrafficV4, 0); }, Router(), - numPaths, + numDesiredPaths, numHops, false, ShouldBundleRC()); @@ -1466,13 +1466,8 @@ namespace llarp bool Endpoint::ShouldBuildMore(llarp_time_t now) const { - if (path::Builder::BuildCooldownHit(now)) + if (not path::Builder::ShouldBuildMore(now)) return false; - - size_t numBuilding = NumInStatus(path::ePathBuilding); - if (numBuilding > 0) - return false; - return ((now - lastBuild) > path::intro_path_spread) || NumInStatus(path::ePathEstablished) < path::min_intro_paths; } diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index 925c32f47..fcb5f232f 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -359,11 +359,9 @@ namespace llarp bool OutboundContext::ShouldBuildMore(llarp_time_t now) const { - if (markedBad || path::Builder::BuildCooldownHit(now)) + if (markedBad || not path::Builder::ShouldBuildMore(now)) return false; - const bool canBuild = - NumInStatus(path::ePathBuilding) == 0 and path::Builder::ShouldBuildMore(now); - if (not canBuild) + if (NumInStatus(path::ePathBuilding) >= numDesiredPaths) return false; llarp_time_t t = 0s; ForEachPath([&t](path::Path_ptr path) {