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.
pull/1942/head
Jason Rhinelander 2 years ago
parent 8c2f4175d6
commit 496c1d274c

@ -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)

@ -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)

@ -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)

@ -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<fs::path>)
{}
void
PeerDb::flushDatabase()
{}
void
PeerDb::accumulatePeerStats(const RouterID&, const PeerStats&)
{}
void
PeerDb::modifyPeerStats(const RouterID&, std::function<void(PeerStats&)>)
{}
std::optional<PeerStats>
PeerDb::getCurrentPeerStats(const RouterID&) const
{
return std::nullopt;
}
std::vector<PeerStats>
PeerDb::listAllPeerStats() const
{
return {};
}
std::vector<PeerStats>
PeerDb::listPeerStats(const std::vector<RouterID>&) 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

@ -4,14 +4,15 @@
#include <functional>
#include <unordered_map>
#include <sqlite_orm/sqlite_orm.h>
#include <llarp/util/fs.hpp>
#include <llarp/config/config.hpp>
#include <llarp/router_id.hpp>
#include <llarp/util/time.hpp>
#include <llarp/util/status.hpp>
#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<RouterID, PeerStats> m_peerStats;
mutable std::mutex m_statsLock;
@ -133,6 +135,7 @@ namespace llarp
std::unique_ptr<PeerDbStorage> m_storage;
std::atomic<llarp_time_t> m_lastFlush;
#endif
};
} // namespace llarp

Loading…
Cancel
Save