From 8a63533d1a5a817150649e440076859fe4e7a19f Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 25 Mar 2019 08:52:32 -0400 Subject: [PATCH] have service nodes maintain min connections path building more robust selection --- llarp/path/pathbuilder.cpp | 6 ++++-- llarp/router/router.cpp | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 770efe1bf..27eb5cf81 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -211,15 +211,17 @@ namespace llarp return router->NumberOfConnectedRouters() && router->GetRandomConnectedRouter(cur); - size_t tries = 10; + size_t tries = 10; + std::set< RouterID > exclude = {prev.pubkey}; do { cur.Clear(); --tries; - if(db->select_random_hop(prev, cur, hop)) + if(db->select_random_hop_excluding(cur, exclude)) { if(!router->routerProfiling().IsBad(cur.pubkey)) return true; + exclude.insert(cur.pubkey); } } while(tries > 0); return tries > 0; diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index cb71e7dbc..e4948f585 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -914,6 +914,24 @@ namespace llarp else llarp::LogError("invalid netid '", val, "', is too long"); } + if(StrEq(key, "max-connections")) + { + auto ival = atoi(val); + if(ival > 0) + { + maxConnectedRouters = ival; + LogInfo("max connections set to ", maxConnectedRouters); + } + } + if(StrEq(key, "min-connections")) + { + auto ival = atoi(val); + if(ival > 0) + { + minConnectedRouters = ival; + LogInfo("min connections set to ", minConnectedRouters); + } + } if(StrEq(key, "nickname")) { _rc.SetNick(val); @@ -1074,17 +1092,17 @@ namespace llarp LogError("we have no bootstrap nodes specified"); } - if(!IsServiceNode()) + const size_t connected = NumberOfConnectedRouters(); + if(connected < minConnectedRouters) { - size_t connected = NumberOfConnectedRouters(); - if(connected < minConnectedRouters) - { - size_t dlt = minConnectedRouters - connected; - LogInfo("connecting to ", dlt, " random routers to keep alive"); - ConnectToRandomRouters(dlt); - } - _hiddenServiceContext.Tick(now); + size_t dlt = minConnectedRouters - connected; + LogInfo("connecting to ", dlt, " random routers to keep alive"); + ConnectToRandomRouters(dlt); } + + if(!IsServiceNode()) + _hiddenServiceContext.Tick(now); + paths.BuildPaths(now); _exitContext.Tick(now); if(rpcCaller) @@ -1401,6 +1419,8 @@ namespace llarp } RouterID us = pubkey(); LogInfo("initalized service node: ", us); + if(minConnectedRouters < 6) + minConnectedRouters = 6; } else {