From 94912ba21bee2705cf5f6f8ea56e507e2b1d61d3 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 29 Jun 2021 12:17:33 -0400 Subject: [PATCH 01/32] fix up docs generation --- docs/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 679e413fe..c7b8a4fd5 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -4,7 +4,7 @@ if (NOT DOXYGEN) return() endif() find_program(SPHINX_BUILD sphinx-build) -if (NOT DOXYGEN) +if (NOT SPHINX_BUILD) message(STATUS "Documentation generation disabled (sphinx-build not found)") return() endif() @@ -22,7 +22,7 @@ add_custom_command( add_custom_command( OUTPUT html/index.html - COMMAND ${SPHINX_BUILD} + COMMAND ${SPHINX_BUILD} -j auto -Dbreathe_projects.lokinet=${CMAKE_CURRENT_BINARY_DIR}/doxyxml -Dversion=${lokinet_VERSION} -Drelease=${lokinet_VERSION} -Aversion=${lokinet_VERSION} -Aversions=${lokinet_VERSION_MAJOR},${lokinet_VERSION_MINOR},${lokinet_VERSION_PATCH} From 4f712769287edf9f57b047b508126aa4cf37599e Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Tue, 29 Jun 2021 16:00:14 -0300 Subject: [PATCH 02/32] Link to jemalloc for better memory usage --- CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea2651591..7ce5bb845 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -302,6 +302,19 @@ endif() add_subdirectory(external) include_directories(SYSTEM external/sqlite_orm/include) +option(USE_JEMALLOC "Link to jemalloc for memory allocations, if found" ON) +if(USE_JEMALLOC AND NOT STATIC_LINK) + pkg_check_modules(JEMALLOC jemalloc IMPORTED_TARGET) + if(JEMALLOC_FOUND) + target_link_libraries(base_libs INTERFACE PkgConfig::JEMALLOC) + else() + message(STATUS "jemalloc not found, not linking to jemalloc") + endif() +else() + message(STATUS "jemalloc support disabled") +endif() + + if(ANDROID) target_link_libraries(base_libs INTERFACE log) target_compile_definitions(base_libs INTERFACE ANDROID) From 8515fe09d41e1819dbd3ba27eaf7f84ffee412ae Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Tue, 29 Jun 2021 18:44:42 -0400 Subject: [PATCH 03/32] fix minor oversight/inefficiency with already established connections --- llarp/router/outbound_session_maker.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/llarp/router/outbound_session_maker.cpp b/llarp/router/outbound_session_maker.cpp index 9c8f64453..96bbd5b95 100644 --- a/llarp/router/outbound_session_maker.cpp +++ b/llarp/router/outbound_session_maker.cpp @@ -80,6 +80,14 @@ namespace llarp CreatePendingSession(router); + // short-circuit to success callback if we already have an outbound session + // to the remote + if (_linkManager->HasOutboundSessionTo(router)) + { + FinalizeRequest(router, SessionResult::Establish); + return; + } + LogDebug("Creating session establish attempt to ", router, " ."); auto fn = util::memFn(&OutboundSessionMaker::OnRouterContactResult, this); @@ -104,6 +112,14 @@ namespace llarp CreatePendingSession(rc.pubkey); } + // short-circuit to success callback if we already have an outbound session + // to the remote + if (_linkManager->HasOutboundSessionTo(router)) + { + FinalizeRequest(router, SessionResult::Establish); + return; + } + GotRouterContact(rc.pubkey, rc); } From e78d0b5e77e42d8a52c13833a35120046d6bb41d Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 30 Jun 2021 05:46:03 -0400 Subject: [PATCH 04/32] update urls --- readme.md | 22 +++++++++++----------- readme_es.md | 30 +++++++++++++++--------------- readme_ru.md | 24 ++++++++++++------------ 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/readme.md b/readme.md index a1620ac89..69ddd90c4 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,7 @@ You can view documentation on how to get started [here](https://docs.oxen.io/pro A simple demo application that is lokinet "aware" can be found [here](https://github.com/majestrate/lokinet-aware-demos) -[![Build Status](https://ci.oxen.rocks/api/badges/oxen-io/loki-network/status.svg?ref=refs/heads/dev)](https://ci.oxen.rocks/oxen-io/loki-network) +[![Build Status](https://ci.oxen.rocks/api/badges/oxen-io/lokinet/status.svg?ref=refs/heads/dev)](https://ci.oxen.rocks/oxen-io/lokinet) ## Building @@ -43,8 +43,8 @@ You can install these using: If you are not on a platform supported by the debian packages or if you want to build a dev build, this is the most "portable" way to do it: $ sudo apt install build-essential cmake git libcap-dev pkg-config automake libtool - $ git clone --recursive https://github.com/loki-project/loki-network - $ cd loki-network + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build $ cd build $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON @@ -60,8 +60,8 @@ You can get the latest stable macos relase from https://lokinet.org/ or check th alternatively you can build from source, 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 + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build $ cd build $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON @@ -88,8 +88,8 @@ setup: building: - $ git clone --recursive https://github.com/loki-project/loki-network - $ cd loki-network + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ ./contrib/windows.sh ### Solaris 2.10+ @@ -105,8 +105,8 @@ build: $ sudo pkg install build-essential gcc8 wget tuntap cmake (optional: ninja ccache - from omnios extra) (OmniOS CE) $ sudo pkg install base-developer-utilities developer-gnu developer-studio-utilities gcc-7 wget cmake (Oracle Solaris, see note) $ sudo pkg install build-essential wget gcc-8 documentation/tuntap header-tun tun (optional: ninja ccache) (all other SunOS) - $ git clone --recursive https://github.com/loki-project/loki-network - $ cd loki-network + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build $ cd build $ cmake .. @@ -121,8 +121,8 @@ install: build: $ pkg install cmake git pkgconf - $ git clone --recursive https://github.com/loki-project/loki-network - $ cd loki-network + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build $ cd build $ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON -DBUILD_SHARED_DEPS=ON .. diff --git a/readme_es.md b/readme_es.md index 5225316e4..f71dee8f8 100644 --- a/readme_es.md +++ b/readme_es.md @@ -8,10 +8,10 @@ Puede aprender a grandes razgos sobre el diseño de LLARP [aquí](docs/high-leve Y puede leer las especificaciones del protocolo [aquí](docs/proto_v0.txt) , documento técnico en idioma ingles. -Puede ver la documentación, en ingles, de como empezar [aqui](https://loki-project.github.io/loki-docs/Lokinet/LokinetOverview/) . +Puede ver la documentación, en ingles, de como empezar [aqui](https://oxen-io.github.io/loki-docs/Lokinet/LokinetOverview/) . + +[![Build Status](https://ci.oxen.rocks/api/badges/oxen-io/lokinet/status.svg?ref=refs/heads/dev)](https://ci.oxen.rocks/oxen-io/lokinet) -![build status](https://gitlab.com/lokiproject/loki-network/badges/master/pipeline.svg "build status") -![travis-ci](https://travis-ci.org/loki-project/loki-network.svg?branch=master "ci status") ## Uso @@ -80,8 +80,8 @@ Requerimientos de compilación: compilando: $ 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 + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build $ cd build $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON @@ -103,8 +103,8 @@ esto coloca el paquete compilado en `../` compilando: este seguro que usted tiene cmake, libuv y las herramientas de terminal de xcode ya instaladas - $ git clone --recursive https://github.com/loki-project/loki-network - $ cd loki-network + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build $ cd build $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON @@ -119,8 +119,8 @@ instalando: compilar (donde `$ARCH` es su plataforma - `i686` or `x86_64`): $ pacman -Sy base-devel mingw-w64-$ARCH-toolchain git libtool autoconf mingw-w64-$ARCH-cmake - $ git clone https://github.com/loki-project/loki-network.git - $ cd loki-network + $ git clone https://github.com/oxen-io/lokinet.git + $ cd lokinet $ mkdir -p build; cd build $ cmake .. -DCMAKE_BUILD_TYPE=[Debug|Release] -DSTATIC_LINK_RUNTIME=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -G 'Unix Makefiles' @@ -149,8 +149,8 @@ compilando: $ sudo pkg install build-essential gcc8 wget tuntap cmake (opcional: ninja ccache - de los extra de omnios) (OmniOS CE) $ sudo pkg install base-developer-utilities developer-gnu developer-studio-utilities gcc-7 wget cmake (Solaris de Oracle, ver notas) $ sudo pkg install build-essential wget gcc-8 documentation/tuntap header-tun tun (opcional: ninja ccache) (todos los demas SunOS) - $ git clone https://github.com/loki-project/loki-network - $ cd loki-network + $ git clone https://github.com/oxen-io/lokinet + $ cd lokinet $ gmake -j8 instalando: @@ -167,8 +167,8 @@ PENDIENTE: agregar instrucciones para pkgsrc compilando: # pkg_add curl cmake git (opcional: ninja ccache) - $ git clone --recursive https://github.com/loki-project/loki-network - $ cd loki-network + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build $ cd build $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON @@ -183,8 +183,8 @@ instalando (root): compilando: $ pkg install cmake git curl libuv-1.27.0 libsodium - $ git clone --recursive https://github.com/loki-project/loki-network - $ cd loki-network + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build $ cd build $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON diff --git a/readme_ru.md b/readme_ru.md index 5f88c2577..73652328d 100644 --- a/readme_ru.md +++ b/readme_ru.md @@ -8,9 +8,9 @@ Lokinet - реализация LLARP (протокол анонимной мар Почитать спецификацию протокола LLARP [здесь](docs/proto_v0.txt) -Почитать документацию о том, как начать работу [здесь](https://loki-project.github.io/loki-docs/Lokinet/LokinetOverview/) +Почитать документацию о том, как начать работу [здесь](https://oxen-io.github.io/loki-docs/Lokinet/LokinetOverview/) -[![Build Status](https://drone.lokinet.dev/api/badges/loki-project/loki-network/status.svg?ref=refs/heads/master)](https://drone.lokinet.dev/loki-project/loki-network) +[![Build Status](https://drone.lokinet.dev/api/badges/oxen-io/lokinet/status.svg?ref=refs/heads/master)](https://drone.lokinet.dev/oxen-io/lokinet) ## Использование @@ -71,8 +71,8 @@ Lokinet - реализация LLARP (протокол анонимной мар сборка: $ 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 + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build $ cd build $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON @@ -87,8 +87,8 @@ Lokinet - реализация LLARP (протокол анонимной мар сборка: убедитесь, что у вас установлены инструменты командной строки cmake, libuv и xcode - $ git clone --recursive https://github.com/loki-project/loki-network - $ cd loki-network + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build $ cd build $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON @@ -113,8 +113,8 @@ Lokinet - реализация LLARP (протокол анонимной мар сборка: - $ git clone --recursive https://github.com/loki-project/loki-network - $ cd loki-network + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build-windows $ cd build-windows $ 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 .. @@ -133,8 +133,8 @@ Lokinet - реализация LLARP (протокол анонимной мар $ sudo pkg install build-essential gcc8 wget tuntap cmake (optional: ninja ccache - from omnios extra) (OmniOS CE) $ sudo pkg install base-developer-utilities developer-gnu developer-studio-utilities gcc-7 wget cmake (Oracle Solaris, see note) $ sudo pkg install build-essential wget gcc-8 documentation/tuntap header-tun tun (optional: ninja ccache) (all other SunOS) - $ git clone --recursive https://github.com/loki-project/loki-network - $ cd loki-network + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build $ cd build $ cmake .. @@ -149,8 +149,8 @@ Lokinet - реализация LLARP (протокол анонимной мар сборка: $ pkg install cmake git curl libuv libsodium pkgconf libunbound - $ git clone --recursive https://github.com/loki-project/loki-network - $ cd loki-network + $ git clone --recursive https://github.com/oxen-io/lokinet + $ cd lokinet $ mkdir build $ cmake -DCMAKE_BUILD_TYPE=Release .. $ make From f4fa83703f59402781e9f58cf847778260f023c6 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 30 Jun 2021 06:45:11 -0400 Subject: [PATCH 05/32] refactor to use RouterID instead of rc.pubkey --- llarp/router/outbound_session_maker.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/llarp/router/outbound_session_maker.cpp b/llarp/router/outbound_session_maker.cpp index 96bbd5b95..d2d66d1a2 100644 --- a/llarp/router/outbound_session_maker.cpp +++ b/llarp/router/outbound_session_maker.cpp @@ -98,18 +98,20 @@ namespace llarp void OutboundSessionMaker::CreateSessionTo(const RouterContact& rc, RouterCallback on_result) { + const RouterID router{rc.pubkey}; + if (on_result) { util::Lock l(_mutex); - auto itr_pair = pendingCallbacks.emplace(rc.pubkey, CallbacksQueue{}); + auto itr_pair = pendingCallbacks.emplace(router, CallbacksQueue{}); itr_pair.first->second.push_back(on_result); } - if (not HavePendingSessionTo(rc.pubkey)) + if (not HavePendingSessionTo(router)) { - LogDebug("Creating session establish attempt to ", rc.pubkey, " ."); - CreatePendingSession(rc.pubkey); + LogDebug("Creating session establish attempt to ", router); + CreatePendingSession(router); } // short-circuit to success callback if we already have an outbound session @@ -120,7 +122,7 @@ namespace llarp return; } - GotRouterContact(rc.pubkey, rc); + GotRouterContact(router, rc); } bool From da985c4c44342424450b7d033f02fdec3b31948e Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 19 Apr 2021 13:22:47 -0400 Subject: [PATCH 06/32] add docker image for nodejs --- contrib/ci/docker/nodejs.dockerfile | 3 +++ contrib/ci/docker/rebuild-docker-images.sh | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 contrib/ci/docker/nodejs.dockerfile diff --git a/contrib/ci/docker/nodejs.dockerfile b/contrib/ci/docker/nodejs.dockerfile new file mode 100644 index 000000000..9099a61b9 --- /dev/null +++ b/contrib/ci/docker/nodejs.dockerfile @@ -0,0 +1,3 @@ +FROM node:14.16.1 +RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections' +RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 -q install -y eatmydata gdb cmake git ninja-build pkg-config ccache g++' diff --git a/contrib/ci/docker/rebuild-docker-images.sh b/contrib/ci/docker/rebuild-docker-images.sh index b86fc655b..959643cef 100755 --- a/contrib/ci/docker/rebuild-docker-images.sh +++ b/contrib/ci/docker/rebuild-docker-images.sh @@ -8,6 +8,6 @@ test "x$registry" != "x" || exit 1 for file in ${@:2} ; do name="$(echo $file | cut -d'.' -f1)" echo "rebuild $name" - docker build -f $file -t $registry/lokinet-ci-$name --pull --no-cache --quiet . + docker build -f $file -t $registry/lokinet-ci-$name . docker push $registry/lokinet-ci-$name done From a316f5f7878d1e197e0c91feee7108272f07a34d Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 19 Apr 2021 13:38:56 -0400 Subject: [PATCH 07/32] add wine as dependancy because god made windows so that man may suffer --- contrib/ci/docker/nodejs.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/ci/docker/nodejs.dockerfile b/contrib/ci/docker/nodejs.dockerfile index 9099a61b9..059d16a6f 100644 --- a/contrib/ci/docker/nodejs.dockerfile +++ b/contrib/ci/docker/nodejs.dockerfile @@ -1,3 +1,3 @@ FROM node:14.16.1 RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections' -RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 -q install -y eatmydata gdb cmake git ninja-build pkg-config ccache g++' +RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 -q install -y eatmydata gdb cmake git ninja-build pkg-config ccache g++ wine' From cf0349c25905e7340312443ccf421a4965892984 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 30 Jun 2021 16:42:10 -0400 Subject: [PATCH 08/32] if we have an inbound session don't fail with NoLink --- llarp/router/outbound_session_maker.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/llarp/router/outbound_session_maker.cpp b/llarp/router/outbound_session_maker.cpp index d2d66d1a2..b7a8fa412 100644 --- a/llarp/router/outbound_session_maker.cpp +++ b/llarp/router/outbound_session_maker.cpp @@ -259,16 +259,18 @@ namespace llarp { if (router == us or not _rcLookup->SessionIsAllowed(router)) return false; + if (_linkManager->HasSessionTo(router)) + return false; + if (_router->IsServiceNode()) + return true; + size_t numPending = 0; { util::Lock lock(_mutex); if (pendingSessions.find(router) == pendingSessions.end()) numPending += pendingSessions.size(); } - if (_linkManager->HasOutboundSessionTo(router)) - return false; - if (_router->IsServiceNode()) - return true; + return _linkManager->NumberOfConnectedRouters() + numPending < maxConnectedRouters; } From 99379c5defcf45865369cb540520aa17b006ddf4 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 30 Jun 2021 16:48:30 -0400 Subject: [PATCH 09/32] establish outbound sessions when we have no outbound session. when we have an inbound session we still want to make an outbound session. --- llarp/router/outbound_session_maker.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/llarp/router/outbound_session_maker.cpp b/llarp/router/outbound_session_maker.cpp index b7a8fa412..fbcc903df 100644 --- a/llarp/router/outbound_session_maker.cpp +++ b/llarp/router/outbound_session_maker.cpp @@ -244,10 +244,6 @@ namespace llarp { _loop->call([this, router] { DoEstablish(router); }); } - else if (_linkManager->HasSessionTo(router)) - { - FinalizeRequest(router, SessionResult::Establish); - } else { FinalizeRequest(router, SessionResult::NoLink); @@ -259,7 +255,7 @@ namespace llarp { if (router == us or not _rcLookup->SessionIsAllowed(router)) return false; - if (_linkManager->HasSessionTo(router)) + if (_linkManager->HasOutboundSessionTo(router)) return false; if (_router->IsServiceNode()) return true; From 977ea3d689758ba00bb9f2c7ea0f8faac9963818 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 1 Jul 2021 08:14:43 -0400 Subject: [PATCH 10/32] * add log warn * throw if inbound link makes outbound session --- llarp/iwp/linklayer.cpp | 17 +++++++++-------- llarp/iwp/linklayer.hpp | 2 +- llarp/link/server.cpp | 25 +++++++++++++------------ 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/llarp/iwp/linklayer.cpp b/llarp/iwp/linklayer.cpp index 527510d8e..6eae44bcc 100644 --- a/llarp/iwp/linklayer.cpp +++ b/llarp/iwp/linklayer.cpp @@ -24,7 +24,7 @@ namespace llarp::iwp keyManager, getrc, h, sign, before, est, reneg, timeout, closed, pumpDone, worker) , m_Wakeup{ev->make_waker([this]() { HandleWakeupPlaintext(); })} , m_PlaintextRecv{1024} - , permitInbound{allowInbound} + , m_Inbound{allowInbound} {} @@ -48,10 +48,10 @@ namespace llarp::iwp bool isNewSession = false; if (itr == m_AuthedAddrs.end()) { - Lock_t lock(m_PendingMutex); + Lock_t lock{m_PendingMutex}; if (m_Pending.count(from) == 0) { - if (not permitInbound) + if (not m_Inbound) return; isNewSession = true; m_Pending.insert({from, std::make_shared(this, from)}); @@ -60,14 +60,13 @@ namespace llarp::iwp } else { - Lock_t lock(m_AuthedLinksMutex); - auto range = m_AuthedLinks.equal_range(itr->second); - session = range.first->second; + if(auto s_itr = m_AuthedLinks.find(itr->second); s_itr != m_AuthedLinks.end()) + session = s_itr->second; } if (session) { bool success = session->Recv_LL(std::move(pkt)); - if (!success and isNewSession) + if (not success and isNewSession) { LogWarn("Brand new session failed; removing from pending sessions list"); m_Pending.erase(m_Pending.find(from)); @@ -78,7 +77,7 @@ namespace llarp::iwp bool LinkLayer::MapAddr(const RouterID& r, ILinkSession* s) { - if (!ILinkLayer::MapAddr(r, s)) + if (not ILinkLayer::MapAddr(r, s)) return false; m_AuthedAddrs.emplace(s->GetRemoteEndpoint(), r); return true; @@ -93,6 +92,8 @@ namespace llarp::iwp std::shared_ptr LinkLayer::NewOutboundSession(const RouterContact& rc, const AddressInfo& ai) { + if(m_Inbound) + throw std::logic_error{"inbound link cannot make outbound sessions"}; return std::make_shared(this, rc, ai); } diff --git a/llarp/iwp/linklayer.hpp b/llarp/iwp/linklayer.hpp index 52d81ee2e..12fa07ab5 100644 --- a/llarp/iwp/linklayer.hpp +++ b/llarp/iwp/linklayer.hpp @@ -63,7 +63,7 @@ namespace llarp::iwp const std::shared_ptr m_Wakeup; std::unordered_map> m_PlaintextRecv; std::unordered_map m_AuthedAddrs; - const bool permitInbound; + const bool m_Inbound; }; using LinkLayer_ptr = std::shared_ptr; diff --git a/llarp/link/server.cpp b/llarp/link/server.cpp index b8c9f748f..23658dfe1 100644 --- a/llarp/link/server.cpp +++ b/llarp/link/server.cpp @@ -12,8 +12,6 @@ static constexpr auto LINK_LAYER_TICK_INTERVAL = 100ms; namespace llarp { - static constexpr size_t MaxSessionsPerKey = 16; - ILinkLayer::ILinkLayer( std::shared_ptr keyManager, GetRCFunc getrc, @@ -241,7 +239,7 @@ namespace llarp auto itr = m_Pending.find(addr); if (itr != m_Pending.end()) { - if (m_AuthedLinks.count(pk) > MaxSessionsPerKey) + if (m_AuthedLinks.count(pk)) { LogWarn("too many session for ", pk); s->Close(); @@ -303,21 +301,24 @@ namespace llarp { { Lock_t l(m_AuthedLinksMutex); - if (m_AuthedLinks.count(rc.pubkey) >= MaxSessionsPerKey) + if (m_AuthedLinks.count(rc.pubkey)) { - LogDebug("Too many links to ", RouterID{rc.pubkey}, ", not establishing another one"); + LogWarn("Too many links to ", RouterID{rc.pubkey}, ", not establishing another one"); return false; } } llarp::AddressInfo to; - if (!PickAddress(rc, to)) + if (not PickAddress(rc, to)) + { + LogWarn("router ", RouterID{rc.pubkey}, " has no acceptable inbound addresses"); return false; + } const SockAddr address{to}; { Lock_t l(m_PendingMutex); - if (m_Pending.count(address) >= MaxSessionsPerKey) + if (m_Pending.count(address)) { - LogDebug( + LogWarn( "Too many pending connections to ", address, " while establishing to ", @@ -331,12 +332,12 @@ namespace llarp { BeforeConnect(std::move(rc)); } - if (PutSession(s)) + if (not PutSession(s)) { - s->Start(); - return true; + return false; } - return false; + s->Start(); + return true; } bool From caddeef2e8b30ac16d412a77e67a556ab12a3845 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 1 Jul 2021 08:30:29 -0400 Subject: [PATCH 11/32] more information in logs --- llarp/iwp/linklayer.cpp | 13 +++++++++++-- llarp/iwp/linklayer.hpp | 3 +++ llarp/iwp/session.cpp | 23 ++++++++++++++--------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/llarp/iwp/linklayer.cpp b/llarp/iwp/linklayer.cpp index 6eae44bcc..d3c10c218 100644 --- a/llarp/iwp/linklayer.cpp +++ b/llarp/iwp/linklayer.cpp @@ -34,6 +34,15 @@ namespace llarp::iwp return "iwp"; } + std::string + LinkLayer::PrintableName() const + { + if (m_Inbound) + return "inbound iwp link"; + else + return "outbound iwp link"; + } + uint16_t LinkLayer::Rank() const { @@ -60,7 +69,7 @@ namespace llarp::iwp } else { - if(auto s_itr = m_AuthedLinks.find(itr->second); s_itr != m_AuthedLinks.end()) + if (auto s_itr = m_AuthedLinks.find(itr->second); s_itr != m_AuthedLinks.end()) session = s_itr->second; } if (session) @@ -92,7 +101,7 @@ namespace llarp::iwp std::shared_ptr LinkLayer::NewOutboundSession(const RouterContact& rc, const AddressInfo& ai) { - if(m_Inbound) + if (m_Inbound) throw std::logic_error{"inbound link cannot make outbound sessions"}; return std::make_shared(this, rc, ai); } diff --git a/llarp/iwp/linklayer.hpp b/llarp/iwp/linklayer.hpp index 12fa07ab5..0ebb4d8aa 100644 --- a/llarp/iwp/linklayer.hpp +++ b/llarp/iwp/linklayer.hpp @@ -56,6 +56,9 @@ namespace llarp::iwp void AddWakeup(std::weak_ptr peer); + std::string + PrintableName() const; + private: void HandleWakeupPlaintext(); diff --git a/llarp/iwp/session.cpp b/llarp/iwp/session.cpp index a84125851..9ea1a24e0 100644 --- a/llarp/iwp/session.cpp +++ b/llarp/iwp/session.cpp @@ -91,6 +91,7 @@ namespace llarp LogError("ident key mismatch"); return false; } + m_RemoteRC = msg->rc; GotLIM = util::memFn(&Session::GotRenegLIM, this); auto self = shared_from_this(); @@ -171,7 +172,7 @@ namespace llarp m_Parent->UnmapAddr(m_RemoteAddr); m_State = State::Closed; EncryptAndSend(std::move(close_msg)); - LogInfo("closing connection to ", m_RemoteAddr); + LogInfo(m_Parent->PrintableName(), " closing connection to ", m_RemoteAddr); } bool @@ -448,13 +449,15 @@ namespace llarp { if (not DecryptMessageInPlace(pkt)) { - LogError("failed to decrypt session request from ", m_RemoteAddr); + LogError( + m_Parent->PrintableName(), " failed to decrypt session request from ", m_RemoteAddr); return; } if (pkt.size() < token.size() + PacketOverhead) { LogError( - "bad session request size, ", + m_Parent->PrintableName(), + " bad session request size, ", pkt.size(), " < ", token.size() + PacketOverhead, @@ -465,7 +468,7 @@ namespace llarp const auto begin = pkt.data() + PacketOverhead; if (not std::equal(begin, begin + token.size(), token.data())) { - LogError("token mismatch from ", m_RemoteAddr); + LogError(m_Parent->PrintableName(), " token mismatch from ", m_RemoteAddr); return; } m_LastRX = m_Parent->Now(); @@ -478,7 +481,7 @@ namespace llarp { if (pkt.size() < (Introduction::SIZE + PacketOverhead)) { - LogWarn("intro too small from ", m_RemoteAddr); + LogWarn(m_Parent->PrintableName(), " intro too small from ", m_RemoteAddr); return; } byte_t* ptr = pkt.data() + PacketOverhead; @@ -495,7 +498,7 @@ namespace llarp pkt.data() + PacketOverhead, Introduction::SIZE - Signature::SIZE); if (!CryptoManager::instance()->verify(m_ExpectedIdent, verifybuf, Z)) { - LogError("intro verify failed from ", m_RemoteAddr); + LogError(m_Parent->PrintableName(), " intro verify failed from ", m_RemoteAddr); return; } const PubKey pk = m_Parent->TransportSecretKey().toPublic(); @@ -529,7 +532,8 @@ namespace llarp if (pkt.size() < (token.size() + PacketOverhead)) { LogError( - "bad intro ack size ", + m_Parent->PrintableName(), + " bad intro ack size ", pkt.size(), " < ", token.size() + PacketOverhead, @@ -540,7 +544,7 @@ namespace llarp Packet_t reply(token.size() + PacketOverhead); if (not DecryptMessageInPlace(pkt)) { - LogError("intro ack decrypt failed from ", m_RemoteAddr); + LogError(m_Parent->PrintableName(), " intro ack decrypt failed from ", m_RemoteAddr); return; } m_LastRX = m_Parent->Now(); @@ -575,7 +579,8 @@ namespace llarp if (H != expected) { LogError( - "keyed hash mismatch ", + m_Parent->PrintableName(), + " keyed hash mismatch ", H, " != ", expected, From 20bc338eba54b000aa3f4881209ffc66d745bfe9 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 1 Jul 2021 08:42:46 -0400 Subject: [PATCH 12/32] inbound sessions from CLIENTS should only have an elevated lifetime --- llarp/iwp/session.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llarp/iwp/session.cpp b/llarp/iwp/session.cpp index 9ea1a24e0..d9388325c 100644 --- a/llarp/iwp/session.cpp +++ b/llarp/iwp/session.cpp @@ -331,7 +331,9 @@ namespace llarp if (m_State == State::Ready || m_State == State::LinkIntro) { return now > m_LastRX - && now - m_LastRX > (m_Inbound ? DefaultLinkSessionLifetime : SessionAliveTimeout); + && now - m_LastRX + > (m_Inbound and not m_RemoteRC.IsPublicRouter() ? DefaultLinkSessionLifetime + : SessionAliveTimeout); } return now - m_CreatedAt >= LinkLayerConnectTimeout; } From 2578983a092d554c84f2b5364c6dc6d85db13ec8 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 1 Jul 2021 09:34:49 -0400 Subject: [PATCH 13/32] dont give peer stats in rpc --- llarp/router/router.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index f5b92df3d..1d5690c0a 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -83,10 +83,6 @@ namespace llarp { if (_running) { - util::StatusObject peerStatsObj = nullptr; - if (m_peerDb) - peerStatsObj = m_peerDb->ExtractStatus(); - return util::StatusObject{ {"running", true}, {"numNodesKnown", _nodedb->NumLoaded()}, @@ -94,8 +90,7 @@ namespace llarp {"services", _hiddenServiceContext.ExtractStatus()}, {"exit", _exitContext.ExtractStatus()}, {"links", _linkManager.ExtractStatus()}, - {"outboundMessages", _outboundMessageHandler.ExtractStatus()}, - {"peerStats", peerStatsObj}}; + {"outboundMessages", _outboundMessageHandler.ExtractStatus()}}; } else { From 1d1d97b0ef09029e7909d6359af9ab3b8923911a Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 1 Jul 2021 09:35:50 -0400 Subject: [PATCH 14/32] disable peer status entirely --- llarp/router/router.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 1d5690c0a..c657779b6 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -674,14 +674,6 @@ namespace llarp hiddenServiceContext().AddEndpoint(conf); } - // peer stats - if (IsServiceNode()) - { - LogInfo("Initializing peerdb..."); - m_peerDb = std::make_shared(); - m_peerDb->configure(conf.router); - } - // Logging config LogContext::Instance().Initialize( conf.logging.m_logLevel, From e3281cd0261ec21068b1de09fb092aea3cd50568 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 1 Jul 2021 12:10:26 -0400 Subject: [PATCH 15/32] add string representation to SessionResult --- llarp/router/i_outbound_session_maker.hpp | 19 +++++++++++++++++++ llarp/router/router.cpp | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/llarp/router/i_outbound_session_maker.hpp b/llarp/router/i_outbound_session_maker.hpp index 5cd1ed8f5..cc57cafea 100644 --- a/llarp/router/i_outbound_session_maker.hpp +++ b/llarp/router/i_outbound_session_maker.hpp @@ -20,6 +20,25 @@ namespace llarp NoLink }; + inline std::ostream& + operator<<(std::ostream& out, const SessionResult& st) + { + switch (st) + { + case SessionResult::Establish: + return out << "success"; + case SessionResult::Timeout: + return out << "timeout"; + case SessionResult::NoLink: + return out << "no link"; + case SessionResult::InvalidRouter: + return out << "invalid router"; + case SessionResult::RouterNotFound: + return out << "not found"; + } + return out; + } + using RouterCallback = std::function; struct IOutboundSessionMaker diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index c657779b6..d5333ba9f 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -1220,7 +1220,8 @@ namespace llarp router, " (", previous_fails + 1, - " consecutive failures)"); + " consecutive failures) result=", + result); } else { From 75451d7124dcc5a37a7f19490c3267f929268dde Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 1 Jul 2021 12:29:42 -0400 Subject: [PATCH 16/32] * add establish fail enum * dont call outbound session hooks for inbound sessions --- llarp/router/i_outbound_session_maker.hpp | 5 ++++- llarp/router/outbound_session_maker.cpp | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/llarp/router/i_outbound_session_maker.hpp b/llarp/router/i_outbound_session_maker.hpp index cc57cafea..7bb5f3693 100644 --- a/llarp/router/i_outbound_session_maker.hpp +++ b/llarp/router/i_outbound_session_maker.hpp @@ -17,7 +17,8 @@ namespace llarp Timeout, RouterNotFound, InvalidRouter, - NoLink + NoLink, + EstablishFail }; inline std::ostream& @@ -35,6 +36,8 @@ namespace llarp return out << "invalid router"; case SessionResult::RouterNotFound: return out << "not found"; + case SessionResult::EstablishFail: + return out << "establish failed"; } return out; } diff --git a/llarp/router/outbound_session_maker.cpp b/llarp/router/outbound_session_maker.cpp index fbcc903df..4eb264487 100644 --- a/llarp/router/outbound_session_maker.cpp +++ b/llarp/router/outbound_session_maker.cpp @@ -35,10 +35,10 @@ namespace llarp OutboundSessionMaker::OnSessionEstablished(ILinkSession* session) { // TODO: do we want to keep it - + const RouterContact rc = session->GetRemoteRC(); const auto router = RouterID(session->GetPubKey()); const bool isOutbound = not session->IsInbound(); - const std::string remoteType = session->GetRemoteRC().IsPublicRouter() ? "router" : "client"; + const std::string remoteType = rc.IsPublicRouter() ? "router" : "client"; LogInfo( "session with ", remoteType, " [", router, "] ", isOutbound ? "established" : "received"); @@ -48,9 +48,12 @@ namespace llarp return false; } - work([this, rc = session->GetRemoteRC()] { VerifyRC(rc); }); - - return true; + if (isOutbound) + { + work([this, rc] { VerifyRC(rc); }); + return true; + } + return _rcLookup->CheckRC(rc); } void @@ -204,12 +207,10 @@ namespace llarp } const auto& job = itr->second; - if (!job->link->TryEstablishTo(job->rc)) + if (not job->link->TryEstablishTo(job->rc)) { - // TODO: maybe different failure type? - l.unlock(); - FinalizeRequest(router, SessionResult::NoLink); + FinalizeRequest(router, SessionResult::EstablishFail); } } @@ -229,7 +230,7 @@ namespace llarp LinkLayer_ptr link = _linkManager->GetCompatibleLink(rc); - if (!link) + if (not link) { l.unlock(); FinalizeRequest(router, SessionResult::NoLink); From 32a94c73e28a340a734eec953ace0b4d1f189625 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Jul 2021 07:40:39 -0400 Subject: [PATCH 17/32] update lokinetmon * add --introset-filter option to filter results in introset inspection mode by regex --- contrib/py/admin/lokinetmon | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/contrib/py/admin/lokinetmon b/contrib/py/admin/lokinetmon index 2c45b2435..d9cfea3bc 100755 --- a/contrib/py/admin/lokinetmon +++ b/contrib/py/admin/lokinetmon @@ -6,6 +6,7 @@ import sys import time import platform import os +import re from argparse import ArgumentParser as AP is_windows = lambda : platform.system().lower() == 'windows' @@ -40,12 +41,13 @@ except ImportError: print("for other linuxs do:") print("\tpip3 install --user geoip") print("for other linuxs you are responsible for obtaining your owen geoip databases, glhf") + time.sleep(1) else: print("install it with:") print("\tpip3 install --user geoip") - print("") - print("press enter to continue without geoip") - sys.stdin.read(1) + print() + print("press enter to continue without geoip") + sys.stdin.read(1) else: try: geoip_env_var = 'GEOIP_DB_FILE' @@ -86,6 +88,7 @@ def ip_to_flag(ip): class Monitor: _sample_size = 12 + introset_filter = None def __init__(self, url, introsetMode=False): self.txrate = 0 @@ -407,12 +410,14 @@ class Monitor: """ y_pos += 1 self.win.move(y_pos, 1) - self.win.addstr("localhost.loki") - y_pos = self._display_our_introset(y_pos, service) - y_pos += 1 + if self.introset_filter("localhost.loki"): + self.win.addstr("localhost.loki") + y_pos = self._display_our_introset(y_pos, service) + y_pos += 1 remotes = service['remoteSessions'] or [] for session in remotes: - y_pos = self._display_session_introset(y_pos, session) + if self.introset_filter(session['remoteIdentity']): + y_pos = self._display_session_introset(y_pos, session) def _display_intro(self, y_pos, intro, label, paths): y_pos += 1 @@ -544,6 +549,7 @@ def main(): ap.add_argument("--introset", action='store_const', const=True, default=False, help="run in introset inspection mode") ap.add_argument("--url", default='tcp://127.0.0.1:1190', type=str, help='url to lokinet rpc') + ap.add_argument('--introset-filter', default=None, type=str, help="while in introset inspection mode filter results by regex") args = ap.parse_args() @@ -551,6 +557,9 @@ def main(): args.url, args.introset ) + mon.introset_filter = lambda x : True + if args.introset_filter: + mon.introset_filter = lambda x : re.match(args.introset_filter, x) is not None mon.run() if __name__ == "__main__": From e7ac0f39020f963e5387af09449ea7768443d2d6 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Jul 2021 07:41:58 -0400 Subject: [PATCH 18/32] expunge outbound contexts that have not gotten inbound traffic for a long while --- llarp/service/outbound_context.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index 12042b1e2..98f6cd28c 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -404,6 +404,10 @@ namespace llarp m_ReadyHooks.clear(); } + if (m_LastInboundTraffic > 0s and lastGoodSend > 0s + and now >= sendTimeout + m_LastInboundTraffic) + return true; + const auto timeout = std::max(lastGoodSend, m_LastInboundTraffic); if (lastGoodSend > 0s and now >= timeout + (sendTimeout / 2)) { From d918e1eddae45c6f183ee2225287c9513c5948b0 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Jul 2021 08:18:52 -0400 Subject: [PATCH 19/32] add age to outbound contexts in lokinetmon better time foratting in lokinetmon --- contrib/py/admin/lokinetmon | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/contrib/py/admin/lokinetmon b/contrib/py/admin/lokinetmon index d9cfea3bc..6c1fabeb5 100755 --- a/contrib/py/admin/lokinetmon +++ b/contrib/py/admin/lokinetmon @@ -156,13 +156,17 @@ class Monitor: @staticmethod def time_to(timestamp): - """ return time until timestamp in seconds formatted""" + """ return time until timestamp formatted""" if timestamp: + unit = 'seconds' val = (timestamp - now()) / 1000.0 + if abs(val) > 60.0: + val /= 60.0 + unit = 'minutes' if val < 0: - return "{} seconds ago".format(0-val) + return "{:.2f} {} ago".format(0-val, unit) else: - return "{} seconds".format(val) + return "{:.2f} {}".format(val, unit) else: return 'never' @@ -423,7 +427,7 @@ class Monitor: y_pos += 1 self.win.move(y_pos, 1) path = 'path' in intro and intro['path'][:4] or '????' - self.win.addstr('{}: ({}|{}) [expires in: {}] [{} paths]'.format(label, intro['router'][:8], path, self.time_to(intro['expiresAt']), self.count_endpoints_in_path(paths, intro['router']))) + self.win.addstr('{}: ({}|{}) [expires: {}] [{} paths]'.format(label, intro['router'][:8], path, self.time_to(intro['expiresAt']), self.count_endpoints_in_path(paths, intro['router']))) return y_pos @staticmethod @@ -466,6 +470,9 @@ class Monitor: self.win.addstr('{} ({}) [{}]'.format(context['remoteIdentity'], context['currentConvoTag'], readyState)) y_pos += 1 self.win.move(y_pos, 1) + self.win.addstr('created: {}'.format(self.time_to(context['sessionCreatedAt']))) + y_pos += 1 + self.win.move(y_pos, 1) self.win.addstr('last good send: {}'.format(self.time_to(context['lastGoodSend']))) y_pos += 1 self.win.move(y_pos, 1) From 30848165e73a3643d2c9c7435082544a2a1fcc9e Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Jul 2021 08:26:56 -0400 Subject: [PATCH 20/32] add path filter in lokinetmon --- contrib/py/admin/lokinetmon | 21 ++++++++++++++------- llarp/exit/session.cpp | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/contrib/py/admin/lokinetmon b/contrib/py/admin/lokinetmon index 6c1fabeb5..91da02be4 100755 --- a/contrib/py/admin/lokinetmon +++ b/contrib/py/admin/lokinetmon @@ -88,7 +88,8 @@ def ip_to_flag(ip): class Monitor: _sample_size = 12 - introset_filter = None + introset_filter = lambda x: True + path_filter = lambda x: True def __init__(self, url, introsetMode=False): self.txrate = 0 @@ -208,15 +209,18 @@ class Monitor: paths = status["paths"] self.win.addstr("paths: {}".format(len(paths))) for path in paths: - y_pos = self._render_path(y_pos, path, "inbound") + if self.path_filter('inbound'): + y_pos = self._render_path(y_pos, path, "inbound") for session in (status["remoteSessions"] or []): for path in session["paths"]: - y_pos = self._render_path( - y_pos, path, "[active] {}".format(session["currentConvoTag"]) - ) + if self.path_filter(session["remoteIdentity"]): + y_pos = self._render_path( + y_pos, path, "[active] {}".format(session["currentConvoTag"]) + ) for session in (status["snodeSessions"] or []): for path in session["paths"]: - y_pos = self._render_path(y_pos, path, "[snode]") + if self.path_filter(session["endpoint"]): + y_pos = self._render_path(y_pos, path, "[snode]") return y_pos def display_links(self, y_pos, data): @@ -558,15 +562,18 @@ def main(): ap.add_argument("--url", default='tcp://127.0.0.1:1190', type=str, help='url to lokinet rpc') ap.add_argument('--introset-filter', default=None, type=str, help="while in introset inspection mode filter results by regex") + ap.add_argument('--path-filter', default=None, type=str, help="regex to filter out paths") + args = ap.parse_args() mon = Monitor( args.url, args.introset ) - mon.introset_filter = lambda x : True if args.introset_filter: mon.introset_filter = lambda x : re.match(args.introset_filter, x) is not None + if args.path_fiter: + mon.path_filter = lambda x :re.match(args.path_filter, x) is not None mon.run() if __name__ == "__main__": diff --git a/llarp/exit/session.cpp b/llarp/exit/session.cpp index fd781bf68..f6c2d5136 100644 --- a/llarp/exit/session.cpp +++ b/llarp/exit/session.cpp @@ -46,6 +46,7 @@ namespace llarp obj["lastExitUse"] = to_json(m_LastUse); auto pub = m_ExitIdentity.toPublic(); obj["exitIdentity"] = pub.ToString(); + obj["endpoint"] = m_ExitRouter.ToString(); return obj; } From 383312a74dd6849bc4aaae0467429162b96bc3ec Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Jul 2021 08:27:44 -0400 Subject: [PATCH 21/32] make filters consistent for localhost.loki --- contrib/py/admin/lokinetmon | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/py/admin/lokinetmon b/contrib/py/admin/lokinetmon index 91da02be4..228b1766c 100755 --- a/contrib/py/admin/lokinetmon +++ b/contrib/py/admin/lokinetmon @@ -209,8 +209,8 @@ class Monitor: paths = status["paths"] self.win.addstr("paths: {}".format(len(paths))) for path in paths: - if self.path_filter('inbound'): - y_pos = self._render_path(y_pos, path, "inbound") + if self.path_filter('localhost.loki'): + y_pos = self._render_path(y_pos, path, "localhost.loki") for session in (status["remoteSessions"] or []): for path in session["paths"]: if self.path_filter(session["remoteIdentity"]): From 91f6ca9869463e3724b2ee13e9c9dcbebc2e3d2a Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Jul 2021 08:28:43 -0400 Subject: [PATCH 22/32] typofix --- contrib/py/admin/lokinetmon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/py/admin/lokinetmon b/contrib/py/admin/lokinetmon index 228b1766c..813a2e710 100755 --- a/contrib/py/admin/lokinetmon +++ b/contrib/py/admin/lokinetmon @@ -572,7 +572,7 @@ def main(): ) if args.introset_filter: mon.introset_filter = lambda x : re.match(args.introset_filter, x) is not None - if args.path_fiter: + if args.path_filter: mon.path_filter = lambda x :re.match(args.path_filter, x) is not None mon.run() From 63c601b0c06a278abc2a092c4c4ae60fdbc83d64 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Jul 2021 08:47:10 -0400 Subject: [PATCH 23/32] fixes for lokinetmon filters --- contrib/py/admin/lokinetmon | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/contrib/py/admin/lokinetmon b/contrib/py/admin/lokinetmon index 813a2e710..25b45b018 100755 --- a/contrib/py/admin/lokinetmon +++ b/contrib/py/admin/lokinetmon @@ -88,8 +88,8 @@ def ip_to_flag(ip): class Monitor: _sample_size = 12 - introset_filter = lambda x: True - path_filter = lambda x: True + introset_filter = lambda x : True + path_filter = lambda x : True def __init__(self, url, introsetMode=False): self.txrate = 0 @@ -148,7 +148,7 @@ class Monitor: self.win.addstr(" {} ->".format(hopstr)) self.win.addstr(" [{} ms latency]".format(path["intro"]["latency"])) - self.win.addstr(" [{} until expire]".format(self.time_to(path["expiresAt"]))) + self.win.addstr(" [expires: {}]".format(self.time_to(path["expiresAt"]))) if path["expiresSoon"]: self.win.addstr("(expiring)") elif path["expired"]: @@ -560,9 +560,9 @@ def main(): ap.add_argument("--introset", action='store_const', const=True, default=False, help="run in introset inspection mode") ap.add_argument("--url", default='tcp://127.0.0.1:1190', type=str, help='url to lokinet rpc') - ap.add_argument('--introset-filter', default=None, type=str, help="while in introset inspection mode filter results by regex") + ap.add_argument('--introset-filter', default='.+', type=str, help="while in introset inspection mode filter results by regex") - ap.add_argument('--path-filter', default=None, type=str, help="regex to filter out paths") + ap.add_argument('--path-filter', default='.+', type=str, help="regex to filter out paths") args = ap.parse_args() @@ -570,10 +570,9 @@ def main(): args.url, args.introset ) - if args.introset_filter: - mon.introset_filter = lambda x : re.match(args.introset_filter, x) is not None - if args.path_filter: - mon.path_filter = lambda x :re.match(args.path_filter, x) is not None + + mon.introset_filter = lambda x : re.match(args.introset_filter, x) is not None + mon.path_filter = lambda x : re.match(args.path_filter, x) is not None mon.run() if __name__ == "__main__": From 264616c8bab34110cf9069917bc3b3f5854fc9f7 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Jul 2021 08:48:55 -0400 Subject: [PATCH 24/32] fix unicode char --- contrib/py/admin/lokinetmon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/py/admin/lokinetmon b/contrib/py/admin/lokinetmon index 25b45b018..f3fb5d611 100755 --- a/contrib/py/admin/lokinetmon +++ b/contrib/py/admin/lokinetmon @@ -470,7 +470,7 @@ class Monitor: #print(context.keys()) y_pos += 1 self.win.move(y_pos, 1) - readyState = context['readyToSend'] and '✔️' or '❌' + readyState = context['readyToSend'] and '️✅' or '❌' self.win.addstr('{} ({}) [{}]'.format(context['remoteIdentity'], context['currentConvoTag'], readyState)) y_pos += 1 self.win.move(y_pos, 1) From 6df1d6412dd6cf0ecd96ddf130cf2465e95d3558 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Jul 2021 08:51:10 -0400 Subject: [PATCH 25/32] unify introset-filter and path-filter --- contrib/py/admin/lokinetmon | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/contrib/py/admin/lokinetmon b/contrib/py/admin/lokinetmon index f3fb5d611..792564faa 100755 --- a/contrib/py/admin/lokinetmon +++ b/contrib/py/admin/lokinetmon @@ -88,8 +88,7 @@ def ip_to_flag(ip): class Monitor: _sample_size = 12 - introset_filter = lambda x : True - path_filter = lambda x : True + filter = lambda x : True def __init__(self, url, introsetMode=False): self.txrate = 0 @@ -209,17 +208,17 @@ class Monitor: paths = status["paths"] self.win.addstr("paths: {}".format(len(paths))) for path in paths: - if self.path_filter('localhost.loki'): + if self.filter('localhost.loki'): y_pos = self._render_path(y_pos, path, "localhost.loki") for session in (status["remoteSessions"] or []): for path in session["paths"]: - if self.path_filter(session["remoteIdentity"]): + if self.filter(session["remoteIdentity"]): y_pos = self._render_path( y_pos, path, "[active] {}".format(session["currentConvoTag"]) ) for session in (status["snodeSessions"] or []): for path in session["paths"]: - if self.path_filter(session["endpoint"]): + if self.filter(session["endpoint"]): y_pos = self._render_path(y_pos, path, "[snode]") return y_pos @@ -418,13 +417,13 @@ class Monitor: """ y_pos += 1 self.win.move(y_pos, 1) - if self.introset_filter("localhost.loki"): + if self.filter("localhost.loki"): self.win.addstr("localhost.loki") y_pos = self._display_our_introset(y_pos, service) y_pos += 1 remotes = service['remoteSessions'] or [] for session in remotes: - if self.introset_filter(session['remoteIdentity']): + if self.filter(session['remoteIdentity']): y_pos = self._display_session_introset(y_pos, session) def _display_intro(self, y_pos, intro, label, paths): @@ -560,9 +559,7 @@ def main(): ap.add_argument("--introset", action='store_const', const=True, default=False, help="run in introset inspection mode") ap.add_argument("--url", default='tcp://127.0.0.1:1190', type=str, help='url to lokinet rpc') - ap.add_argument('--introset-filter', default='.+', type=str, help="while in introset inspection mode filter results by regex") - - ap.add_argument('--path-filter', default='.+', type=str, help="regex to filter out paths") + ap.add_argument('--filter', default='.+', type=str, help="regex to filter entries") args = ap.parse_args() @@ -571,8 +568,7 @@ def main(): args.introset ) - mon.introset_filter = lambda x : re.match(args.introset_filter, x) is not None - mon.path_filter = lambda x : re.match(args.path_filter, x) is not None + mon.filter = lambda x : re.match(args.filter, x) is not None mon.run() if __name__ == "__main__": From 3893a94e07da7f451545f5ad201f181c7bf297b9 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Jul 2021 08:53:39 -0400 Subject: [PATCH 26/32] better time formatting for future times --- contrib/py/admin/lokinetmon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/py/admin/lokinetmon b/contrib/py/admin/lokinetmon index 792564faa..65f3f637a 100755 --- a/contrib/py/admin/lokinetmon +++ b/contrib/py/admin/lokinetmon @@ -166,7 +166,7 @@ class Monitor: if val < 0: return "{:.2f} {} ago".format(0-val, unit) else: - return "{:.2f} {}".format(val, unit) + return "in {:.2f} {}".format(val, unit) else: return 'never' From 8f4c23ef473afe54f9305a0a5863c778ab19b0c8 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 2 Jul 2021 09:01:14 -0400 Subject: [PATCH 27/32] add option to invert regex filter results --- contrib/py/admin/lokinetmon | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/py/admin/lokinetmon b/contrib/py/admin/lokinetmon index 65f3f637a..ea086f85e 100755 --- a/contrib/py/admin/lokinetmon +++ b/contrib/py/admin/lokinetmon @@ -560,6 +560,7 @@ def main(): ap.add_argument("--introset", action='store_const', const=True, default=False, help="run in introset inspection mode") ap.add_argument("--url", default='tcp://127.0.0.1:1190', type=str, help='url to lokinet rpc') ap.add_argument('--filter', default='.+', type=str, help="regex to filter entries") + ap.add_argument('--invert-filter', const=True, default=False, action='store_const', help='invert regex filter matching') args = ap.parse_args() @@ -567,8 +568,10 @@ def main(): args.url, args.introset ) - mon.filter = lambda x : re.match(args.filter, x) is not None + if args.invert_filter: + old_filter = mon.filter + mon.filter = lambda x : not old_filter(x) mon.run() if __name__ == "__main__": From 18cb59a1b58c03fdd4302fc3f408cf959681585d Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 5 Jul 2021 09:06:46 -0400 Subject: [PATCH 28/32] * make tranform function for SessionResult to SendStatus * add case for SessionResult::EstablishFail * clean up outbound message handler to use transform function instead of many private member functions --- llarp/router/outbound_message_handler.cpp | 62 ++++++----------------- llarp/router/outbound_message_handler.hpp | 16 ------ 2 files changed, 16 insertions(+), 62 deletions(-) diff --git a/llarp/router/outbound_message_handler.cpp b/llarp/router/outbound_message_handler.cpp index cf02c1d82..abbe54702 100644 --- a/llarp/router/outbound_message_handler.cpp +++ b/llarp/router/outbound_message_handler.cpp @@ -137,61 +137,31 @@ namespace llarp outboundMessageQueues.emplace(zeroID, MessageQueue()); } - void - OutboundMessageHandler::OnSessionEstablished(const RouterID& router) - { - FinalizeSessionRequest(router, SendStatus::Success); - } - - void - OutboundMessageHandler::OnConnectTimeout(const RouterID& router) - { - FinalizeSessionRequest(router, SendStatus::Timeout); - } - - void - OutboundMessageHandler::OnRouterNotFound(const RouterID& router) - { - FinalizeSessionRequest(router, SendStatus::RouterNotFound); - } - - void - OutboundMessageHandler::OnInvalidRouter(const RouterID& router) - { - FinalizeSessionRequest(router, SendStatus::InvalidRouter); - } - - void - OutboundMessageHandler::OnNoLink(const RouterID& router) - { - FinalizeSessionRequest(router, SendStatus::NoLink); - } - - void - OutboundMessageHandler::OnSessionResult(const RouterID& router, const SessionResult result) + constexpr SendStatus + ToSendStatus(const SessionResult result) { switch (result) { case SessionResult::Establish: - OnSessionEstablished(router); - break; + return SendStatus::Success; case SessionResult::Timeout: - OnConnectTimeout(router); - break; + case SessionResult::EstablishFail: + return SendStatus::Timeout; case SessionResult::RouterNotFound: - OnRouterNotFound(router); - break; + return SendStatus::RouterNotFound; case SessionResult::InvalidRouter: - OnInvalidRouter(router); - break; + return SendStatus::InvalidRouter; case SessionResult::NoLink: - OnNoLink(router); - break; - default: - LogError("Impossible situation: enum class value out of bounds."); - std::abort(); - break; + return SendStatus::NoLink; } + // fall through case to appease compiler + return SendStatus::Congestion; + } + + void + OutboundMessageHandler::OnSessionResult(const RouterID& router, const SessionResult result) + { + FinalizeSessionRequest(router, ToSendStatus(result)); } void diff --git a/llarp/router/outbound_message_handler.hpp b/llarp/router/outbound_message_handler.hpp index 51beac9cc..be4d151eb 100644 --- a/llarp/router/outbound_message_handler.hpp +++ b/llarp/router/outbound_message_handler.hpp @@ -114,22 +114,6 @@ namespace llarp * the messages are dropped and their send status callbacks are invoked with * the appropriate send status. */ - - void - OnSessionEstablished(const RouterID& router); - - void - OnConnectTimeout(const RouterID& router); - - void - OnRouterNotFound(const RouterID& router); - - void - OnInvalidRouter(const RouterID& router); - - void - OnNoLink(const RouterID& router); - void OnSessionResult(const RouterID& router, const SessionResult result); From 114c7bab62beb4288194ae21244c6652f483870c Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 5 Jul 2021 09:13:05 -0400 Subject: [PATCH 29/32] bump up the jam, bump it up, while your feet are jumping. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ce5bb845..0583bc5e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ if(CCACHE_PROGRAM) endif() project(lokinet - VERSION 0.9.4 + VERSION 0.9.5 DESCRIPTION "lokinet - IP packet onion router" LANGUAGES C CXX) From 069d9487b7dd630381d2c7890ad42933eb328f45 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 5 Jul 2021 09:18:28 -0400 Subject: [PATCH 30/32] * throw exception on invalid SessionResult when transforming to SendStatus * add case for printing unknown SessionResult --- llarp/router/i_outbound_session_maker.hpp | 2 +- llarp/router/outbound_message_handler.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/llarp/router/i_outbound_session_maker.hpp b/llarp/router/i_outbound_session_maker.hpp index 7bb5f3693..76ef6ddbd 100644 --- a/llarp/router/i_outbound_session_maker.hpp +++ b/llarp/router/i_outbound_session_maker.hpp @@ -39,7 +39,7 @@ namespace llarp case SessionResult::EstablishFail: return out << "establish failed"; } - return out; + return out << "???"; } using RouterCallback = std::function; diff --git a/llarp/router/outbound_message_handler.cpp b/llarp/router/outbound_message_handler.cpp index abbe54702..16e63b12d 100644 --- a/llarp/router/outbound_message_handler.cpp +++ b/llarp/router/outbound_message_handler.cpp @@ -154,8 +154,8 @@ namespace llarp case SessionResult::NoLink: return SendStatus::NoLink; } - // fall through case to appease compiler - return SendStatus::Congestion; + throw std::invalid_argument{ + stringify("SessionResult ", result, " has no corrispoding SendStatus when transforming")}; } void From ed456b0c7e7d2bbdba0f97328367b19324a25625 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Mon, 5 Jul 2021 10:40:48 -0300 Subject: [PATCH 31/32] Fix typo in libuv error message --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0583bc5e0..8f982142c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,7 +141,7 @@ if(LIBUV_FOUND AND NOT BUILD_STATIC_DEPS) target_link_libraries(libuv INTERFACE PkgConfig::LIBUV) else() if(NOT BUILD_STATIC_DEPS) - message(FATAL_ERROR "Could not find libu >= 1.28.0; install it on your system or use -DBUILD_STATIC_DEPS=ON") + message(FATAL_ERROR "Could not find libuv >= 1.28.0; install it on your system or use -DBUILD_STATIC_DEPS=ON") endif() endif() From 14cc11548963a13dad8cf34b39753d215129980a Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 5 Jul 2021 12:37:54 -0400 Subject: [PATCH 32/32] dont use constexpr --- llarp/router/outbound_message_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llarp/router/outbound_message_handler.cpp b/llarp/router/outbound_message_handler.cpp index 16e63b12d..ac8fda64f 100644 --- a/llarp/router/outbound_message_handler.cpp +++ b/llarp/router/outbound_message_handler.cpp @@ -137,7 +137,7 @@ namespace llarp outboundMessageQueues.emplace(zeroID, MessageQueue()); } - constexpr SendStatus + static inline SendStatus ToSendStatus(const SessionResult result) { switch (result)