From 7852735b368fa26538ef73850a4d25a3dd91224e Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 2 Oct 2020 05:48:08 -0400 Subject: [PATCH 01/13] tweak configuration defaults --- llarp/config/config.cpp | 6 ++---- llarp/config/key_manager.cpp | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 777aa9ba5..50adbc06c 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -36,7 +36,6 @@ namespace llarp constexpr int DefaultWorkerThreads = 1; constexpr int DefaultNetThreads = 1; constexpr bool DefaultBlockBogons = true; - constexpr bool DefaultEnablePeerStats = true; conf.defineOption("router", "job-queue-size", false, DefaultJobQueueSize, [this](int arg) { if (arg < 1024) @@ -134,7 +133,7 @@ namespace llarp "router", "enable-peer-stats", false, - DefaultEnablePeerStats, + params.isRelay, AssignmentAcceptor(m_enablePeerStats)); m_isRelay = params.isRelay; } @@ -478,7 +477,6 @@ namespace llarp { (void)params; - constexpr bool DefaultWhitelistRouters = false; constexpr auto DefaultLokidRPCAddr = "tcp://127.0.0.1:22023"; conf.defineOption( @@ -491,7 +489,7 @@ namespace llarp }); conf.defineOption( - "lokid", "enabled", false, DefaultWhitelistRouters, AssignmentAcceptor(whitelistRouters)); + "lokid", "enabled", false, params.isRelay, AssignmentAcceptor(whitelistRouters)); conf.defineOption("lokid", "jsonrpc", false, "", [](std::string arg) { if (arg.empty()) diff --git a/llarp/config/key_manager.cpp b/llarp/config/key_manager.cpp index 5818db155..aebf41171 100644 --- a/llarp/config/key_manager.cpp +++ b/llarp/config/key_manager.cpp @@ -18,7 +18,7 @@ namespace llarp if (m_initialized) return false; - fs::path root = config.router.m_dataDir; + const fs::path root = config.router.m_dataDir; // utility function to assign a path, using the specified config parameter if present and // falling back to root / defaultName if not @@ -31,7 +31,7 @@ namespace llarp { fs::path file(option); if (not file.is_absolute()) - throw std::runtime_error(stringify("override for ", defaultName, " cannot be relative")); + file = root / file; return file; } From 503a92c992fabaaf6d599712d057c589da9a429e Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 2 Oct 2020 05:51:52 -0400 Subject: [PATCH 02/13] un limit lmq --- llarp/router/router.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 7cba6c818..8fb737ccb 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -66,7 +66,8 @@ namespace llarp , m_lokidRpcClient(std::make_shared(m_lmq, this)) { m_keyManager = std::make_shared(); - + // for lokid, so we don't close the connection when syncing the whitelist + m_lmq->MAX_MSG_SIZE = -1; _stopping.store(false); _running.store(false); _lastTick = llarp::time_now_ms(); From 3445716fceefeaffe9805e3038845440cd8aad74 Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 2 Oct 2020 06:16:01 -0400 Subject: [PATCH 03/13] update readme build info --- readme.md | 24 +++++++++++++----------- readme_es.md | 34 ++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/readme.md b/readme.md index de4d976a9..9f98746ca 100644 --- a/readme.md +++ b/readme.md @@ -62,7 +62,9 @@ Build requirements: * C++ 17 capable C++ compiler * libuv >= 1.27.0 * libsodium >= 1.0.18 -* gcovr (if generating test coverage with gcc) +* libunbound +* libzmq +* sqlite3 ### Linux @@ -71,9 +73,9 @@ build: $ sudo apt install build-essential cmake git libcap-dev curl libuv1-dev libsodium-dev pkg-config $ git clone --recursive https://github.com/loki-project/loki-network $ cd loki-network - $ mkdir build + $ mkdir build $ cd build - $ cmake .. + $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON $ make -j$(nproc) install: @@ -84,14 +86,14 @@ install: build: make sure you have cmake, libuv and xcode command line tools installed - + $ git clone --recursive https://github.com/loki-project/loki-network $ cd loki-network - $ mkdir build + $ mkdir build $ cd build - $ cmake .. + $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON $ make -j$(nproc) - + install: $ sudo make install @@ -106,16 +108,16 @@ additional build requirements: * cpack setup: - + $ sudo apt install build-essential cmake git pkg-config mingw-w64 nsis - + building: $ git clone --recursive https://github.com/loki-project/loki-network $ cd loki-network $ mkdir build-windows $ cd build-windows - $ cmake -DNATIVE_BUILD=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_PACKAGE=ON -DCMAKE_TOOLCHAIN_FILE='../contrib/cross/mingw64.cmake' -DWITH_TESTS=OFF -DCMAKE_CROSSCOMPILING=ON .. + $ cmake -DBUILD_STATIC_DEPS=ON -DNATIVE_BUILD=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_PACKAGE=ON -DCMAKE_TOOLCHAIN_FILE='../contrib/cross/mingw64.cmake' -DWITH_TESTS=OFF -DCMAKE_CROSSCOMPILING=ON .. $ cpack -D CPACK_MONOLITHIC_INSTALL=1 -G NSIS .. ### Solaris 2.10+ @@ -146,7 +148,7 @@ install: build: - $ pkg install cmake git curl libuv libsodium pkgconf + $ pkg install cmake git curl libuv libsodium pkgconf libunbound $ git clone --recursive https://github.com/loki-project/loki-network $ cd loki-network $ mkdir build diff --git a/readme_es.md b/readme_es.md index 94f03a2b7..39d549b79 100644 --- a/readme_es.md +++ b/readme_es.md @@ -67,20 +67,25 @@ Requerimientos de compilaciĆ³n: * GNU Make * CMake -* Compilador C++ que pueda usar C++ 17 +* Compilador C++ que pueda usar C++ 17 * gcovr (para generar la covertura de prueba en gcc) * libuv >= 1.27.0 * libsodium >= 1.0.18 -* libcurl +* libunbound +* libzmq +* sqlite3 ### Linux compilando: - $ sudo apt install build-essential cmake git libcap-dev curl libuv1-dev libsodium-dev - $ git clone https://github.com/loki-project/loki-network + $ sudo apt install build-essential cmake git libcap-dev curl libuv1-dev libsodium-dev pkg-config + $ git clone --recursive https://github.com/loki-project/loki-network $ cd loki-network - $ make + $ mkdir build + $ cd build + $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON + $ make instalando: @@ -97,9 +102,12 @@ esto coloca el paquete compilado en `../` compilando: este seguro que usted tiene cmake y las herramientas de terminal de xcode ya instaladas - + $ git clone https://github.com/loki-project/loki-network $ cd loki-network + $ mkdir build + $ cd build + $ cmake .. $ make -j8 instalando: @@ -159,9 +167,12 @@ PENDIENTE: agregar instrucciones para pkgsrc compilando: # pkg_add curl cmake git (opcional: ninja ccache) - $ git clone https://github.com/loki-project/loki-network + $ git clone --recursive https://github.com/loki-project/loki-network $ cd loki-network - $ gmake -j8 + $ mkdir build + $ cd build + $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON + $ make instalando (root): @@ -172,9 +183,12 @@ instalando (root): compilando: $ pkg install cmake git curl libuv-1.27.0 libsodium - $ git clone https://github.com/loki-project/loki-network + $ git clone --recursive https://github.com/loki-project/loki-network $ cd loki-network - $ gmake -j8 + $ mkdir build + $ cd build + $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON + $ make instalando (root): From 23302cd10c7786a28c180e56dbd4953f89291fbe Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Oct 2020 10:06:08 -0400 Subject: [PATCH 04/13] use size_left --- llarp/router_contact.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llarp/router_contact.cpp b/llarp/router_contact.cpp index 2fd810f92..33f88ac30 100644 --- a/llarp/router_contact.cpp +++ b/llarp/router_contact.cpp @@ -235,7 +235,7 @@ namespace llarp try { - std::string_view buf_view(reinterpret_cast(buf->cur), buf->sz); + std::string_view buf_view(reinterpret_cast(buf->cur), buf->size_left()); lokimq::bt_list_consumer btlist(buf_view); uint64_t outer_version = btlist.consume_integer(); @@ -266,7 +266,7 @@ namespace llarp bool RouterContact::DecodeVersion_0(llarp_buffer_t* buf) { - signed_bt_dict = std::string(reinterpret_cast(buf->cur), buf->sz); + signed_bt_dict = std::string(reinterpret_cast(buf->cur), buf->size_left()); return bencode_decode_dict(*this, buf); } From bb67b42f0b3898f360c4957c19ba807b9db8ca02 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Oct 2020 10:06:35 -0400 Subject: [PATCH 05/13] put pubkey_ed25519 in fields --- llarp/rpc/lokid_rpc_client.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llarp/rpc/lokid_rpc_client.cpp b/llarp/rpc/lokid_rpc_client.cpp index 98a97a868..27edff10d 100644 --- a/llarp/rpc/lokid_rpc_client.cpp +++ b/llarp/rpc/lokid_rpc_client.cpp @@ -67,8 +67,9 @@ namespace llarp void LokidRpcClient::UpdateServiceNodeList() { - nlohmann::json request; - request["pubkey_ed25519"] = true; + nlohmann::json request, fields; + fields["pubkey_ed25519"] = true; + request["fields"] = fields; request["active_only"] = true; if (not m_CurrentBlockHash.empty()) request["poll_block_hash"] = m_CurrentBlockHash; From 5b4b1f7aeedf16666e52ae27cb793aa731cb1e50 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Oct 2020 11:08:49 -0400 Subject: [PATCH 06/13] disable whitelist in unit test --- test/exit/test_llarp_exit_context.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/exit/test_llarp_exit_context.cpp b/test/exit/test_llarp_exit_context.cpp index b7546d39f..4cb2bbb2d 100644 --- a/test/exit/test_llarp_exit_context.cpp +++ b/test/exit/test_llarp_exit_context.cpp @@ -19,6 +19,7 @@ make_context() conf.bootstrap.skipBootstrap = true; conf.api.m_enableRPCServer = false; conf.router.m_enablePeerStats = true; + conf.lokid.whitelistRouters = false; conf.router.m_publicAddress = llarp::IpAddress("1.1.1.1"); // make a fake inbound link conf.links.m_InboundLinks.emplace_back(); From 79dfb6d3571ebb78d7a6cc9b8a90cc156f6e718a Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Oct 2020 11:09:13 -0400 Subject: [PATCH 07/13] kill lmq before stopping links/ --- llarp/router/router.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 8fb737ccb..aa943a62e 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -1119,6 +1119,7 @@ namespace llarp StopLinks(); nodedb()->AsyncFlushToDisk(); _logic->call_later(200ms, std::bind(&Router::AfterStopLinks, this)); + m_lmq.reset(); } void From c04cbfe34f5acd214d9c729b90884ac774146870 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Oct 2020 11:09:38 -0400 Subject: [PATCH 08/13] fix decode version 0 rc when in version 1 mode --- llarp/router_contact.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/llarp/router_contact.cpp b/llarp/router_contact.cpp index 33f88ac30..f31705900 100644 --- a/llarp/router_contact.cpp +++ b/llarp/router_contact.cpp @@ -266,8 +266,12 @@ namespace llarp bool RouterContact::DecodeVersion_0(llarp_buffer_t* buf) { - signed_bt_dict = std::string(reinterpret_cast(buf->cur), buf->size_left()); - return bencode_decode_dict(*this, buf); + auto begin = reinterpret_cast(buf->cur); + if (not bencode_decode_dict(*this, buf)) + return false; + auto end = reinterpret_cast(buf->cur); + signed_bt_dict = std::string(begin, std::distance(begin, end)); + return true; } bool From 4f3ed5d1c43bda46e622b3ce501853f0fc0f6be7 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Fri, 2 Oct 2020 11:41:21 -0400 Subject: [PATCH 09/13] remove unnecessary code the signed_bt_dict field is not used for a Version 0 RC anyway, so no need to handle it here. That was my bad. --- llarp/router_contact.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/llarp/router_contact.cpp b/llarp/router_contact.cpp index f31705900..bce459d1d 100644 --- a/llarp/router_contact.cpp +++ b/llarp/router_contact.cpp @@ -266,12 +266,7 @@ namespace llarp bool RouterContact::DecodeVersion_0(llarp_buffer_t* buf) { - auto begin = reinterpret_cast(buf->cur); - if (not bencode_decode_dict(*this, buf)) - return false; - auto end = reinterpret_cast(buf->cur); - signed_bt_dict = std::string(begin, std::distance(begin, end)); - return true; + return bencode_decode_dict(*this, buf); } bool From f79740531819ff3e8a9c76cf47f6ff735247f6bf Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 2 Oct 2020 14:11:39 -0400 Subject: [PATCH 10/13] ping lokid every 30 second after starting up --- llarp/rpc/lokid_rpc_client.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llarp/rpc/lokid_rpc_client.cpp b/llarp/rpc/lokid_rpc_client.cpp index 27edff10d..3b6417a84 100644 --- a/llarp/rpc/lokid_rpc_client.cpp +++ b/llarp/rpc/lokid_rpc_client.cpp @@ -101,7 +101,7 @@ namespace llarp void LokidRpcClient::Connected() { - constexpr auto PingInterval = 1min; + constexpr auto PingInterval = 30s; constexpr auto NodeListUpdateInterval = 30s; auto makePingRequest = [self = shared_from_this()]() { @@ -114,7 +114,6 @@ namespace llarp }, payload.dump()); }; - makePingRequest(); m_lokiMQ->add_timer(makePingRequest, PingInterval); m_lokiMQ->add_timer( [self = shared_from_this()]() { self->UpdateServiceNodeList(); }, NodeListUpdateInterval); From b121933374b2fa476e7c3f4e2fe828013460fcbc Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Fri, 2 Oct 2020 15:47:14 -0300 Subject: [PATCH 11/13] Make public-ip option work (#1380) 0.7 supported both public-address and public-ip, but only the former was being allowed in 0.8. This makes `public-ip=...` work again, and makes it the canonical option (because it makes a bit more sense than address when we also have the public-port parameter), while making `public-address=` accepted with a deprecation warning. Also adds default descriptions for port and ip for the generated ini. --- llarp/config/config.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 50adbc06c..d0b138181 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -80,12 +80,24 @@ namespace llarp m_dataDir = std::move(arg); }); - conf.defineOption("router", "public-address", false, "", [this](std::string arg) { + conf.defineOption("router", "public-ip", false, "", [this](std::string arg) { if (not arg.empty()) { llarp::LogInfo("public ip ", arg, " size ", arg.size()); - if (arg.size() > 16) + if (arg.size() > 15) + throw std::invalid_argument(stringify("Not a valid IPv4 addr: ", arg)); + + m_publicAddress.setAddress(arg); + } + }); + + conf.defineOption("router", "public-address", false, "", [this](std::string arg) { + if (not arg.empty()) + { + llarp::LogWarn("*** WARNING: The config option [router]:public-address=", arg, " is deprecated, use public-ip=", arg, " instead."); + + if (arg.size() > 15) throw std::invalid_argument(stringify("Not a valid IPv4 addr: ", arg)); m_publicAddress.setAddress(arg); @@ -767,6 +779,23 @@ namespace llarp "Maximum number (hard limit) of routers lokinet will be connected to at any time.", }); + def.addOptionComments( + "router", + "public-ip", + { + "For complex network configurations where the detected IP is incorrect or non-public", + "this setting specifies the public IP at which this router is reachable. When", + "provided the public-port option must also be specified." + }); + + def.addOptionComments( + "router", + "public-port", + { + "When specifying public-ip=, this specifies the public UDP port at which this lokinet", + "router is reachable. Required when public-ip is used.", + }); + // logging def.addSectionComments( "logging", From fbfa8ca89c64752f4615eb30bfa527042067e794 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Fri, 2 Oct 2020 16:50:20 -0300 Subject: [PATCH 12/13] make format (#1381) --- llarp/config/config.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index d0b138181..9a704eb42 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -95,7 +95,12 @@ namespace llarp conf.defineOption("router", "public-address", false, "", [this](std::string arg) { if (not arg.empty()) { - llarp::LogWarn("*** WARNING: The config option [router]:public-address=", arg, " is deprecated, use public-ip=", arg, " instead."); + llarp::LogWarn( + "*** WARNING: The config option [router]:public-address=", + arg, + " is deprecated, use public-ip=", + arg, + " instead."); if (arg.size() > 15) throw std::invalid_argument(stringify("Not a valid IPv4 addr: ", arg)); @@ -785,7 +790,7 @@ namespace llarp { "For complex network configurations where the detected IP is incorrect or non-public", "this setting specifies the public IP at which this router is reachable. When", - "provided the public-port option must also be specified." + "provided the public-port option must also be specified.", }); def.addOptionComments( From 0f7e8489033a19068d57fe57094e99c05a669609 Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 2 Oct 2020 16:54:31 -0400 Subject: [PATCH 13/13] disable rpc on relays by default (#1383) * disable rpc on relays by default * add default inbound link as service node * throw if public-ip and public-port are not set --- llarp/config/config.cpp | 5 +---- llarp/router/router.cpp | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 9a704eb42..af280bf45 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -464,13 +464,10 @@ namespace llarp void ApiConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params) { - (void)params; - - constexpr bool DefaultRPCEnabled = true; constexpr auto DefaultRPCBindAddr = "tcp://127.0.0.1:1190"; conf.defineOption( - "api", "enabled", false, DefaultRPCEnabled, AssignmentAcceptor(m_enableRPCServer)); + "api", "enabled", false, not params.isRelay, AssignmentAcceptor(m_enableRPCServer)); conf.defineOption( "api", "bind", false, DefaultRPCBindAddr, [this](std::string arg) { diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index aa943a62e..f7c15b5c3 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -568,8 +568,22 @@ namespace llarp whitelistRouters, m_isServiceNode); + std::vector inboundLinks = conf.links.m_InboundLinks; + + if (inboundLinks.empty() and m_isServiceNode) + { + const auto& publicAddr = conf.router.m_publicAddress; + if (publicAddr.isEmpty() or not publicAddr.hasPort()) + { + throw std::runtime_error( + "service node enabled but could not find a public IP to bind to; you need to set the " + "public-ip= and public-port= options"); + } + inboundLinks.push_back(LinksConfig::LinkInfo{"0.0.0.0", AF_INET, *publicAddr.getPort()}); + } + // create inbound links, if we are a service node - for (const LinksConfig::LinkInfo& serverConfig : conf.links.m_InboundLinks) + for (const LinksConfig::LinkInfo& serverConfig : inboundLinks) { auto server = iwp::NewInboundLink( m_keyManager, @@ -594,11 +608,6 @@ namespace llarp _linkManager.AddLink(std::move(server), true); } - if (conf.links.m_InboundLinks.empty() and m_isServiceNode) - { - throw std::runtime_error("service node enabled but have no inbound links"); - } - // Network config if (conf.network.m_enableProfiling.has_value() and not*conf.network.m_enableProfiling) {