From 2abe2d936350a8993497d9eb4f6d8118e7de8859 Mon Sep 17 00:00:00 2001 From: dr7ana Date: Tue, 24 Oct 2023 12:25:42 -0700 Subject: [PATCH] Review fixes - cleaned up include-what-you-use errors (mostly quoted includes) - misc fixes --- daemon/lokinet.cpp | 2 +- llarp/CMakeLists.txt | 1 - llarp/nodedb.cpp | 2 +- llarp/pow.cpp | 56 ------------------------------ llarp/pow.hpp | 48 ------------------------- llarp/router/rc_lookup_handler.cpp | 3 -- llarp/service/intro_set.cpp | 1 + llarp/service/intro_set.hpp | 1 - llarp/service/outbound_context.cpp | 2 +- llarp/service/outbound_context.hpp | 2 +- llarp/service/protocol.cpp | 3 +- llarp/vpn/android.hpp | 3 +- pybind/llarp/router.cpp | 4 +-- 13 files changed, 10 insertions(+), 118 deletions(-) delete mode 100644 llarp/pow.cpp delete mode 100644 llarp/pow.hpp diff --git a/daemon/lokinet.cpp b/daemon/lokinet.cpp index b3cb416c8..f43900669 100644 --- a/daemon/lokinet.cpp +++ b/daemon/lokinet.cpp @@ -639,7 +639,7 @@ main(int argc, char* argv[]) static const char* text = "Don't run lokinet in wine, aborting startup"; static const char* title = "Lokinet Wine Error"; MessageBoxA(NULL, text, title, MB_ICONHAND); - abort(); + std::abort(); } } diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index f67243cf4..06e4ac5b2 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -98,7 +98,6 @@ lokinet_add_library(lokinet-time-place net/ip_range.cpp net/net_int.cpp net/sock_addr.cpp - pow.cpp # only intro_set router_contact.cpp router_id.cpp router_version.cpp # to be deleted shortly diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index 5ea66233e..cc6d2a28b 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -238,7 +238,7 @@ namespace llarp size_t NodeDB::num_loaded() const { - return router.loop()->call_get([this]() -> size_t { return entries.size(); }); + return router.loop()->call_get([this]() { return entries.size(); }); } void diff --git a/llarp/pow.cpp b/llarp/pow.cpp deleted file mode 100644 index 2051fbc7a..000000000 --- a/llarp/pow.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "pow.hpp" - -#include "crypto/crypto.hpp" - -#include - -namespace llarp -{ - PoW::~PoW() = default; - - bool - PoW::decode_key(const llarp_buffer_t& /*k*/, llarp_buffer_t* /*val*/) - { - // TODO: implement me - return false; - } - - std::string - PoW::bt_encode() const - { - return ""s; - } - - bool - PoW::IsValid(llarp_time_t now) const - { - if (now - timestamp > extendedLifetime) - return false; - - ShortHash digest; - auto buf = bt_encode(); - - // hash - if (!crypto::shorthash(digest, reinterpret_cast(buf.data()), buf.size())) - return false; - // check bytes required - uint32_t required = std::floor(std::log(extendedLifetime.count())); - for (uint32_t idx = 0; idx < required; ++idx) - { - if (digest[idx]) - return false; - } - return true; - } - - std::string - PoW::ToString() const - { - return fmt::format( - "[PoW timestamp={} lifetime={} nonce={}]", - timestamp.count(), - extendedLifetime.count(), - nonce); - } - -} // namespace llarp diff --git a/llarp/pow.hpp b/llarp/pow.hpp deleted file mode 100644 index b41fb003a..000000000 --- a/llarp/pow.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "router_id.hpp" -#include "util/buffer.hpp" - -namespace llarp -{ - /// proof of work - struct PoW - { - static constexpr size_t MaxSize = 128; - llarp_time_t timestamp = 0s; - llarp_time_t extendedLifetime = 0s; - AlignedBuffer<32> nonce; - uint64_t version = llarp::constants::proto_version; - - ~PoW(); - - bool - IsValid(llarp_time_t now) const; - - bool - decode_key(const llarp_buffer_t& k, llarp_buffer_t* val); - - std::string - bt_encode() const; - - bool - operator==(const PoW& other) const - { - return timestamp == other.timestamp && version == other.version - && extendedLifetime == other.extendedLifetime && nonce == other.nonce; - } - - bool - operator!=(const PoW& other) const - { - return !(*this == other); - } - - std::string - ToString() const; - }; - - template <> - constexpr inline bool IsToStringFormattable = true; - -} // namespace llarp diff --git a/llarp/router/rc_lookup_handler.cpp b/llarp/router/rc_lookup_handler.cpp index e10684a79..8cb96b10d 100644 --- a/llarp/router/rc_lookup_handler.cpp +++ b/llarp/router/rc_lookup_handler.cpp @@ -106,10 +106,7 @@ namespace llarp if (callback) callback(result.router_id(), result, true); else - { r.node_db()->put_rc_if_newer(result); - // r.connect_to(result); - } } else { diff --git a/llarp/service/intro_set.cpp b/llarp/service/intro_set.cpp index 93cd5af30..602e79dd4 100644 --- a/llarp/service/intro_set.cpp +++ b/llarp/service/intro_set.cpp @@ -184,6 +184,7 @@ namespace llarp::service IntroSet::ExtractStatus() const { util::StatusObject obj{{"published", to_json(time_signed)}}; + // TODO: this // std::vector introsObjs; // std::transform( // intros.begin(), diff --git a/llarp/service/intro_set.hpp b/llarp/service/intro_set.hpp index de11118f8..3fdcf80b6 100644 --- a/llarp/service/intro_set.hpp +++ b/llarp/service/intro_set.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index 9c0537915..115394f57 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -489,7 +489,7 @@ namespace llarp::service } void - OutboundContext::Tick(std::chrono::milliseconds now) + OutboundContext::Tick(llarp_time_t now) { path::Builder::Tick(now); diff --git a/llarp/service/outbound_context.hpp b/llarp/service/outbound_context.hpp index 2b66715ee..d0381b0c7 100644 --- a/llarp/service/outbound_context.hpp +++ b/llarp/service/outbound_context.hpp @@ -79,7 +79,7 @@ namespace llarp::service send_auth_async(std::function resultHandler); void - Tick(std::chrono::milliseconds now) override; + Tick(llarp_time_t now) override; util::StatusObject ExtractStatus() const; diff --git a/llarp/service/protocol.cpp b/llarp/service/protocol.cpp index 755554a24..bcc2960ef 100644 --- a/llarp/service/protocol.cpp +++ b/llarp/service/protocol.cpp @@ -39,8 +39,7 @@ namespace llarp::service ProtocolMessage::decode_key(const llarp_buffer_t& k, llarp_buffer_t* buf) { bool read = false; - // if (!BEncodeMaybeReadDictInt("a", proto, read, k, buf)) - // return false; + if (k.startswith("d")) { llarp_buffer_t strbuf; diff --git a/llarp/vpn/android.hpp b/llarp/vpn/android.hpp index 402c91ada..88012c3be 100644 --- a/llarp/vpn/android.hpp +++ b/llarp/vpn/android.hpp @@ -5,9 +5,10 @@ #include -#include #include +#include + namespace llarp::vpn { class AndroidInterface : public NetworkInterface diff --git a/pybind/llarp/router.cpp b/pybind/llarp/router.cpp index edc9be78f..51543e8da 100644 --- a/pybind/llarp/router.cpp +++ b/pybind/llarp/router.cpp @@ -1,8 +1,8 @@ +#include "common.hpp" + #include #include -#include - namespace llarp { void