|
|
@ -332,61 +332,33 @@ namespace llarp
|
|
|
|
OutboundContext::MarkCurrentIntroBad(llarp_time_t now)
|
|
|
|
OutboundContext::MarkCurrentIntroBad(llarp_time_t now)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// insert bad intro
|
|
|
|
// insert bad intro
|
|
|
|
m_BadIntros[remoteIntro] = now;
|
|
|
|
m_BadIntros[m_NextIntro] = now;
|
|
|
|
// unconditional shift
|
|
|
|
// try shifting intro without rebuild
|
|
|
|
bool shiftedRouter = false;
|
|
|
|
if(ShiftIntroduction(false))
|
|
|
|
bool shiftedIntro = false;
|
|
|
|
|
|
|
|
// try same router
|
|
|
|
|
|
|
|
for(const auto& intro : currentIntroSet.I)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(intro.ExpiresSoon(now))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(router->routerProfiling().IsBadForPath(intro.router))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto itr = m_BadIntros.find(intro);
|
|
|
|
|
|
|
|
if(itr == m_BadIntros.end() && intro.router == m_NextIntro.router)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(intro.expiresAt > m_NextIntro.expiresAt)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
shiftedIntro = true;
|
|
|
|
|
|
|
|
m_NextIntro = intro;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!shiftedIntro)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// try any router
|
|
|
|
|
|
|
|
for(const auto& intro : currentIntroSet.I)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(intro.ExpiresSoon(now))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto itr = m_BadIntros.find(intro);
|
|
|
|
|
|
|
|
if(itr == m_BadIntros.end())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// TODO: this should always be true but idk if it really is
|
|
|
|
|
|
|
|
if(intro.expiresAt > m_NextIntro.expiresAt)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
shiftedRouter = m_NextIntro.router != intro.router;
|
|
|
|
|
|
|
|
shiftedIntro = true;
|
|
|
|
|
|
|
|
m_NextIntro = intro;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(shiftedRouter)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lastShift = now;
|
|
|
|
// we shifted
|
|
|
|
|
|
|
|
// check if we have a path to the next intro router
|
|
|
|
|
|
|
|
if(GetNewestPathByRouter(m_NextIntro.router))
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// we don't have a path build one if we aren't building too fast
|
|
|
|
if(!BuildCooldownHit(now))
|
|
|
|
if(!BuildCooldownHit(now))
|
|
|
|
BuildOneAlignedTo(m_NextIntro.router);
|
|
|
|
BuildOneAlignedTo(m_NextIntro.router);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!shiftedIntro)
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LogInfo(Name(), " updating introset");
|
|
|
|
// we didn't shift check if we should update introset
|
|
|
|
UpdateIntroSet(true);
|
|
|
|
if(now - lastShift >= MIN_SHIFT_INTERVAL
|
|
|
|
|
|
|
|
|| currentIntroSet.HasExpiredIntros(now)
|
|
|
|
|
|
|
|
|| currentIntroSet.IsExpired(now))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// update introset
|
|
|
|
|
|
|
|
LogInfo(Name(), " updating introset");
|
|
|
|
|
|
|
|
UpdateIntroSet(true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return shiftedIntro;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
bool
|
|
|
@ -409,37 +381,40 @@ namespace llarp
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(intro.expiresAt > m_NextIntro.expiresAt)
|
|
|
|
if(intro.expiresAt > m_NextIntro.expiresAt)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
success = true;
|
|
|
|
m_NextIntro = intro;
|
|
|
|
m_NextIntro = intro;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// pick newer intro not on same router
|
|
|
|
if(!success)
|
|
|
|
for(const auto& intro : currentIntroSet.I)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(m_Endpoint->m_SnodeBlacklist.count(intro.router))
|
|
|
|
/// pick newer intro not on same router
|
|
|
|
continue;
|
|
|
|
for(const auto& intro : currentIntroSet.I)
|
|
|
|
m_Endpoint->EnsureRouterIsKnown(intro.router);
|
|
|
|
|
|
|
|
if(intro.ExpiresSoon(now))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(m_BadIntros.find(intro) == m_BadIntros.end() && m_NextIntro != intro)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(intro.expiresAt > m_NextIntro.expiresAt)
|
|
|
|
if(m_Endpoint->m_SnodeBlacklist.count(intro.router))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
m_Endpoint->EnsureRouterIsKnown(intro.router);
|
|
|
|
|
|
|
|
if(intro.ExpiresSoon(now))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(m_BadIntros.find(intro) == m_BadIntros.end()
|
|
|
|
|
|
|
|
&& m_NextIntro != intro)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
shifted = intro.router != m_NextIntro.router;
|
|
|
|
if(intro.expiresAt > m_NextIntro.expiresAt)
|
|
|
|
m_NextIntro = intro;
|
|
|
|
{
|
|
|
|
success = true;
|
|
|
|
shifted = intro.router != m_NextIntro.router;
|
|
|
|
|
|
|
|
m_NextIntro = intro;
|
|
|
|
|
|
|
|
success = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(m_NextIntro.router.IsZero())
|
|
|
|
if(m_NextIntro.router.IsZero())
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
if(shifted)
|
|
|
|
if(shifted)
|
|
|
|
{
|
|
|
|
|
|
|
|
lastShift = now;
|
|
|
|
lastShift = now;
|
|
|
|
if(rebuild && !BuildCooldownHit(Now()))
|
|
|
|
if(rebuild && !BuildCooldownHit(Now()))
|
|
|
|
BuildOneAlignedTo(m_NextIntro.router);
|
|
|
|
BuildOneAlignedTo(m_NextIntro.router);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -496,7 +471,9 @@ namespace llarp
|
|
|
|
// check if we have a path to this router
|
|
|
|
// check if we have a path to this router
|
|
|
|
num = 0;
|
|
|
|
num = 0;
|
|
|
|
ForEachPath([&](const path::Path_ptr& p) {
|
|
|
|
ForEachPath([&](const path::Path_ptr& p) {
|
|
|
|
if(p->Endpoint() == m_NextIntro.router)
|
|
|
|
// don't count timed out paths
|
|
|
|
|
|
|
|
if(p->Status() != path::ePathTimeout
|
|
|
|
|
|
|
|
&& p->Endpoint() == m_NextIntro.router)
|
|
|
|
++num;
|
|
|
|
++num;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// build a path if one isn't already pending build or established
|
|
|
|
// build a path if one isn't already pending build or established
|
|
|
|