From 61d42811be8d2c80ecdffd57e89718957e246359 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 7 May 2019 09:04:43 -0400 Subject: [PATCH] prevent crash --- llarp/exit/session.cpp | 2 +- llarp/link/session.hpp | 2 +- llarp/path/pathbuilder.cpp | 19 ++++++++++++------- llarp/utp/session.hpp | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/llarp/exit/session.cpp b/llarp/exit/session.cpp index 98745c7a4..e573fcdc2 100644 --- a/llarp/exit/session.cpp +++ b/llarp/exit/session.cpp @@ -277,7 +277,7 @@ namespace llarp r->TryConnectAsync(results[0], 5); }); } - else if(!BuildCooldownHit(now)) + else if(ShouldBuildMore(now)) BuildOneAlignedTo(m_ExitRouter); } return true; diff --git a/llarp/link/session.hpp b/llarp/link/session.hpp index 9faee2207..c7cdb98d4 100644 --- a/llarp/link/session.hpp +++ b/llarp/link/session.hpp @@ -47,7 +47,7 @@ namespace llarp /// return true if we are established virtual bool - IsEstablished() = 0; + IsEstablished() const = 0; /// return true if this session has timed out virtual bool diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 1e308374f..58324d1de 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -221,12 +221,15 @@ namespace llarp } bool got = false; router->ForEachPeer( - [&](const ILinkSession* s, bool) { - const PubKey k(s->GetPubKey()); - if(got || router->IsBootstrapNode(k)) - return; - cur = s->GetRemoteRC(); - got = true; + [&](const ILinkSession* s, bool isOutbound) { + if(s && s->IsEstablished() && isOutbound && !got) + { + const RouterContact rc = s->GetRemoteRC(); + if(got || router->IsBootstrapNode(rc.pubkey)) + return; + cur = rc; + got = true; + } }, true); return got; @@ -328,7 +331,8 @@ namespace llarp } if(hops.size() == 0) { - LogInfo(Name(), " building path to ", remote); + hops.resize(numHops); + auto nodedb = router->nodedb(); for(size_t hop = 0; hop < numHops; ++hop) { @@ -362,6 +366,7 @@ namespace llarp return false; } } + LogInfo(Name(), " building path to ", remote); Build(hops); return true; } diff --git a/llarp/utp/session.hpp b/llarp/utp/session.hpp index 1694f21f5..eb77e3156 100644 --- a/llarp/utp/session.hpp +++ b/llarp/utp/session.hpp @@ -120,9 +120,9 @@ namespace llarp SendKeepAlive() override; bool - IsEstablished() override + IsEstablished() const override { - return state == eSessionReady || state == eLinkEstablished; + return state == eSessionReady; } bool