final touches

pull/836/head
jeff 5 years ago
parent 35230adbe5
commit f9fb40f590

@ -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;
};

@ -116,6 +116,7 @@ namespace llarp
{
if(itr->second.IsExpired(now))
{
LogInfo("Expire session T=", itr->first);
itr = sessions.erase(itr);
}
else

@ -44,8 +44,6 @@ namespace llarp
if(MarkCurrentIntroBad(Now()))
{
SwapIntros();
LogInfo(Name(), " switched intros to ", remoteIntro.router, " via ",
remoteIntro.pathID);
}
UpdateIntroSet(true);
}
@ -53,13 +51,13 @@ namespace llarp
}
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;
@ -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);
@ -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;
}
@ -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)
{
@ -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
@ -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))
{
@ -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())
@ -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))
{

@ -6,6 +6,7 @@
#include <util/status.hpp>
#include <unordered_map>
#include <unordered_set>
namespace llarp
{
@ -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;
@ -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;

@ -19,7 +19,6 @@ namespace llarp
, m_Endpoint(ep)
{
createdAt = ep->Now();
currentConvoTag.Zero();
}
bool

Loading…
Cancel
Save