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 <tewinget@gmail.com>
pull/1433/head
Jeff 4 years ago committed by GitHub
parent e731eab4b6
commit 4c7d52ac20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -58,7 +58,7 @@ namespace llarp
{ {
if (BuildCooldownHit(now)) if (BuildCooldownHit(now))
return false; 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 // check 30 seconds into the future and see if we need more paths
const llarp_time_t future = now + 30s + buildIntervalLimit; const llarp_time_t future = now + 30s + buildIntervalLimit;
return NumPathsExistingAt(future) < expect; return NumPathsExistingAt(future) < expect;
@ -250,7 +250,7 @@ namespace llarp
bool bool
BaseSession::IsReady() const BaseSession::IsReady() const
{ {
const size_t expect = (1 + (numPaths / 2)); const size_t expect = (1 + (numDesiredPaths / 2));
return AvailablePaths(llarp::path::ePathRoleExit) >= expect; return AvailablePaths(llarp::path::ePathRoleExit) >= expect;
} }
@ -265,9 +265,9 @@ namespace llarp
{ {
if (BuildCooldownHit(now)) if (BuildCooldownHit(now))
return false; return false;
if (!IsReady()) if (IsReady() and NumInStatus(path::ePathBuilding) < numDesiredPaths)
return NumInStatus(path::ePathBuilding) < numPaths; return path::Builder::UrgentBuild(now);
return path::Builder::UrgentBuild(now); return false;
} }
bool bool

@ -191,7 +191,7 @@ namespace llarp
{ {
util::StatusObject obj{{"buildStats", m_BuildStats.ExtractStatus()}, util::StatusObject obj{{"buildStats", m_BuildStats.ExtractStatus()},
{"numHops", uint64_t(numHops)}, {"numHops", uint64_t(numHops)},
{"numPaths", uint64_t(numPaths)}}; {"numPaths", uint64_t(numDesiredPaths)}};
std::transform( std::transform(
m_Paths.begin(), m_Paths.begin(),
m_Paths.end(), m_Paths.end(),

@ -44,7 +44,7 @@ namespace llarp
llarp_time_t buildIntervalLimit = MIN_PATH_BUILD_INTERVAL; llarp_time_t buildIntervalLimit = MIN_PATH_BUILD_INTERVAL;
/// construct /// construct
Builder(AbstractRouter* p_router, size_t numPaths, size_t numHops); Builder(AbstractRouter* p_router, size_t numDesiredPaths, size_t numHops);
virtual ~Builder() = default; virtual ~Builder() = default;

@ -11,7 +11,7 @@ namespace llarp
{ {
namespace path namespace path
{ {
PathSet::PathSet(size_t num) : numPaths(num) PathSet::PathSet(size_t num) : numDesiredPaths(num)
{} {}
bool bool
@ -19,10 +19,10 @@ namespace llarp
{ {
(void)now; (void)now;
const auto building = NumInStatus(ePathBuilding); const auto building = NumInStatus(ePathBuilding);
if (building >= numPaths) if (building >= numDesiredPaths)
return false; return false;
const auto established = NumInStatus(ePathEstablished); const auto established = NumInStatus(ePathEstablished);
return established < numPaths; return established < numDesiredPaths;
} }
bool bool

@ -97,8 +97,8 @@ namespace llarp
/// maximum number of paths a path set can maintain /// maximum number of paths a path set can maintain
static constexpr size_t max_paths = 32; static constexpr size_t max_paths = 32;
/// construct /// construct
/// @params numPaths the number of paths to maintain /// @params numDesiredPaths the number of paths to maintain
PathSet(size_t numPaths); PathSet(size_t numDesiredPaths);
/// get a shared_ptr of ourself /// get a shared_ptr of ourself
virtual PathSet_ptr virtual PathSet_ptr
@ -296,7 +296,7 @@ namespace llarp
void void
DownstreamFlush(AbstractRouter* r); DownstreamFlush(AbstractRouter* r);
size_t numPaths; size_t numDesiredPaths;
protected: protected:
BuildStats m_BuildStats; BuildStats m_BuildStats;

@ -52,7 +52,7 @@ namespace llarp
Endpoint::Configure(const NetworkConfig& conf, [[maybe_unused]] const DnsConfig& dnsConf) Endpoint::Configure(const NetworkConfig& conf, [[maybe_unused]] const DnsConfig& dnsConf)
{ {
if (conf.m_Paths.has_value()) if (conf.m_Paths.has_value())
numPaths = *conf.m_Paths; numDesiredPaths = *conf.m_Paths;
if (conf.m_Hops.has_value()) if (conf.m_Hops.has_value())
numHops = *conf.m_Hops; numHops = *conf.m_Hops;
@ -1231,7 +1231,7 @@ namespace llarp
return HandleInboundPacket(tag, pkt.ConstBuffer(), eProtocolTrafficV4, 0); return HandleInboundPacket(tag, pkt.ConstBuffer(), eProtocolTrafficV4, 0);
}, },
Router(), Router(),
numPaths, numDesiredPaths,
numHops, numHops,
false, false,
ShouldBundleRC()); ShouldBundleRC());
@ -1466,13 +1466,8 @@ namespace llarp
bool bool
Endpoint::ShouldBuildMore(llarp_time_t now) const Endpoint::ShouldBuildMore(llarp_time_t now) const
{ {
if (path::Builder::BuildCooldownHit(now)) if (not path::Builder::ShouldBuildMore(now))
return false; return false;
size_t numBuilding = NumInStatus(path::ePathBuilding);
if (numBuilding > 0)
return false;
return ((now - lastBuild) > path::intro_path_spread) return ((now - lastBuild) > path::intro_path_spread)
|| NumInStatus(path::ePathEstablished) < path::min_intro_paths; || NumInStatus(path::ePathEstablished) < path::min_intro_paths;
} }

@ -359,11 +359,9 @@ namespace llarp
bool bool
OutboundContext::ShouldBuildMore(llarp_time_t now) const OutboundContext::ShouldBuildMore(llarp_time_t now) const
{ {
if (markedBad || path::Builder::BuildCooldownHit(now)) if (markedBad || not path::Builder::ShouldBuildMore(now))
return false; return false;
const bool canBuild = if (NumInStatus(path::ePathBuilding) >= numDesiredPaths)
NumInStatus(path::ePathBuilding) == 0 and path::Builder::ShouldBuildMore(now);
if (not canBuild)
return false; return false;
llarp_time_t t = 0s; llarp_time_t t = 0s;
ForEachPath([&t](path::Path_ptr path) { ForEachPath([&t](path::Path_ptr path) {

Loading…
Cancel
Save