try spacing path building out more wide in time so that intros don't die in the same small interval

This commit is contained in:
Jeff Becker 2018-09-27 06:51:30 -04:00
parent 34dc5bec93
commit d71882259e
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
3 changed files with 40 additions and 2 deletions

View File

@ -51,6 +51,9 @@ namespace llarp
virtual void
HandlePathBuildTimeout(Path* path);
bool
GetNewestIntro(service::Introduction& intro) const;
void
AddPath(Path* path);
@ -124,10 +127,12 @@ namespace llarp
SelectHop(llarp_nodedb* db, const RouterContact& prev, RouterContact& cur,
size_t hop) = 0;
protected:
size_t m_NumPaths;
private:
typedef std::pair< RouterID, PathID_t > PathInfo_t;
typedef std::map< PathInfo_t, Path* > PathMap_t;
size_t m_NumPaths;
PathMap_t m_Paths;
};

View File

@ -190,6 +190,24 @@ namespace llarp
llarp::LogInfo("path ", p->Name(), " has timed out");
}
bool
PathSet::GetNewestIntro(service::Introduction& intro) const
{
bool found = false;
auto itr = m_Paths.begin();
while(itr != m_Paths.end())
{
if(itr->second->IsReady()
&& itr->second->intro.expiresAt > intro.expiresAt)
{
intro = itr->second->intro;
found = true;
}
++itr;
}
return found;
}
Path*
PathSet::PickRandomEstablishedPath() const
{

View File

@ -1343,7 +1343,21 @@ namespace llarp
{
if(markedBad)
return false;
return path::Builder::ShouldBuildMore();
bool should = path::Builder::ShouldBuildMore();
// determinte newest intro
Introduction intro;
if(!GetNewestIntro(intro))
return should;
auto now = llarp_time_now_ms();
// time from now that the newest intro expires at
auto dlt = now < intro.expiresAt ? intro.expiresAt - now : 0;
return should || // try spacing tunnel builds out evenly in time
(dlt
&& (dlt < (DEFAULT_PATH_LIFETIME / 2)
&& NumInStatus(path::ePathBuilding)
< m_NumPaths) // try not to overload with builds
&& dlt > buildIntervalLimit);
}
/// send on an established convo tag
@ -1371,6 +1385,7 @@ namespace llarp
// shift intro
if(!MarkCurrentIntroBad(now))
{
UpdateIntroSet();
llarp::LogError("dropping message, no path after shifting intros");
return;
}