From f110f3f3adbbd5deac872fc5bfea3080f3622b75 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 18 Sep 2018 19:56:26 -0400 Subject: [PATCH] tweak parameters for path build and obtain path if we have none --- include/llarp/path.hpp | 2 +- include/llarp/pathset.hpp | 3 +++ llarp/pathset.cpp | 22 ++++++++++++++++++++ llarp/service/endpoint.cpp | 42 ++++++++++++++++++-------------------- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/include/llarp/path.hpp b/include/llarp/path.hpp index b2d8e0cbf..83d9f0079 100644 --- a/include/llarp/path.hpp +++ b/include/llarp/path.hpp @@ -24,7 +24,7 @@ #define MAXHOPS (8) #define DEFAULT_PATH_LIFETIME (10 * 60 * 1000) -#define PATH_BUILD_TIMEOUT (30 * 1000) +#define PATH_BUILD_TIMEOUT (15 * 1000) #define MESSAGE_PAD_SIZE (512) namespace llarp diff --git a/include/llarp/pathset.hpp b/include/llarp/pathset.hpp index 00840e224..649b700e7 100644 --- a/include/llarp/pathset.hpp +++ b/include/llarp/pathset.hpp @@ -101,6 +101,9 @@ namespace llarp Path* GetPathByRouter(const RouterID& router) const; + Path* + GetNewestPathByRouter(const RouterID& router) const; + Path* GetPathByID(const PathID_t& id) const; diff --git a/llarp/pathset.cpp b/llarp/pathset.cpp index d5a72b51d..eb0e4d694 100644 --- a/llarp/pathset.cpp +++ b/llarp/pathset.cpp @@ -64,6 +64,28 @@ namespace llarp return path; } + Path* + PathSet::GetNewestPathByRouter(const RouterID& id) const + { + Path* chosen = nullptr; + auto itr = m_Paths.begin(); + while(itr != m_Paths.end()) + { + if(itr->second->IsReady()) + { + if(itr->second->Endpoint() == id) + { + if(chosen == nullptr) + chosen = itr->second; + else if(chosen->intro.expiresAt < itr->second->intro.expiresAt) + chosen = itr->second; + } + } + ++itr; + } + return chosen; + } + Path* PathSet::GetPathByRouter(const RouterID& id) const { diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index d367cc3e0..939c84647 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -906,29 +906,27 @@ namespace llarp } } } - if(p == nullptr) + if(p) { - llarp::LogError("no path found"); - return false; - } - // TODO: check expiration of our end - ProtocolMessage m(f.T); - m.proto = t; - m.introReply = p->intro; - m.sender = m_Identity.pub; - m.PutBuffer(data); - f.N.Randomize(); - f.S = GetSeqNoForConvo(f.T); - f.C.Zero(); - transfer.Y.Randomize(); - transfer.P = remoteIntro.pathID; - if(!f.EncryptAndSign(&Router()->crypto, m, K, m_Identity)) - { - llarp::LogError("failed to encrypt and sign"); - return false; + // TODO: check expiration of our end + ProtocolMessage m(f.T); + m.proto = t; + m.introReply = p->intro; + m.sender = m_Identity.pub; + m.PutBuffer(data); + f.N.Randomize(); + f.S = GetSeqNoForConvo(f.T); + f.C.Zero(); + transfer.Y.Randomize(); + transfer.P = remoteIntro.pathID; + if(!f.EncryptAndSign(&Router()->crypto, m, K, m_Identity)) + { + llarp::LogError("failed to encrypt and sign"); + return false; + } + llarp::LogInfo(Name(), " send ", data.sz, " via ", remoteIntro); + return p->SendRoutingMessage(&transfer, Router()); } - llarp::LogInfo(Name(), " send ", data.sz, " via ", remoteIntro); - return p->SendRoutingMessage(&transfer, Router()); } } if(HasPathToService(remote)) @@ -1242,7 +1240,7 @@ namespace llarp f.T = *tags.begin(); f.S = m_Endpoint->GetSeqNoForConvo(f.T); - auto path = m_PathSet->GetPathByRouter(remoteIntro.router); + auto path = m_PathSet->GetNewestPathByRouter(remoteIntro.router); if(!path) { llarp::LogError("cannot encrypt and send: no path for intro ",