Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

final touches for handover drop bug #836

Merged
merged 1 commit into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions llarp/path/pathbuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ namespace llarp
virtual const SecretKey&
GetTunnelEncryptionSecretKey() const;

void
virtual void
HandlePathBuilt(Path_ptr p) override;

void
virtual void
HandlePathBuildTimeout(Path_ptr p) override;

void
virtual void
HandlePathBuildFailed(Path_ptr p) override;
};

Expand Down
1 change: 1 addition & 0 deletions llarp/service/endpoint_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ namespace llarp
{
if(itr->second.IsExpired(now))
{
LogInfo("Expire session T=", itr->first);
itr = sessions.erase(itr);
}
else
Expand Down
54 changes: 47 additions & 7 deletions llarp/service/outbound_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,20 @@ namespace llarp
if(MarkCurrentIntroBad(Now()))
{
SwapIntros();
LogInfo(Name(), " switched intros to ", remoteIntro.router, " via ",
remoteIntro.pathID);
}
UpdateIntroSet(true);
}
return true;
}

OutboundContext::OutboundContext(const IntroSet& introset, Endpoint* parent)
: path::Builder(parent->Router(), 3, path::default_len)
: path::Builder(parent->Router(), 4, path::default_len)
, SendContext(introset.A, {}, this, parent)
, currentIntroSet(introset)

{
updatingIntroSet = false;
for(const auto intro : introset.I)
for(const auto& intro : introset.I)
{
if(intro.expiresAt > m_NextIntro.expiresAt)
m_NextIntro = intro;
Expand All @@ -75,6 +73,7 @@ namespace llarp
{
if(remoteIntro != m_NextIntro)
{
LogInfo(Name(), " swap intro to use ", RouterID(m_NextIntro.router));
remoteIntro = m_NextIntro;
m_DataHandler->PutIntroFor(currentConvoTag, remoteIntro);
ShiftIntroduction(false);
Expand Down Expand Up @@ -114,7 +113,10 @@ namespace llarp
BuildOneAlignedTo(m_NextIntro.router);
}
else
{
++m_LookupFails;
LogWarn(Name(), " failed to look up introset, fails=", m_LookupFails);
}
return true;
}

Expand All @@ -125,6 +127,32 @@ namespace llarp
&& GetPathByRouter(remoteIntro.router) != nullptr;
}

void
OutboundContext::ShiftIntroRouter(const RouterID r)
{
const auto now = Now();
Introduction selectedIntro;
for(const auto& intro : currentIntroSet.I)
{
if(intro.expiresAt > selectedIntro.expiresAt && intro.router != r)
{
selectedIntro = intro;
}
}
if(selectedIntro.router.IsZero() || selectedIntro.ExpiresSoon(now))
return;
LogWarn(Name(), " shfiting intro off of ", r, " to ",
RouterID(selectedIntro.router));
m_NextIntro = selectedIntro;
}

void
OutboundContext::HandlePathBuildTimeout(path::Path_ptr p)
{
ShiftIntroRouter(p->Endpoint());
path::Builder::HandlePathBuildTimeout(p);
}

void
OutboundContext::HandlePathBuilt(path::Path_ptr p)
{
Expand All @@ -138,6 +166,10 @@ namespace llarp
// we now have a path to the next intro, swap intros
if(p->Endpoint() == m_NextIntro.router)
SwapIntros();
else
{
LogInfo(Name(), " built to non aligned router: ", p->Endpoint());
}
}

void
Expand Down Expand Up @@ -241,6 +273,7 @@ namespace llarp
// we are probably dead af
if(m_LookupFails > 16 || m_BuildFails > 10)
return true;

// check for expiration
if(remoteIntro.ExpiresSoon(now))
{
Expand Down Expand Up @@ -296,9 +329,10 @@ namespace llarp
{
if(m_NextIntro.router.IsZero() || prev.count(m_NextIntro.router))
{
if(!ShiftIntroduction(false))
return false;
ShiftIntroduction(false);
}
if(m_NextIntro.router.IsZero())
return false;
std::set< RouterID > exclude = prev;
exclude.insert(m_NextIntro.router);
for(const auto& snode : m_Endpoint->SnodeBlacklist())
Expand Down Expand Up @@ -337,9 +371,15 @@ namespace llarp

bool
OutboundContext::MarkCurrentIntroBad(llarp_time_t now)
{
return MarkIntroBad(remoteIntro, now);
}

bool
OutboundContext::MarkIntroBad(const Introduction& intro, llarp_time_t now)
{
// insert bad intro
m_BadIntros[remoteIntro] = now;
m_BadIntros[intro] = now;
// try shifting intro without rebuild
if(ShiftIntroduction(false))
{
Expand Down
11 changes: 11 additions & 0 deletions llarp/service/outbound_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <util/status.hpp>

#include <unordered_map>
#include <unordered_set>

namespace llarp
{
Expand Down Expand Up @@ -52,10 +53,17 @@ namespace llarp
bool
ShiftIntroduction(bool rebuild = true) override;

/// shift the intro off the current router it is using
void
ShiftIntroRouter(const RouterID remote);

/// mark the current remote intro as bad
bool
MarkCurrentIntroBad(llarp_time_t now) override;

bool
MarkIntroBad(const Introduction& marked, llarp_time_t now);

/// return true if we are ready to send
bool
ReadyToSend() const;
Expand Down Expand Up @@ -85,6 +93,9 @@ namespace llarp
void
HandlePathBuilt(path::Path_ptr path) override;

void
HandlePathBuildTimeout(path::Path_ptr path) override;

bool
SelectHop(llarp_nodedb* db, const std::set< RouterID >& prev,
RouterContact& cur, size_t hop, path::PathRole roles) override;
Expand Down
1 change: 0 additions & 1 deletion llarp/service/sendcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace llarp
, m_Endpoint(ep)
{
createdAt = ep->Now();
currentConvoTag.Zero();
}

bool
Expand Down