Merge pull request #182 from majestrate/master

better client side exit logic
This commit is contained in:
Jeff 2018-12-27 07:54:43 -05:00 committed by GitHub
commit 0264acf3ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 22 deletions

View File

@ -32,11 +32,15 @@ namespace llarp
BaseSession::ShouldBuildMore(llarp_time_t now) const BaseSession::ShouldBuildMore(llarp_time_t now) const
{ {
const size_t expect = (1 + (m_NumPaths / 2)); const size_t expect = (1 + (m_NumPaths / 2));
if(NumPathsExistingAt(now + (10 * 1000)) < expect) // check 30 seconds into the future and see if we need more paths
return path::Builder::ShouldBuildMore(now); const llarp_time_t future = now + (30 * 1000);
if(NumPathsExistingAt(future) < expect)
return llarp::randint() % 4 == 0; // 25% chance for build if we will run out soon
// if we don't have the expended number of paths right now try building some if the cooldown timer isn't hit
if(AvailablePaths(llarp::path::ePathRoleExit) < expect) if(AvailablePaths(llarp::path::ePathRoleExit) < expect)
return path::Builder::ShouldBuildMore(now); return !path::Builder::BuildCooldownHit(now);
return false; // maintain regular number of paths
return path::Builder::ShouldBuildMore(now);
} }
bool bool
@ -179,24 +183,29 @@ namespace llarp
{ {
auto now = router->Now(); auto now = router->Now();
auto path = PickRandomEstablishedPath(llarp::path::ePathRoleExit); auto path = PickRandomEstablishedPath(llarp::path::ePathRoleExit);
if(!path) if(path)
{ {
// discard for(auto& item : m_Upstream)
{
auto& queue = item.second;
while(queue.size())
{
auto& msg = queue.front();
msg.S = path->NextSeqNo();
if(path->SendRoutingMessage(&msg, router))
m_LastUse = now;
queue.pop_front();
}
}
}
else
{
if(m_Upstream.size())
llarp::LogWarn("no path for exit session");
// discard upstream
for(auto& item : m_Upstream) for(auto& item : m_Upstream)
item.second.clear(); item.second.clear();
return false; m_Upstream.clear();
}
for(auto& item : m_Upstream)
{
auto& queue = item.second;
while(queue.size())
{
auto& msg = queue.front();
msg.S = path->NextSeqNo();
if(path->SendRoutingMessage(&msg, router))
m_LastUse = now;
queue.pop_front();
}
} }
while(m_Downstream.size()) while(m_Downstream.size())
{ {

View File

@ -216,11 +216,17 @@ namespace llarp
return enckey; return enckey;
} }
bool
Builder::BuildCooldownHit(llarp_time_t now) const
{
return now < lastBuild
|| now - lastBuild < buildIntervalLimit;
}
bool bool
Builder::ShouldBuildMore(llarp_time_t now) const Builder::ShouldBuildMore(llarp_time_t now) const
{ {
return llarp::path::PathSet::ShouldBuildMore(now) && now > lastBuild return PathSet::ShouldBuildMore(now) && !BuildCooldownHit(now);
&& now - lastBuild > buildIntervalLimit;
} }
void void

View File

@ -47,6 +47,10 @@ namespace llarp
virtual bool virtual bool
ShouldBuildMore(llarp_time_t now) const override; ShouldBuildMore(llarp_time_t now) const override;
/// return true if we hit our soft limit for building paths too fast
bool
BuildCooldownHit(llarp_time_t now) const;
virtual bool virtual bool
Stop() override; Stop() override;

View File

@ -279,7 +279,7 @@ namespace llarp
void void
PathSet::HandlePathBuildTimeout(Path* p) PathSet::HandlePathBuildTimeout(Path* p)
{ {
llarp::LogInfo("path ", p->Name(), " has timed out"); llarp::LogInfo("path build for ", p->Name(), " has timed out");
} }
bool bool