diff --git a/CMakeLists.txt b/CMakeLists.txt index f400e03391..df65a21867 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) diff --git a/contrib/format.sh b/contrib/format.sh index d6fa22389e..f83c274363 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 diff --git a/contrib/git-hook-pre-push.sh b/contrib/git-hook-pre-push.sh new file mode 100755 index 0000000000..b4bdf8f794 --- /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 "" diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index 0504f74d24..e855356074 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}); @@ -1059,22 +1059,31 @@ 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) + { + var::visit( + [&](auto&& address) { LogWarn(Name(), " does not allow ", src, " from ", address); }, + addr); return false; + } } else { diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 29b24262ce..9eeac81763 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); } diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index 15b16fdbe5..c24928d350 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; } @@ -347,26 +348,20 @@ 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)) + { + // send a keep alive to keep this session alive + KeepAlive(); } // if we are dead return true so we are removed