mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
docstrings and manual rebuild if the path expires soon
This commit is contained in:
parent
186a36cd4b
commit
fa5389cb05
2 changed files with 25 additions and 35 deletions
|
@ -195,8 +195,12 @@ namespace llarp
|
|||
llarp_time_t connectTimeout = 30 * 1000;
|
||||
bool markedBad = false;
|
||||
|
||||
virtual void
|
||||
ShiftIntroduction(){};
|
||||
virtual bool
|
||||
ShiftIntroduction()
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
virtual void
|
||||
UpdateIntroSet(){};
|
||||
virtual bool
|
||||
|
@ -231,7 +235,8 @@ namespace llarp
|
|||
bool updatingIntroSet;
|
||||
|
||||
/// update the current selected intro to be a new best introduction
|
||||
void
|
||||
/// return true if we have changed intros
|
||||
bool
|
||||
ShiftIntroduction();
|
||||
|
||||
/// mark the current remote intro as bad
|
||||
|
|
|
@ -1026,40 +1026,19 @@ namespace llarp
|
|||
bool
|
||||
Endpoint::OutboundContext::MarkCurrentIntroBad(llarp_time_t now)
|
||||
{
|
||||
bool shifted = false;
|
||||
bool success = false;
|
||||
// insert bad intro
|
||||
m_BadIntros.insert(std::make_pair(remoteIntro, now));
|
||||
// shift off current intro
|
||||
for(const auto& intro : currentIntroSet.I)
|
||||
{
|
||||
if(m_BadIntros.find(intro) == m_BadIntros.end()
|
||||
&& !intro.ExpiresSoon(now))
|
||||
{
|
||||
shifted = intro.router != remoteIntro.router;
|
||||
remoteIntro = intro;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// don't rebuild paths rapidly
|
||||
if(now - lastShift < MIN_SHIFT_INTERVAL)
|
||||
return success;
|
||||
// rebuild path if shifted
|
||||
if(shifted)
|
||||
{
|
||||
lastShift = now;
|
||||
ManualRebuild(1);
|
||||
}
|
||||
return success;
|
||||
// shift
|
||||
return ShiftIntroduction();
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
Endpoint::OutboundContext::ShiftIntroduction()
|
||||
{
|
||||
bool success = false;
|
||||
auto now = llarp_time_now_ms();
|
||||
if(now - lastShift < MIN_SHIFT_INTERVAL)
|
||||
return;
|
||||
return false;
|
||||
bool shifted = false;
|
||||
for(const auto& intro : currentIntroSet.I)
|
||||
{
|
||||
|
@ -1068,8 +1047,12 @@ namespace llarp
|
|||
continue;
|
||||
if(m_BadIntros.find(intro) == m_BadIntros.end() && remoteIntro != intro)
|
||||
{
|
||||
shifted = intro.router != remoteIntro.router;
|
||||
shifted = intro.router != remoteIntro.router
|
||||
|| (now < intro.expiresAt
|
||||
&& intro.expiresAt - now
|
||||
> 10 * 1000); // TODO: hardcoded value
|
||||
remoteIntro = intro;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1078,6 +1061,7 @@ namespace llarp
|
|||
lastShift = now;
|
||||
ManualRebuild(1);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1282,13 +1266,13 @@ namespace llarp
|
|||
{
|
||||
if(remoteIntro.ExpiresSoon(now))
|
||||
{
|
||||
if(!MarkCurrentIntroBad(now))
|
||||
{
|
||||
// TODO: log?
|
||||
}
|
||||
// shift intro if it expires "soon"
|
||||
ShiftIntroduction();
|
||||
}
|
||||
// lookup router in intro if set and unknown
|
||||
if(!remoteIntro.router.IsZero())
|
||||
m_Endpoint->EnsureRouterIsKnown(remoteIntro.router);
|
||||
// expire bad intros
|
||||
auto itr = m_BadIntros.begin();
|
||||
while(itr != m_BadIntros.end())
|
||||
{
|
||||
|
@ -1297,6 +1281,7 @@ namespace llarp
|
|||
else
|
||||
++itr;
|
||||
}
|
||||
// if we are dead return true so we are removed
|
||||
return lastGoodSend
|
||||
? (now >= lastGoodSend && now - lastGoodSend > sendTimeout)
|
||||
: (now >= createdAt && now - createdAt > connectTimeout);
|
||||
|
|
Loading…
Reference in a new issue