From 6e67f38408c9ec61d4fee5dbcf5f1fde37e9ae60 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 12 May 2021 07:36:00 -0400 Subject: [PATCH 1/9] add format verification to contrib/format.sh run with ./contrib/format.sh verify exits with 0 if we are good, exits non-zero if we are not formatted right --- contrib/format.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contrib/format.sh b/contrib/format.sh index d6fa22389..f83c27436 100755 --- a/contrib/format.sh +++ b/contrib/format.sh @@ -16,6 +16,9 @@ if [ $? -ne 0 ]; then fi fi -# TODO: readlink -e is a GNU-ism -cd "$(readlink -e $(dirname $0)/../)" -$binary -i $(find jni daemon llarp include pybind | grep -E '\.[hc](pp)?$') &> /dev/null +cd "$(dirname $0)/../" +if [ "$1" = "verify" ] ; then + exit $($binary --output-replacements-xml $(find jni daemon llarp include pybind | grep -E '\.[hc](pp)?$' | grep -v '\#') | grep '' | wc -l) +else + $binary -i $(find jni daemon llarp include pybind | grep -E '\.[hc](pp)?$' | grep -v '\#') &> /dev/null +fi From d066bf8576d7f120bdee7ead95e5bd0d1b60e5b4 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 12 May 2021 08:03:35 -0400 Subject: [PATCH 2/9] check in pre-push git hook so I don't lose it --- contrib/git-hook-pre-push.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 contrib/git-hook-pre-push.sh diff --git a/contrib/git-hook-pre-push.sh b/contrib/git-hook-pre-push.sh new file mode 100755 index 000000000..b4bdf8f79 --- /dev/null +++ b/contrib/git-hook-pre-push.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# pre-push hook for git +# this script is probably overkill for most contributors +# +# "i use this to prevent foot cannons caused by commiting broken code" +# +# ~ jeff (lokinet author and crazy person) +# +# +# to use this as a git hook do this in the root of the repo: +# +# cp contrib/git-hook-pre-push.sh .git/hooks/pre-push +# + + +set -e + +cd "$(dirname $0)/../.." +echo "check format..." +./contrib/format.sh verify +echo "format is gucci af fam" + +echo "remove old test build directory..." +rm -rf build-git-hook +mkdir build-git-hook +echo "configuring test build jizz..." +cmake -S . -B build-git-hook -DWITH_LTO=OFF -DWITH_HIVE=ON -G Ninja +echo "ensure this shit compiles..." +ninja -C build-git-hook all +echo "ensure unit tests aren't fucked..." +ninja -C build-git-hook check + +echo "we gud UmU" +echo "" From f1efcc29ea5d64806cd88341de46bdfeb454fdfc Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 15 May 2021 06:23:45 -0400 Subject: [PATCH 3/9] mark inbound traffic as convotag active --- llarp/service/endpoint.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 29b24262c..9eeac8176 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -1083,9 +1083,10 @@ namespace llarp PutReplyIntroFor(msg->tag, path->intro); Introduction intro; intro.pathID = from; - intro.router = PubKey(path->Endpoint()); + intro.router = PubKey{path->Endpoint()}; intro.expiresAt = std::min(path->ExpireTime(), msg->introReply.expiresAt); PutIntroFor(msg->tag, intro); + ConvoTagRX(msg->tag); return ProcessDataMessage(msg); } From ae97b871116a0e6636d2d0c29979d63decfc1e58 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 15 May 2021 06:54:56 -0400 Subject: [PATCH 4/9] exits don't rewrite ip addresses, fix this and add note --- llarp/handlers/tun.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index 0504f74d2..4846bdffd 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -933,7 +933,6 @@ namespace llarp PathAlignmentTimeout()); return; } - bool rewriteAddrs = true; std::variant to; service::ProtocolType type; if (m_SNodes.at(itr->second)) @@ -950,7 +949,8 @@ namespace llarp // prepare packet for insertion into network // this includes clearing IP addresses, recalculating checksums, etc - if (rewriteAddrs) + // this does not happen for exits because the point is they don't rewrite addresses + if (type != service::ProtocolType::Exit) { if (pkt.IsV4()) pkt.UpdateIPv4Address({0}, {0}); @@ -1074,7 +1074,12 @@ namespace llarp } } if (not allow) + { + var::visit( + [&](auto&& address) { LogWarn(Name(), " does not allow ", src, " from ", address); }, + addr); return false; + } } else { From 7c6bb9a24cdf437eb8ae1f84eacc6bf92fed8010 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 15 May 2021 09:19:45 -0400 Subject: [PATCH 5/9] simplify loop and correct logic, we want to bail out of the loop on first match. --- llarp/handlers/tun.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index 4846bdffd..e85535607 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -1059,18 +1059,22 @@ namespace llarp src = pkt.srcv6(); } // find what exit we think this should be for + service::Address fromAddr{}; + if (const auto* ptr = std::get_if(&addr)) + { + fromAddr = *ptr; + } + else // don't allow snode + return false; const auto mapped = m_ExitMap.FindAllEntries(src); bool allow = false; for (const auto& [range, exitAddr] : mapped) { if ((range.BogonRange() and range.Contains(src)) or not IsBogon(src)) { - // this range is either not a bogon or is a bogon we are explicitly allowing - if (const auto* ptr = std::get_if(&addr)) - { - // allow if this address matches the endpoint we think it should be - allow = exitAddr == *ptr; - } + // allow if this address matches the endpoint we think it should be + allow = exitAddr == fromAddr; + break; } } if (not allow) From 970ccfcd4ef611f12aebc5434616b3f39b6f0106 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 16 May 2021 05:59:39 -0400 Subject: [PATCH 6/9] send a keep alive to keep an idle session alive so it doesn't get removed --- llarp/service/outbound_context.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index 15b16fdbe..f7d64547a 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -369,6 +369,12 @@ namespace llarp }); } + if (lastGoodSend > 0s and now >= lastGoodSend + (sendTimeout / 2)) + { + // send a keep alive to keep this session alive + KeepAlive(); + } + // if we are dead return true so we are removed return lastGoodSend > 0s ? (now >= lastGoodSend && now - lastGoodSend > sendTimeout) : (now >= createdAt && now - createdAt > connectTimeout); From 432e7f2a5aa85dfca2ff3702203d6a2301b8cfbe Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 16 May 2021 16:26:32 -0400 Subject: [PATCH 7/9] update introset if we get a discard message from a possibly expired intro --- llarp/service/outbound_context.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index f7d64547a..741ddccf2 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -47,6 +47,7 @@ namespace llarp LogWarn(Name(), " message ", seq, " dropped by endpoint ", p->Endpoint(), " via ", dst); MarkCurrentIntroBad(Now()); ShiftIntroduction(false); + UpdateIntroSet(); } return true; } From f172db75c5f3ff89ec7a65252b62c1183778db32 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 16 May 2021 19:31:59 -0400 Subject: [PATCH 8/9] don't defer call to ready hook with timer call it right away because we are ready --- llarp/service/outbound_context.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index 741ddccf2..c24928d35 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -348,26 +348,14 @@ namespace llarp if (ReadyToSend() and m_ReadyHook) { - KeepAlive(); const auto path = GetPathByRouter(remoteIntro.router); if (not path) { LogWarn(Name(), " ready but no path to ", remoteIntro.router, " ???"); - return false; + return true; } - const auto rtt = (path->intro.latency + remoteIntro.latency) * 2; - m_router->loop()->call_later( - rtt, [rtt, self = shared_from_this(), hook = std::move(m_ReadyHook)]() { - LogInfo( - self->Name(), - " is ready, RTT is measured as ", - self->estimatedRTT, - " approximated as ", - rtt, - " delta=", - rtt - self->estimatedRTT); - hook(self.get()); - }); + m_ReadyHook(this); + m_ReadyHook = nullptr; } if (lastGoodSend > 0s and now >= lastGoodSend + (sendTimeout / 2)) From cbb78b52800f3f6e2f9ee0c13e5caa65b9112801 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 17 May 2021 13:00:34 -0400 Subject: [PATCH 9/9] bump version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f400e0339..df65a2186 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ if(CCACHE_PROGRAM) endif() project(lokinet - VERSION 0.9.1 + VERSION 0.9.2 DESCRIPTION "lokinet - IP packet onion router" LANGUAGES C CXX)