Revert "tweaking handover logic"

This reverts commit 50bfe5d810.
pull/309/head
Jeff Becker 5 years ago
parent 39fdebbf48
commit 550fc3c439
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -12,7 +12,6 @@ namespace llarp
Introduction::ExtractStatus() const
{
util::StatusObject obj{{"router", router.ToHex()},
{"path", pathID.ToHex()},
{"expiresAt", expiresAt},
{"latency", latency},
{"version", uint64_t(version)}};

@ -64,19 +64,6 @@ namespace llarp
return read;
}
bool
IntroSet::GetNewestIntroOnRouter(const RouterID& router,
Introduction& intro) const
{
intro.Clear();
for(const auto& i : I)
{
if(intro.router == router && intro.expiresAt < i.expiresAt)
intro = i;
}
return intro.expiresAt > 0;
}
bool
IntroSet::BEncode(llarp_buffer_t* buf) const
{

@ -144,10 +144,6 @@ namespace llarp
llarp_time_t
GetNewestIntroExpiration() const;
bool
GetNewestIntroOnRouter(const RouterID& router,
Introduction& result) const;
bool
HasExpiredIntros(llarp_time_t now) const;

@ -1121,6 +1121,29 @@ namespace llarp
Endpoint::OutboundContext::SwapIntros()
{
remoteIntro = m_NextIntro;
// prepare next intro
auto now = Now();
for(const auto& intro : currentIntroSet.I)
{
if(intro.ExpiresSoon(now))
continue;
if(m_BadIntros.find(intro) == m_BadIntros.end()
&& remoteIntro.router == intro.router)
{
m_NextIntro = intro;
return;
}
}
for(const auto& intro : currentIntroSet.I)
{
if(intro.ExpiresSoon(now))
continue;
if(m_BadIntros.find(intro) == m_BadIntros.end())
{
m_NextIntro = intro;
return;
}
}
}
bool
@ -1152,6 +1175,8 @@ namespace llarp
}
if(GetPathByRouter(m_NextIntro.router) == nullptr)
BuildOneAlignedTo(m_NextIntro.router);
else
SwapIntros();
}
return true;
}
@ -1383,6 +1408,10 @@ namespace llarp
lastShift = now;
BuildOneAlignedTo(m_NextIntro.router);
}
else if(shiftedIntro)
{
SwapIntros();
}
else
{
llarp::LogInfo(Name(), " updating introset");
@ -1399,16 +1428,18 @@ namespace llarp
if(now - lastShift < MIN_SHIFT_INTERVAL)
return false;
bool shifted = false;
Introduction newIntro;
if(currentIntroSet.GetNewestIntroOnRouter(remoteIntro.router, newIntro))
// to find a intro on the same router as before
for(const auto& intro : currentIntroSet.I)
{
if(m_NextIntro != newIntro)
if(intro.ExpiresSoon(now))
continue;
if(m_BadIntros.find(intro) == m_BadIntros.end()
&& remoteIntro.router == intro.router)
{
m_NextIntro = newIntro;
m_NextIntro = intro;
return true;
}
}
for(const auto& intro : currentIntroSet.I)
{
m_Endpoint->EnsureRouterIsKnown(intro.router);
@ -1416,7 +1447,10 @@ namespace llarp
continue;
if(m_BadIntros.find(intro) == m_BadIntros.end() && m_NextIntro != intro)
{
shifted = intro.router != m_NextIntro.router;
shifted = intro.router != m_NextIntro.router
|| (now < intro.expiresAt
&& intro.expiresAt - now
> 10 * 1000); // TODO: hardcoded value
m_NextIntro = intro;
success = true;
break;
@ -1426,7 +1460,6 @@ namespace llarp
{
lastShift = now;
BuildOneAlignedTo(m_NextIntro.router);
SwapIntros();
}
return success;
}
@ -1438,7 +1471,10 @@ namespace llarp
auto now = m_Endpoint->Now();
if(remoteIntro.ExpiresSoon(now))
{
llarp::LogWarn("no good path yet, your message may drop");
if(!MarkCurrentIntroBad(now))
{
llarp::LogWarn("no good path yet, your message may drop");
}
}
if(sequenceNo)
{
@ -1672,6 +1708,13 @@ namespace llarp
bool
Endpoint::OutboundContext::Tick(llarp_time_t now)
{
// check for expiration
if(remoteIntro.ExpiresSoon(now))
{
// shift intro if it expires "soon"
ShiftIntroduction();
}
// swap if we can
if(remoteIntro != m_NextIntro)
{
if(GetPathByRouter(m_NextIntro.router) != nullptr)
@ -1681,16 +1724,9 @@ namespace llarp
llarp::LogInfo(Name(), "swapped intro");
}
}
else if(remoteIntro.ExpiresSoon(now))
{
// 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())
@ -1703,11 +1739,6 @@ namespace llarp
// send control message if we look too quiet
if(now - lastGoodSend > (sendTimeout / 2))
{
// build path
if(GetPathByRouter(remoteIntro.router) == nullptr)
{
BuildOneAlignedTo(remoteIntro.router);
}
Encrypted< 64 > tmp;
tmp.Randomize();
llarp_buffer_t buf(tmp.data(), tmp.size());
@ -1805,6 +1836,7 @@ namespace llarp
{
llarp::LogError("cannot encrypt and send: no path for intro ",
remoteIntro);
return;
}

Loading…
Cancel
Save