From 965b0957ee4936b79c8cde611769ee5b2fa60c6f Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 31 Mar 2019 11:09:59 -0400 Subject: [PATCH] tweaks --- llarp/path/pathbuilder.cpp | 2 +- llarp/router/abstractrouter.hpp | 6 +++++ llarp/router/router.cpp | 43 +++++++++++++++++++++++++++------ llarp/router/router.hpp | 8 +++++- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 27eb5cf81..e819fab5a 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -345,7 +345,7 @@ namespace llarp static constexpr llarp_time_t MaxBuildInterval = 30 * 1000; buildIntervalLimit = std::min(1000 + buildIntervalLimit, MaxBuildInterval); - // router->routerProfiling().MarkPathFail(p); + router->routerProfiling().MarkPathFail(p); PathSet::HandlePathBuildTimeout(p); } diff --git a/llarp/router/abstractrouter.hpp b/llarp/router/abstractrouter.hpp index a159da4ea..3d8eee496 100644 --- a/llarp/router/abstractrouter.hpp +++ b/llarp/router/abstractrouter.hpp @@ -165,6 +165,12 @@ namespace llarp HandleDHTLookupForExplore(RouterID remote, const std::vector< RouterContact > &results) = 0; + /// lookup router by pubkey + /// if we are a service node this is done direct otherwise it's done via + /// path + virtual void + LookupRouter(RouterID remote) = 0; + /// check if newRc matches oldRC and update local rc for this remote contact /// if valid /// returns true on valid and updated diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 3834e5369..ea7c43c33 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -1027,6 +1027,23 @@ namespace llarp this, router, std::placeholders::_1)); } + void + Router::LookupRouter(RouterID remote) + { + if(IsServiceNode()) + { + ServiceNodeLookupRouterWhenExpired(remote); + return; + } + auto ep = hiddenServiceContext().getFirstEndpoint(); + if(ep == nullptr) + { + LogError("cannot lookup ", remote, " no service endpoints available"); + return; + } + ep->LookupRouterAnon(remote); + } + void Router::Tick() { @@ -1035,15 +1052,16 @@ namespace llarp routerProfiling().Tick(); - if(_rc.ExpiresSoon(now, randint() % 10000)) - { - LogInfo("regenerating RC"); - if(!UpdateOurRC(false)) - LogError("Failed to update our RC"); - } - if(IsServiceNode()) { + if(_rc.ExpiresSoon(now, randint() % 10000) + || (now - _rc.last_updated) > rcRegenInterval) + { + LogInfo("regenerating RC"); + if(!UpdateOurRC(false)) + LogError("Failed to update our RC"); + } + // only do this as service node // client endpoints do this on their own nodedb()->visit([&](const RouterContact &rc) -> bool { @@ -1053,9 +1071,18 @@ namespace llarp }); } // kill dead nodes + std::set< RouterID > removed; nodedb()->RemoveIf([&](const RouterContact &rc) -> bool { - return routerProfiling().IsBad(rc.pubkey); + if(!routerProfiling().IsBad(rc.pubkey)) + return false; + removed.insert(rc.pubkey); + return true; }); + + // request killed nodes 1 time + for(const auto &pk : removed) + LookupRouter(pk); + paths.TickPaths(now); paths.ExpirePaths(now); diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 67629e104..160f1c821 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -211,11 +211,14 @@ namespace llarp uint16_t m_OutboundPort = 0; /// always maintain this many connections to other routers - size_t minConnectedRouters = 3; + size_t minConnectedRouters = 2; /// hard upperbound limit on the number of router to router connections size_t maxConnectedRouters = 2000; size_t minRequiredRouters = 4; + /// how often do we resign our RC? milliseconds. + // TODO: make configurable + llarp_time_t rcRegenInterval = 60 * 60 * 1000; // should we be sending padded messages every interval? bool sendPadding = false; @@ -428,6 +431,9 @@ namespace llarp void FlushOutboundFor(RouterID remote, ILinkLayer *chosen = nullptr); + void + LookupRouter(RouterID remote) override; + /// manually discard all pending messages to remote router void DiscardOutboundFor(const RouterID &remote);