try better publish logic and timeouts for requests

pull/18/head
Jeff Becker 6 years ago
parent 4158e422bb
commit 681e669fd8
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -113,6 +113,12 @@ namespace llarp
Path*
GetPathByID(const PathID_t& id) const;
bool
GetCurrentIntroductionsWithFilter(
std::set< llarp::service::Introduction >& intros,
std::function< bool(const llarp::service::Introduction&) > filter)
const;
bool
GetCurrentIntroductions(
std::set< llarp::service::Introduction >& intros) const;

@ -351,7 +351,7 @@ namespace llarp
protected:
void
RegenAndPublishIntroSet(llarp_time_t now);
RegenAndPublishIntroSet(llarp_time_t now, bool forceRebuild = false);
IServiceLookup*
GenerateLookupByTag(const Tag& tag);

@ -32,7 +32,7 @@ namespace llarp
/// determine if this request has timed out
bool
IsTimedOut(llarp_time_t now, llarp_time_t timeout = 5000) const
IsTimedOut(llarp_time_t now, llarp_time_t timeout = 10000) const
{
if(now <= m_created)
return false;

@ -165,6 +165,26 @@ namespace llarp
" rx=", path->RXID());
}
bool
PathSet::GetCurrentIntroductionsWithFilter(
std::set< llarp::service::Introduction >& intros,
std::function< bool(const llarp::service::Introduction&) > filter) const
{
intros.clear();
size_t count = 0;
auto itr = m_Paths.begin();
while(itr != m_Paths.end())
{
if(itr->second->IsReady() && filter(itr->second->intro))
{
intros.insert(itr->second->intro);
++count;
}
++itr;
}
return count > 0;
}
bool
PathSet::GetCurrentIntroductions(
std::set< llarp::service::Introduction >& intros) const

@ -91,22 +91,25 @@ namespace llarp
}
void
Endpoint::RegenAndPublishIntroSet(llarp_time_t now)
Endpoint::RegenAndPublishIntroSet(llarp_time_t now, bool forceRebuild)
{
std::set< Introduction > I;
if(!GetCurrentIntroductions(I))
if(!GetCurrentIntroductionsWithFilter(
I, [now](const service::Introduction& intro) -> bool {
return now < intro.expiresAt
&& intro.expiresAt - now > (2 * 60 * 1000);
}))
{
llarp::LogWarn("could not publish descriptors for endpoint ", Name(),
" because we couldn't get any introductions");
if(ShouldBuildMore())
" because we couldn't get enough valid introductions");
if(ShouldBuildMore() || forceRebuild)
ManualRebuild(1);
return;
}
m_IntroSet.I.clear();
for(const auto& intro : I)
{
if(now < intro.expiresAt && intro.expiresAt - now > 60000)
m_IntroSet.I.push_back(intro);
m_IntroSet.I.push_back(intro);
}
if(m_IntroSet.I.size() == 0)
{
@ -815,7 +818,7 @@ namespace llarp
Endpoint::HandlePathDead(void* user)
{
Endpoint* self = static_cast< Endpoint* >(user);
self->RegenAndPublishIntroSet(llarp_time_now_ms());
self->RegenAndPublishIntroSet(llarp_time_now_ms(), true);
}
bool

Loading…
Cancel
Save