From 496c1d274caf5c019061504f6fb7e79979a8da45 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Fri, 12 Aug 2022 19:52:42 -0300 Subject: [PATCH] Stub out the peer stats sqlite_orm code This avoids needing to build it and include it in static builds since we aren't currently making use of it. --- CMakeLists.txt | 1 + cmake/StaticBuild.cmake | 7 ++-- llarp/CMakeLists.txt | 6 +++- llarp/peerstats/peer_db.cpp | 64 +++++++++++++++++++++++++++++++++++++ llarp/peerstats/peer_db.hpp | 7 ++-- 5 files changed, 80 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85efb29a1..91f14fae4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ option(WITH_TESTS "build unit tests" OFF) option(WITH_HIVE "build simulation stubs" OFF) option(BUILD_PACKAGE "builds extra components for making an installer (with 'make package')" OFF) option(WITH_BOOTSTRAP "build lokinet-bootstrap tool" ${DEFAULT_WITH_BOOTSTRAP}) +option(WITH_PEERSTATS "build with experimental peerstats db support" OFF) include(cmake/enable_lto.cmake) diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake index 4f3902994..72f0a2565 100644 --- a/cmake/StaticBuild.cmake +++ b/cmake/StaticBuild.cmake @@ -315,8 +315,11 @@ build_external(sodium CONFIGURE_COMMAND ./configure ${cross_host} ${cross_rc} -- --enable-static --with-pic "CC=${deps_cc}" "CFLAGS=${deps_CFLAGS}") add_static_target(sodium sodium_external libsodium.a) -build_external(sqlite3) -add_static_target(sqlite3 sqlite3_external libsqlite3.a) + +if(WITH_PEERSTATS_BACKEND) + build_external(sqlite3) + add_static_target(sqlite3 sqlite3_external libsqlite3.a) +endif() if(ARCH_TRIPLET MATCHES mingw) diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index c6dd5e6f6..f95543089 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -205,6 +205,11 @@ add_library(liblokinet service/tag.cpp ) +if(WITH_PEERSTATS_BACKEND) + target_compile_definitions(liblokinet PRIVATE -DLOKINET_PEERSTATS_BACKEND) + target_link_libraries(liblokinet PUBLIC sqlite_orm) +endif() + set_target_properties(liblokinet PROPERTIES OUTPUT_NAME lokinet) enable_lto(lokinet-util lokinet-platform liblokinet) @@ -227,7 +232,6 @@ target_link_libraries(liblokinet PUBLIC lokinet-platform lokinet-util lokinet-cryptography - sqlite_orm ngtcp2_static oxenmq::oxenmq) target_link_libraries(liblokinet PRIVATE libunbound) diff --git a/llarp/peerstats/peer_db.cpp b/llarp/peerstats/peer_db.cpp index 78e904137..91c9b2c6a 100644 --- a/llarp/peerstats/peer_db.cpp +++ b/llarp/peerstats/peer_db.cpp @@ -6,6 +6,8 @@ namespace llarp { +#ifdef LOKINET_PEERSTATS_BACKEND + PeerDb::PeerDb() { m_lastFlush.store({}); @@ -297,4 +299,66 @@ namespace llarp return obj; } +#else // !LOKINET_PEERSTATS + + // Empty stubs + + PeerDb::PeerDb() + { + throw std::logic_error{"Peer stats backend not enabled!"}; + } + + void PeerDb::loadDatabase(std::optional) + {} + + void + PeerDb::flushDatabase() + {} + + void + PeerDb::accumulatePeerStats(const RouterID&, const PeerStats&) + {} + + void + PeerDb::modifyPeerStats(const RouterID&, std::function) + {} + + std::optional + PeerDb::getCurrentPeerStats(const RouterID&) const + { + return std::nullopt; + } + + std::vector + PeerDb::listAllPeerStats() const + { + return {}; + } + + std::vector + PeerDb::listPeerStats(const std::vector&) const + { + return {}; + } + + void + PeerDb::handleGossipedRC(const RouterContact&, llarp_time_t) + {} + + void + PeerDb::configure(const RouterConfig& routerConfig) + {} + + bool + PeerDb::shouldFlush(llarp_time_t now) + {} + + util::StatusObject + PeerDb::ExtractStatus() const + { + return {}; + } + +#endif + }; // namespace llarp diff --git a/llarp/peerstats/peer_db.hpp b/llarp/peerstats/peer_db.hpp index b669b233c..d02430680 100644 --- a/llarp/peerstats/peer_db.hpp +++ b/llarp/peerstats/peer_db.hpp @@ -4,14 +4,15 @@ #include #include -#include - #include #include #include #include +#include #include "types.hpp" +#ifdef LOKINET_PEERSTATS_BACKEND #include "orm.hpp" +#endif namespace llarp { @@ -126,6 +127,7 @@ namespace llarp util::StatusObject ExtractStatus() const; +#ifdef LOKINET_PEERSTATS_BACKEND private: std::unordered_map m_peerStats; mutable std::mutex m_statsLock; @@ -133,6 +135,7 @@ namespace llarp std::unique_ptr m_storage; std::atomic m_lastFlush; +#endif }; } // namespace llarp