final touches

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

@ -113,13 +113,13 @@ namespace llarp
virtual const SecretKey& virtual const SecretKey&
GetTunnelEncryptionSecretKey() const; GetTunnelEncryptionSecretKey() const;
void virtual void
HandlePathBuilt(Path_ptr p) override; HandlePathBuilt(Path_ptr p) override;
void virtual void
HandlePathBuildTimeout(Path_ptr p) override; HandlePathBuildTimeout(Path_ptr p) override;
void virtual void
HandlePathBuildFailed(Path_ptr p) override; HandlePathBuildFailed(Path_ptr p) override;
}; };

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

@ -44,8 +44,6 @@ namespace llarp
if(MarkCurrentIntroBad(Now())) if(MarkCurrentIntroBad(Now()))
{ {
SwapIntros(); SwapIntros();
LogInfo(Name(), " switched intros to ", remoteIntro.router, " via ",
remoteIntro.pathID);
} }
UpdateIntroSet(true); UpdateIntroSet(true);
} }
@ -53,13 +51,13 @@ namespace llarp
} }
OutboundContext::OutboundContext(const IntroSet& introset, Endpoint* parent) 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) , SendContext(introset.A, {}, this, parent)
, currentIntroSet(introset) , currentIntroSet(introset)
{ {
updatingIntroSet = false; updatingIntroSet = false;
for(const auto intro : introset.I) for(const auto& intro : introset.I)
{ {
if(intro.expiresAt > m_NextIntro.expiresAt) if(intro.expiresAt > m_NextIntro.expiresAt)
m_NextIntro = intro; m_NextIntro = intro;
@ -75,6 +73,7 @@ namespace llarp
{ {
if(remoteIntro != m_NextIntro) if(remoteIntro != m_NextIntro)
{ {
LogInfo(Name(), " swap intro to use ", RouterID(m_NextIntro.router));
remoteIntro = m_NextIntro; remoteIntro = m_NextIntro;
m_DataHandler->PutIntroFor(currentConvoTag, remoteIntro); m_DataHandler->PutIntroFor(currentConvoTag, remoteIntro);
ShiftIntroduction(false); ShiftIntroduction(false);
@ -114,7 +113,10 @@ namespace llarp
BuildOneAlignedTo(m_NextIntro.router); BuildOneAlignedTo(m_NextIntro.router);
} }
else else
{
++m_LookupFails; ++m_LookupFails;
LogWarn(Name(), " failed to look up introset, fails=", m_LookupFails);
}
return true; return true;
} }
@ -125,6 +127,32 @@ namespace llarp
&& GetPathByRouter(remoteIntro.router) != nullptr; && 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 void
OutboundContext::HandlePathBuilt(path::Path_ptr p) OutboundContext::HandlePathBuilt(path::Path_ptr p)
{ {
@ -138,6 +166,10 @@ namespace llarp
// we now have a path to the next intro, swap intros // we now have a path to the next intro, swap intros
if(p->Endpoint() == m_NextIntro.router) if(p->Endpoint() == m_NextIntro.router)
SwapIntros(); SwapIntros();
else
{
LogInfo(Name(), " built to non aligned router: ", p->Endpoint());
}
} }
void void
@ -241,6 +273,7 @@ namespace llarp
// we are probably dead af // we are probably dead af
if(m_LookupFails > 16 || m_BuildFails > 10) if(m_LookupFails > 16 || m_BuildFails > 10)
return true; return true;
// check for expiration // check for expiration
if(remoteIntro.ExpiresSoon(now)) if(remoteIntro.ExpiresSoon(now))
{ {
@ -296,9 +329,10 @@ namespace llarp
{ {
if(m_NextIntro.router.IsZero() || prev.count(m_NextIntro.router)) if(m_NextIntro.router.IsZero() || prev.count(m_NextIntro.router))
{ {
if(!ShiftIntroduction(false)) ShiftIntroduction(false);
return false;
} }
if(m_NextIntro.router.IsZero())
return false;
std::set< RouterID > exclude = prev; std::set< RouterID > exclude = prev;
exclude.insert(m_NextIntro.router); exclude.insert(m_NextIntro.router);
for(const auto& snode : m_Endpoint->SnodeBlacklist()) for(const auto& snode : m_Endpoint->SnodeBlacklist())
@ -337,9 +371,15 @@ namespace llarp
bool bool
OutboundContext::MarkCurrentIntroBad(llarp_time_t now) OutboundContext::MarkCurrentIntroBad(llarp_time_t now)
{
return MarkIntroBad(remoteIntro, now);
}
bool
OutboundContext::MarkIntroBad(const Introduction& intro, llarp_time_t now)
{ {
// insert bad intro // insert bad intro
m_BadIntros[remoteIntro] = now; m_BadIntros[intro] = now;
// try shifting intro without rebuild // try shifting intro without rebuild
if(ShiftIntroduction(false)) if(ShiftIntroduction(false))
{ {

@ -6,6 +6,7 @@
#include <util/status.hpp> #include <util/status.hpp>
#include <unordered_map> #include <unordered_map>
#include <unordered_set>
namespace llarp namespace llarp
{ {
@ -52,10 +53,17 @@ namespace llarp
bool bool
ShiftIntroduction(bool rebuild = true) override; 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 /// mark the current remote intro as bad
bool bool
MarkCurrentIntroBad(llarp_time_t now) override; MarkCurrentIntroBad(llarp_time_t now) override;
bool
MarkIntroBad(const Introduction& marked, llarp_time_t now);
/// return true if we are ready to send /// return true if we are ready to send
bool bool
ReadyToSend() const; ReadyToSend() const;
@ -85,6 +93,9 @@ namespace llarp
void void
HandlePathBuilt(path::Path_ptr path) override; HandlePathBuilt(path::Path_ptr path) override;
void
HandlePathBuildTimeout(path::Path_ptr path) override;
bool bool
SelectHop(llarp_nodedb* db, const std::set< RouterID >& prev, SelectHop(llarp_nodedb* db, const std::set< RouterID >& prev,
RouterContact& cur, size_t hop, path::PathRole roles) override; RouterContact& cur, size_t hop, path::PathRole roles) override;

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

Loading…
Cancel
Save