tweaking handover logic

pull/309/head
Jeff Becker 5 years ago
parent 1921704b78
commit 50bfe5d810
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

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

@ -64,6 +64,19 @@ 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,6 +144,10 @@ namespace llarp
llarp_time_t
GetNewestIntroExpiration() const;
bool
GetNewestIntroOnRouter(const RouterID& router,
Introduction& result) const;
bool
HasExpiredIntros(llarp_time_t now) const;

@ -1121,29 +1121,6 @@ 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
@ -1175,8 +1152,6 @@ namespace llarp
}
if(GetPathByRouter(m_NextIntro.router) == nullptr)
BuildOneAlignedTo(m_NextIntro.router);
else
SwapIntros();
}
return true;
}
@ -1408,10 +1383,6 @@ namespace llarp
lastShift = now;
BuildOneAlignedTo(m_NextIntro.router);
}
else if(shiftedIntro)
{
SwapIntros();
}
else
{
llarp::LogInfo(Name(), " updating introset");
@ -1428,18 +1399,16 @@ namespace llarp
if(now - lastShift < MIN_SHIFT_INTERVAL)
return false;
bool shifted = false;
// to find a intro on the same router as before
for(const auto& intro : currentIntroSet.I)
Introduction newIntro;
if(currentIntroSet.GetNewestIntroOnRouter(remoteIntro.router, newIntro))
{
if(intro.ExpiresSoon(now))
continue;
if(m_BadIntros.find(intro) == m_BadIntros.end()
&& remoteIntro.router == intro.router)
if(m_NextIntro != newIntro)
{
m_NextIntro = intro;
m_NextIntro = newIntro;
return true;
}
}
for(const auto& intro : currentIntroSet.I)
{
m_Endpoint->EnsureRouterIsKnown(intro.router);
@ -1447,10 +1416,7 @@ namespace llarp
continue;
if(m_BadIntros.find(intro) == m_BadIntros.end() && m_NextIntro != intro)
{
shifted = intro.router != m_NextIntro.router
|| (now < intro.expiresAt
&& intro.expiresAt - now
> 10 * 1000); // TODO: hardcoded value
shifted = intro.router != m_NextIntro.router;
m_NextIntro = intro;
success = true;
break;
@ -1460,6 +1426,7 @@ namespace llarp
{
lastShift = now;
BuildOneAlignedTo(m_NextIntro.router);
SwapIntros();
}
return success;
}
@ -1471,10 +1438,7 @@ namespace llarp
auto now = m_Endpoint->Now();
if(remoteIntro.ExpiresSoon(now))
{
if(!MarkCurrentIntroBad(now))
{
llarp::LogWarn("no good path yet, your message may drop");
}
llarp::LogWarn("no good path yet, your message may drop");
}
if(sequenceNo)
{
@ -1708,13 +1672,6 @@ 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)
@ -1724,9 +1681,16 @@ 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())
@ -1739,6 +1703,11 @@ 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());
@ -1836,7 +1805,6 @@ namespace llarp
{
llarp::LogError("cannot encrypt and send: no path for intro ",
remoteIntro);
return;
}

Loading…
Cancel
Save