limit path builds across all builders

pull/1626/head
Jeff Becker 3 years ago
parent 289ab9c4be
commit ec62228149
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -160,12 +160,26 @@ namespace llarp
namespace path
{
bool
BuildLimiter::Attempt(const RouterID& router)
{
return m_EdgeLimiter.Insert(router);
}
void
BuildLimiter::Decay(llarp_time_t now)
{
m_EdgeLimiter.Decay(now);
}
bool
BuildLimiter::Limited(const RouterID& router) const
{
return m_EdgeLimiter.Contains(router);
}
Builder::Builder(AbstractRouter* p_router, size_t pathNum, size_t hops)
: path::PathSet{pathNum}
, m_EdgeLimiter{MIN_PATH_BUILD_INTERVAL}
, _run{true}
, m_router{p_router}
, numHops{hops}
: path::PathSet{pathNum}, _run{true}, m_router{p_router}, numHops{hops}
{
CryptoManager::instance()->encryption_keygen(enckey);
}
@ -180,7 +194,6 @@ namespace llarp
void Builder::Tick(llarp_time_t)
{
const auto now = llarp::time_now_ms();
m_EdgeLimiter.Decay(now);
ExpirePaths(now, m_router);
if (ShouldBuildMore(now))
BuildOne();
@ -226,7 +239,7 @@ namespace llarp
if (exclude.count(rc.pubkey))
return;
if (m_EdgeLimiter.Contains(rc.pubkey))
if (BuildCooldownHit(rc.pubkey))
return;
found = rc;
@ -277,7 +290,7 @@ namespace llarp
bool
Builder::BuildCooldownHit(RouterID edge) const
{
return m_EdgeLimiter.Contains(edge);
return m_router->pathBuildLimiter().Limited(edge);
}
bool
@ -399,7 +412,7 @@ namespace llarp
return;
lastBuild = Now();
const RouterID edge{hops[0].pubkey};
if (not m_EdgeLimiter.Insert(edge))
if (not m_router->pathBuildLimiter().Attempt(edge))
{
LogWarn(Name(), " building too fast to edge router ", edge);
return;
@ -437,8 +450,6 @@ namespace llarp
{
PathSet::HandlePathBuildFailedAt(p, edge);
DoPathBuildBackoff();
/// add it to the edge limter even if it's not an edge for simplicity
m_EdgeLimiter.Insert(edge);
}
void

@ -15,11 +15,31 @@ namespace llarp
static constexpr auto MIN_PATH_BUILD_INTERVAL = 500ms;
static constexpr auto PATH_BUILD_RATE = 100ms;
/// limiter for path builds
/// prevents overload and such
class BuildLimiter
{
util::DecayingHashSet<RouterID> m_EdgeLimiter;
public:
/// attempt a build
/// return true if we are allowed to continue
bool
Attempt(const RouterID& router);
/// decay limit entries
void
Decay(llarp_time_t now);
/// return true if this router is currently limited
bool
Limited(const RouterID& router) const;
};
struct Builder : public PathSet
{
private:
llarp_time_t m_LastWarn = 0s;
util::DecayingHashSet<RouterID> m_EdgeLimiter;
protected:
/// flag for PathSet::Stop()

@ -292,6 +292,9 @@ namespace llarp
virtual bool
ConnectionToRouterAllowed(const RouterID& router) const = 0;
virtual path::BuildLimiter&
pathBuildLimiter() = 0;
/// return true if we have at least 1 session to this router in either
/// direction
virtual bool

@ -753,6 +753,8 @@ namespace llarp
}
#endif
m_PathBuildLimiter.Decay(now);
routerProfiling().Tick();
if (ShouldReportStats(now))

@ -74,6 +74,14 @@ namespace llarp
LMQ_ptr m_lmq;
path::BuildLimiter m_PathBuildLimiter;
path::BuildLimiter&
pathBuildLimiter() override
{
return m_PathBuildLimiter;
}
const LMQ_ptr&
lmq() const override
{

Loading…
Cancel
Save