diff --git a/CMakeLists.txt b/CMakeLists.txt index c4995657..7ef21b3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,16 +63,16 @@ target_sources(clio PRIVATE ## Main src/main/impl/Build.cpp ## Backend - src/backend/BackendInterface.cpp - src/backend/LedgerCache.cpp - src/backend/cassandra/impl/Future.cpp - src/backend/cassandra/impl/Cluster.cpp - src/backend/cassandra/impl/Batch.cpp - src/backend/cassandra/impl/Result.cpp - src/backend/cassandra/impl/Tuple.cpp - src/backend/cassandra/impl/SslContext.cpp - src/backend/cassandra/Handle.cpp - src/backend/cassandra/SettingsProvider.cpp + src/data/BackendInterface.cpp + src/data/LedgerCache.cpp + src/data/cassandra/impl/Future.cpp + src/data/cassandra/impl/Cluster.cpp + src/data/cassandra/impl/Batch.cpp + src/data/cassandra/impl/Result.cpp + src/data/cassandra/impl/Tuple.cpp + src/data/cassandra/impl/SslContext.cpp + src/data/cassandra/Handle.cpp + src/data/cassandra/SettingsProvider.cpp ## ETL src/etl/Source.cpp src/etl/ProbingSource.cpp @@ -120,8 +120,8 @@ target_sources(clio PRIVATE src/rpc/handlers/TransactionEntry.cpp src/rpc/handlers/Tx.cpp ## Util - src/config/Config.cpp - src/log/Logger.cpp + src/util/config/Config.cpp + src/util/log/Logger.cpp src/util/Taggable.cpp) # Clio server @@ -135,75 +135,75 @@ if(tests) # Common unittests/Main.cpp unittests/Playground.cpp - unittests/Logger.cpp - unittests/Config.cpp - unittests/ProfilerTest.cpp - unittests/JsonUtilTest.cpp - unittests/DOSGuard.cpp - unittests/SubscriptionTest.cpp - unittests/SubscriptionManagerTest.cpp + unittests/LoggerTests.cpp + unittests/ConfigTests.cpp + unittests/ProfilerTests.cpp + unittests/JsonUtilTests.cpp + unittests/DOSGuardTests.cpp + unittests/SubscriptionTests.cpp + unittests/SubscriptionManagerTests.cpp unittests/util/TestObject.cpp unittests/util/StringUtils.cpp # ETL - unittests/etl/ExtractionDataPipeTest.cpp - unittests/etl/ExtractorTest.cpp - unittests/etl/TransformerTest.cpp - unittests/etl/CacheLoaderTest.cpp + unittests/etl/ExtractionDataPipeTests.cpp + unittests/etl/ExtractorTests.cpp + unittests/etl/TransformerTests.cpp + unittests/etl/CacheLoaderTests.cpp # RPC unittests/rpc/ErrorTests.cpp unittests/rpc/BaseTests.cpp - unittests/rpc/RPCHelpersTest.cpp - unittests/rpc/CountersTest.cpp - unittests/rpc/AdminVerificationTest.cpp + unittests/rpc/RPCHelpersTests.cpp + unittests/rpc/CountersTests.cpp + unittests/rpc/AdminVerificationTests.cpp unittests/rpc/APIVersionTests.cpp unittests/rpc/ForwardingProxyTests.cpp - unittests/rpc/WorkQueueTest.cpp - unittests/rpc/AmendmentsTest.cpp + unittests/rpc/WorkQueueTests.cpp + unittests/rpc/AmendmentsTests.cpp ## RPC handlers unittests/rpc/handlers/DefaultProcessorTests.cpp unittests/rpc/handlers/TestHandlerTests.cpp - unittests/rpc/handlers/AccountCurrenciesTest.cpp - unittests/rpc/handlers/AccountLinesTest.cpp - unittests/rpc/handlers/AccountTxTest.cpp - unittests/rpc/handlers/AccountOffersTest.cpp - unittests/rpc/handlers/AccountInfoTest.cpp - unittests/rpc/handlers/AccountChannelsTest.cpp - unittests/rpc/handlers/AccountNFTsTest.cpp - unittests/rpc/handlers/BookOffersTest.cpp - unittests/rpc/handlers/DepositAuthorizedTest.cpp - unittests/rpc/handlers/GatewayBalancesTest.cpp - unittests/rpc/handlers/TxTest.cpp - unittests/rpc/handlers/TransactionEntryTest.cpp - unittests/rpc/handlers/LedgerEntryTest.cpp - unittests/rpc/handlers/LedgerRangeTest.cpp - unittests/rpc/handlers/NoRippleCheckTest.cpp - unittests/rpc/handlers/ServerInfoTest.cpp - unittests/rpc/handlers/PingTest.cpp - unittests/rpc/handlers/RandomTest.cpp - unittests/rpc/handlers/NFTInfoTest.cpp - unittests/rpc/handlers/NFTBuyOffersTest.cpp - unittests/rpc/handlers/NFTSellOffersTest.cpp - unittests/rpc/handlers/NFTHistoryTest.cpp - unittests/rpc/handlers/SubscribeTest.cpp - unittests/rpc/handlers/UnsubscribeTest.cpp - unittests/rpc/handlers/LedgerDataTest.cpp - unittests/rpc/handlers/AccountObjectsTest.cpp - unittests/rpc/handlers/BookChangesTest.cpp - unittests/rpc/handlers/LedgerTest.cpp - unittests/rpc/handlers/VersionHandlerTest.cpp + unittests/rpc/handlers/AccountCurrenciesTests.cpp + unittests/rpc/handlers/AccountLinesTests.cpp + unittests/rpc/handlers/AccountTxTests.cpp + unittests/rpc/handlers/AccountOffersTests.cpp + unittests/rpc/handlers/AccountInfoTests.cpp + unittests/rpc/handlers/AccountChannelsTests.cpp + unittests/rpc/handlers/AccountNFTsTests.cpp + unittests/rpc/handlers/BookOffersTests.cpp + unittests/rpc/handlers/DepositAuthorizedTests.cpp + unittests/rpc/handlers/GatewayBalancesTests.cpp + unittests/rpc/handlers/TxTests.cpp + unittests/rpc/handlers/TransactionEntryTests.cpp + unittests/rpc/handlers/LedgerEntryTests.cpp + unittests/rpc/handlers/LedgerRangeTests.cpp + unittests/rpc/handlers/NoRippleCheckTests.cpp + unittests/rpc/handlers/ServerInfoTests.cpp + unittests/rpc/handlers/PingTests.cpp + unittests/rpc/handlers/RandomTests.cpp + unittests/rpc/handlers/NFTInfoTests.cpp + unittests/rpc/handlers/NFTBuyOffersTests.cpp + unittests/rpc/handlers/NFTSellOffersTests.cpp + unittests/rpc/handlers/NFTHistoryTests.cpp + unittests/rpc/handlers/SubscribeTests.cpp + unittests/rpc/handlers/UnsubscribeTests.cpp + unittests/rpc/handlers/LedgerDataTests.cpp + unittests/rpc/handlers/AccountObjectsTests.cpp + unittests/rpc/handlers/BookChangesTests.cpp + unittests/rpc/handlers/LedgerTests.cpp + unittests/rpc/handlers/VersionHandlerTests.cpp # Backend - unittests/backend/BackendFactoryTest.cpp - unittests/backend/cassandra/BaseTests.cpp - unittests/backend/cassandra/BackendTests.cpp - unittests/backend/cassandra/RetryPolicyTests.cpp - unittests/backend/cassandra/SettingsProviderTests.cpp - unittests/backend/cassandra/ExecutionStrategyTests.cpp - unittests/backend/cassandra/AsyncExecutorTests.cpp + unittests/data/BackendFactoryTests.cpp + unittests/data/cassandra/BaseTests.cpp + unittests/data/cassandra/BackendTests.cpp + unittests/data/cassandra/RetryPolicyTests.cpp + unittests/data/cassandra/SettingsProviderTests.cpp + unittests/data/cassandra/ExecutionStrategyTests.cpp + unittests/data/cassandra/AsyncExecutorTests.cpp # Webserver - unittests/webserver/ServerTest.cpp - unittests/webserver/RPCServerHandlerTest.cpp - unittests/webserver/WhitelistHandlerTest.cpp - unittests/webserver/SweepHandlerTest.cpp) + unittests/webserver/ServerTests.cpp + unittests/webserver/RPCServerHandlerTests.cpp + unittests/webserver/WhitelistHandlerTests.cpp + unittests/webserver/SweepHandlerTests.cpp) include(CMake/deps/gtest.cmake) diff --git a/src/backend/BackendFactory.h b/src/data/BackendFactory.h similarity index 82% rename from src/backend/BackendFactory.h rename to src/data/BackendFactory.h index 8910aaad..e5628d4b 100644 --- a/src/backend/BackendFactory.h +++ b/src/data/BackendFactory.h @@ -19,18 +19,18 @@ #pragma once -#include -#include -#include -#include +#include +#include +#include +#include #include -namespace Backend { +namespace data { std::shared_ptr -make_Backend(boost::asio::io_context& ioc, clio::Config const& config) +make_Backend(boost::asio::io_context& ioc, util::Config const& config) { - static clio::Logger log{"Backend"}; + static util::Logger log{"Backend"}; log.info() << "Constructing BackendInterface"; auto const readOnly = config.valueOr("read_only", false); @@ -42,8 +42,7 @@ make_Backend(boost::asio::io_context& ioc, clio::Config const& config) if (boost::iequals(type, "cassandra") or boost::iequals(type, "cassandra-new")) { auto cfg = config.section("database." + type); - backend = - std::make_shared(Backend::Cassandra::SettingsProvider{cfg}, readOnly); + backend = std::make_shared(data::cassandra::SettingsProvider{cfg}, readOnly); } if (!backend) @@ -59,4 +58,4 @@ make_Backend(boost::asio::io_context& ioc, clio::Config const& config) log.info() << "Constructed BackendInterface Successfully"; return backend; } -} // namespace Backend +} // namespace data diff --git a/src/backend/BackendInterface.cpp b/src/data/BackendInterface.cpp similarity index 98% rename from src/backend/BackendInterface.cpp rename to src/data/BackendInterface.cpp index 1c0130ba..7aa9e211 100644 --- a/src/backend/BackendInterface.cpp +++ b/src/data/BackendInterface.cpp @@ -17,20 +17,18 @@ */ //============================================================================== -#include -#include +#include +#include #include #include -using namespace clio; - // local to compilation unit loggers namespace { -clio::Logger gLog{"Backend"}; +util::Logger gLog{"Backend"}; } // namespace -namespace Backend { +namespace data { bool BackendInterface::finishWrites(std::uint32_t const ledgerSequence) { @@ -315,4 +313,4 @@ BackendInterface::fetchFees(std::uint32_t const seq, boost::asio::yield_context return fees; } -} // namespace Backend +} // namespace data diff --git a/src/backend/BackendInterface.h b/src/data/BackendInterface.h similarity index 98% rename from src/backend/BackendInterface.h rename to src/data/BackendInterface.h index b22c412a..8ba91f01 100644 --- a/src/backend/BackendInterface.h +++ b/src/data/BackendInterface.h @@ -19,11 +19,11 @@ #pragma once -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -33,7 +33,7 @@ #include #include -namespace Backend { +namespace data { /** * @brief Throws an error when database read time limit is exceeded. @@ -63,7 +63,7 @@ template auto retryOnTimeout(F func, size_t waitMs = 500) { - static clio::Logger log{"Backend"}; + static util::Logger log{"Backend"}; while (true) { @@ -548,5 +548,5 @@ private: doFinishWrites() = 0; }; -} // namespace Backend -using BackendInterface = Backend::BackendInterface; +} // namespace data +using BackendInterface = data::BackendInterface; diff --git a/src/backend/CassandraBackend.h b/src/data/CassandraBackend.h similarity index 98% rename from src/backend/CassandraBackend.h rename to src/data/CassandraBackend.h index 141a2c17..cb144589 100644 --- a/src/backend/CassandraBackend.h +++ b/src/data/CassandraBackend.h @@ -19,21 +19,21 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include +#include #include #include #include -namespace Backend::Cassandra { +namespace data::cassandra { /** * @brief Implements @ref BackendInterface for Cassandra/Scylladb @@ -47,7 +47,7 @@ namespace Backend::Cassandra { template class BasicCassandraBackend : public BackendInterface { - clio::Logger log_{"Backend"}; + util::Logger log_{"Backend"}; SettingsProviderType settingsProvider_; Schema schema_; @@ -820,4 +820,4 @@ private: using CassandraBackend = BasicCassandraBackend>; -} // namespace Backend::Cassandra +} // namespace data::cassandra diff --git a/src/backend/DBHelpers.h b/src/data/DBHelpers.h similarity index 99% rename from src/backend/DBHelpers.h rename to src/data/DBHelpers.h index b8f57c9a..6df7711c 100644 --- a/src/backend/DBHelpers.h +++ b/src/data/DBHelpers.h @@ -27,7 +27,7 @@ #include -#include +#include /** * @brief Struct used to keep track of what to write to account_transactions/account_tx tables diff --git a/src/backend/LedgerCache.cpp b/src/data/LedgerCache.cpp similarity index 98% rename from src/backend/LedgerCache.cpp rename to src/data/LedgerCache.cpp index ab65ec0a..af938b9a 100644 --- a/src/backend/LedgerCache.cpp +++ b/src/data/LedgerCache.cpp @@ -17,9 +17,9 @@ */ //============================================================================== -#include +#include -namespace Backend { +namespace data { uint32_t LedgerCache::latestLedgerSequence() const @@ -157,4 +157,4 @@ LedgerCache::getSuccessorHitRate() const return ((float)successorHitCounter_) / successorReqCounter_; } -} // namespace Backend +} // namespace data diff --git a/src/backend/LedgerCache.h b/src/data/LedgerCache.h similarity index 97% rename from src/backend/LedgerCache.h rename to src/data/LedgerCache.h index 7da33e41..577ff580 100644 --- a/src/backend/LedgerCache.h +++ b/src/data/LedgerCache.h @@ -21,14 +21,14 @@ #include #include -#include +#include #include #include #include #include #include -namespace Backend { +namespace data { class LedgerCache { @@ -95,4 +95,4 @@ public: getSuccessorHitRate() const; }; -} // namespace Backend +} // namespace data diff --git a/src/backend/README.md b/src/data/README.md similarity index 100% rename from src/backend/README.md rename to src/data/README.md diff --git a/src/backend/Types.h b/src/data/Types.h similarity index 99% rename from src/backend/Types.h rename to src/data/Types.h index 994a4b99..925e03c4 100644 --- a/src/backend/Types.h +++ b/src/data/Types.h @@ -25,7 +25,7 @@ #include #include -namespace Backend { +namespace data { // *** return types @@ -161,4 +161,4 @@ struct LedgerRange constexpr ripple::uint256 firstKey{"0000000000000000000000000000000000000000000000000000000000000000"}; constexpr ripple::uint256 lastKey{"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"}; constexpr ripple::uint256 hi192{"0000000000000000000000000000000000000000000000001111111111111111"}; -} // namespace Backend +} // namespace data diff --git a/src/backend/cassandra/Concepts.h b/src/data/cassandra/Concepts.h similarity index 96% rename from src/backend/cassandra/Concepts.h rename to src/data/cassandra/Concepts.h index ac2dc472..137dd95d 100644 --- a/src/backend/cassandra/Concepts.h +++ b/src/data/cassandra/Concepts.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include @@ -28,7 +28,7 @@ #include #include -namespace Backend::Cassandra { +namespace data::cassandra { // clang-format off template @@ -76,4 +76,4 @@ concept SomeRetryPolicy = requires(T a, boost::asio::io_context ioc, CassandraEr }; // clang-format on -} // namespace Backend::Cassandra +} // namespace data::cassandra diff --git a/src/backend/cassandra/Error.h b/src/data/cassandra/Error.h similarity index 97% rename from src/backend/cassandra/Error.h rename to src/data/cassandra/Error.h index 98ea00a1..8d844168 100644 --- a/src/backend/cassandra/Error.h +++ b/src/data/cassandra/Error.h @@ -23,7 +23,7 @@ #include -namespace Backend::Cassandra { +namespace data::cassandra { /** * @brief A simple container for both error message and error code @@ -96,4 +96,4 @@ public: } }; -} // namespace Backend::Cassandra +} // namespace data::cassandra diff --git a/src/backend/cassandra/Handle.cpp b/src/data/cassandra/Handle.cpp similarity index 97% rename from src/backend/cassandra/Handle.cpp rename to src/data/cassandra/Handle.cpp index 8cf193eb..74affd89 100644 --- a/src/backend/cassandra/Handle.cpp +++ b/src/data/cassandra/Handle.cpp @@ -17,9 +17,9 @@ */ //============================================================================== -#include +#include -namespace Backend::Cassandra { +namespace data::cassandra { Handle::Handle(Settings clusterSettings) : cluster_{clusterSettings} { @@ -152,4 +152,4 @@ Handle::prepare(std::string_view query) const throw std::runtime_error(rc.error().message()); } -} // namespace Backend::Cassandra +} // namespace data::cassandra diff --git a/src/backend/cassandra/Handle.h b/src/data/cassandra/Handle.h similarity index 94% rename from src/backend/cassandra/Handle.h rename to src/data/cassandra/Handle.h index 2f7577cd..675fb14e 100644 --- a/src/backend/cassandra/Handle.h +++ b/src/data/cassandra/Handle.h @@ -19,15 +19,15 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -37,7 +37,7 @@ #include #include -namespace Backend::Cassandra { +namespace data::cassandra { /** * @brief Represents a handle to the cassandra database cluster @@ -292,4 +292,4 @@ extract(Handle::ResultType const& result) return {result}; } -} // namespace Backend::Cassandra +} // namespace data::cassandra diff --git a/src/backend/cassandra/Schema.h b/src/data/cassandra/Schema.h similarity index 98% rename from src/backend/cassandra/Schema.h rename to src/data/cassandra/Schema.h index e706f2c1..69b3b424 100644 --- a/src/backend/cassandra/Schema.h +++ b/src/data/cassandra/Schema.h @@ -19,17 +19,17 @@ #pragma once -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include +#include +#include #include -namespace Backend::Cassandra { +namespace data::cassandra { template [[nodiscard]] std::string inline qualifiedTableName(SettingsProviderType const& provider, std::string_view name) @@ -48,7 +48,7 @@ class Schema // Migrations will be ran automatically based on this value. static constexpr uint16_t version = 1u; - clio::Logger log_{"Backend"}; + util::Logger log_{"Backend"}; std::reference_wrapper settingsProvider_; public: @@ -664,4 +664,4 @@ private: std::unique_ptr statements_{nullptr}; }; -} // namespace Backend::Cassandra +} // namespace data::cassandra diff --git a/src/backend/cassandra/SettingsProvider.cpp b/src/data/cassandra/SettingsProvider.cpp similarity index 94% rename from src/backend/cassandra/SettingsProvider.cpp rename to src/data/cassandra/SettingsProvider.cpp index 592b283d..37f4c3b7 100644 --- a/src/backend/cassandra/SettingsProvider.cpp +++ b/src/data/cassandra/SettingsProvider.cpp @@ -17,10 +17,10 @@ */ //============================================================================== -#include -#include -#include -#include +#include +#include +#include +#include #include @@ -28,7 +28,7 @@ #include #include -namespace Backend::Cassandra { +namespace data::cassandra { namespace detail { inline Settings::ContactPoints @@ -39,7 +39,7 @@ tag_invoke(boost::json::value_to_tag, boost::json::valu "Feed entire Cassandra section to parse " "Settings::ContactPoints instead"); - clio::Config obj{value}; + util::Config obj{value}; Settings::ContactPoints out; out.contactPoints = obj.valueOrThrow("contact_points", "`contact_points` must be a string"); @@ -57,7 +57,7 @@ tag_invoke(boost::json::value_to_tag, boost::j } } // namespace detail -SettingsProvider::SettingsProvider(clio::Config const& cfg, uint16_t ttl) +SettingsProvider::SettingsProvider(util::Config const& cfg, uint16_t ttl) : config_{cfg} , keyspace_{cfg.valueOr("keyspace", "clio")} , tablePrefix_{cfg.maybeValue("table_prefix")} @@ -148,4 +148,4 @@ SettingsProvider::parseSettings() const return settings; } -} // namespace Backend::Cassandra +} // namespace data::cassandra diff --git a/src/backend/cassandra/SettingsProvider.h b/src/data/cassandra/SettingsProvider.h similarity index 88% rename from src/backend/cassandra/SettingsProvider.h rename to src/data/cassandra/SettingsProvider.h index 4b9f9e25..d279e07f 100644 --- a/src/backend/cassandra/SettingsProvider.h +++ b/src/data/cassandra/SettingsProvider.h @@ -19,20 +19,20 @@ #pragma once -#include -#include -#include -#include +#include +#include #include +#include +#include -namespace Backend::Cassandra { +namespace data::cassandra { /** * @brief Provides settings for @ref CassandraBackend */ class SettingsProvider { - clio::Config config_; + util::Config config_; std::string keyspace_; std::optional tablePrefix_; @@ -41,7 +41,7 @@ class SettingsProvider Settings settings_; public: - explicit SettingsProvider(clio::Config const& cfg, uint16_t ttl = 0); + explicit SettingsProvider(util::Config const& cfg, uint16_t ttl = 0); /*! Get the cluster settings */ [[nodiscard]] Settings @@ -83,4 +83,4 @@ private: parseSettings() const; }; -} // namespace Backend::Cassandra +} // namespace data::cassandra diff --git a/src/backend/cassandra/Types.h b/src/data/cassandra/Types.h similarity index 96% rename from src/backend/cassandra/Types.h rename to src/data/cassandra/Types.h index 6abd2f29..b3deaa37 100644 --- a/src/backend/cassandra/Types.h +++ b/src/data/cassandra/Types.h @@ -23,7 +23,7 @@ #include -namespace Backend::Cassandra { +namespace data::cassandra { namespace detail { struct Settings; @@ -64,4 +64,4 @@ using MaybeError = util::Expected; using ResultOrError = util::Expected; using Error = util::Unexpected; -} // namespace Backend::Cassandra +} // namespace data::cassandra diff --git a/src/backend/cassandra/impl/AsyncExecutor.h b/src/data/cassandra/impl/AsyncExecutor.h similarity index 92% rename from src/backend/cassandra/impl/AsyncExecutor.h rename to src/data/cassandra/impl/AsyncExecutor.h index c17986ee..30cddfc5 100644 --- a/src/backend/cassandra/impl/AsyncExecutor.h +++ b/src/data/cassandra/impl/AsyncExecutor.h @@ -19,19 +19,19 @@ #pragma once -#include -#include -#include -#include -#include +#include +#include +#include +#include #include +#include #include #include #include -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { /** * @brief A query executor with a changable retry policy @@ -53,7 +53,7 @@ class AsyncExecutor : public std::enable_shared_from_this; - clio::Logger log_{"Backend"}; + util::Logger log_{"Backend"}; StatementType data_; RetryPolicyType retryPolicy_; @@ -116,4 +116,4 @@ private: } }; -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/Batch.cpp b/src/data/cassandra/impl/Batch.cpp similarity index 90% rename from src/backend/cassandra/impl/Batch.cpp rename to src/data/cassandra/impl/Batch.cpp index 751124fb..71a667b9 100644 --- a/src/backend/cassandra/impl/Batch.cpp +++ b/src/data/cassandra/impl/Batch.cpp @@ -17,9 +17,9 @@ */ //============================================================================== -#include -#include -#include +#include +#include +#include #include #include @@ -29,7 +29,7 @@ namespace { static constexpr auto batchDeleter = [](CassBatch* ptr) { cass_batch_free(ptr); }; }; -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { // todo: use an appropritae value instead of CASS_BATCH_TYPE_LOGGED for // different use cases @@ -53,4 +53,4 @@ Batch::add(Statement const& statement) return {}; } -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/Batch.h b/src/data/cassandra/impl/Batch.h similarity index 87% rename from src/backend/cassandra/impl/Batch.h rename to src/data/cassandra/impl/Batch.h index 26197d97..1f563b59 100644 --- a/src/backend/cassandra/impl/Batch.h +++ b/src/data/cassandra/impl/Batch.h @@ -19,12 +19,12 @@ #pragma once -#include -#include +#include +#include #include -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { struct Batch : public ManagedObject { @@ -34,4 +34,4 @@ struct Batch : public ManagedObject add(Statement const& statement); }; -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/Cluster.cpp b/src/data/cassandra/impl/Cluster.cpp similarity index 97% rename from src/backend/cassandra/impl/Cluster.cpp rename to src/data/cassandra/impl/Cluster.cpp index 4d5fc949..70400904 100644 --- a/src/backend/cassandra/impl/Cluster.cpp +++ b/src/data/cassandra/impl/Cluster.cpp @@ -17,9 +17,9 @@ */ //============================================================================== -#include -#include -#include +#include +#include +#include #include #include @@ -41,7 +41,7 @@ template overloadSet(Ts...) -> overloadSet; }; // namespace -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { Cluster::Cluster(Settings const& settings) : ManagedObject{cass_cluster_new(), clusterDeleter} { @@ -221,4 +221,4 @@ Cluster::setupCredentials(Settings const& settings) cass_cluster_set_credentials(*this, settings.username.value().c_str(), settings.password.value().c_str()); } -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/Cluster.h b/src/data/cassandra/impl/Cluster.h similarity index 94% rename from src/backend/cassandra/impl/Cluster.h rename to src/data/cassandra/impl/Cluster.h index 18637562..dc807ade 100644 --- a/src/backend/cassandra/impl/Cluster.h +++ b/src/data/cassandra/impl/Cluster.h @@ -19,8 +19,8 @@ #pragma once -#include -#include +#include +#include #include @@ -31,7 +31,7 @@ #include #include -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { struct Settings { @@ -86,7 +86,7 @@ struct Settings class Cluster : public ManagedObject { - clio::Logger log_{"Backend"}; + util::Logger log_{"Backend"}; public: Cluster(Settings const& settings); @@ -108,4 +108,4 @@ private: setupCredentials(Settings const& settings); }; -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/ExecutionStrategy.h b/src/data/cassandra/impl/ExecutionStrategy.h similarity index 98% rename from src/backend/cassandra/impl/ExecutionStrategy.h rename to src/data/cassandra/impl/ExecutionStrategy.h index f35e9140..29c079a1 100644 --- a/src/backend/cassandra/impl/ExecutionStrategy.h +++ b/src/data/cassandra/impl/ExecutionStrategy.h @@ -19,11 +19,11 @@ #pragma once -#include -#include -#include -#include +#include +#include +#include #include +#include #include #include @@ -36,7 +36,7 @@ #include #include -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { /** * @brief Implements async and sync querying against the cassandra DB with @@ -48,7 +48,7 @@ namespace Backend::Cassandra::detail { template class DefaultExecutionStrategy { - clio::Logger log_{"Backend"}; + util::Logger log_{"Backend"}; std::uint32_t maxWriteRequestsOutstanding_; std::atomic_uint32_t numWriteRequestsOutstanding_ = 0; @@ -448,4 +448,4 @@ private: } }; -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/Future.cpp b/src/data/cassandra/impl/Future.cpp similarity index 94% rename from src/backend/cassandra/impl/Future.cpp rename to src/data/cassandra/impl/Future.cpp index 2edaa74c..ef01b719 100644 --- a/src/backend/cassandra/impl/Future.cpp +++ b/src/data/cassandra/impl/Future.cpp @@ -17,9 +17,9 @@ */ //============================================================================== -#include -#include -#include +#include +#include +#include #include #include @@ -28,7 +28,7 @@ namespace { static constexpr auto futureDeleter = [](CassFuture* ptr) { cass_future_free(ptr); }; } // namespace -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { /* implicit */ Future::Future(CassFuture* ptr) : ManagedObject{ptr, futureDeleter} { @@ -100,4 +100,4 @@ invokeHelper(CassFuture* ptr, void* cbPtr) cass_future_set_callback(*this, &invokeHelper, cb_.get()); } -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/Future.h b/src/data/cassandra/impl/Future.h similarity index 91% rename from src/backend/cassandra/impl/Future.h rename to src/data/cassandra/impl/Future.h index f11db9fc..b2a1c338 100644 --- a/src/backend/cassandra/impl/Future.h +++ b/src/data/cassandra/impl/Future.h @@ -19,12 +19,12 @@ #pragma once -#include -#include +#include +#include #include -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { struct Future : public ManagedObject { @@ -55,4 +55,4 @@ private: fn_ptr_t cb_; }; -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/ManagedObject.h b/src/data/cassandra/impl/ManagedObject.h similarity index 95% rename from src/backend/cassandra/impl/ManagedObject.h rename to src/data/cassandra/impl/ManagedObject.h index 565529d6..e54e3a40 100644 --- a/src/backend/cassandra/impl/ManagedObject.h +++ b/src/data/cassandra/impl/ManagedObject.h @@ -21,7 +21,7 @@ #include -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { template class ManagedObject @@ -44,4 +44,4 @@ public: } }; -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/Result.cpp b/src/data/cassandra/impl/Result.cpp similarity index 94% rename from src/backend/cassandra/impl/Result.cpp rename to src/data/cassandra/impl/Result.cpp index 2596ceba..8efb3021 100644 --- a/src/backend/cassandra/impl/Result.cpp +++ b/src/data/cassandra/impl/Result.cpp @@ -17,14 +17,14 @@ */ //============================================================================== -#include +#include namespace { static constexpr auto resultDeleter = [](CassResult const* ptr) { cass_result_free(ptr); }; static constexpr auto resultIteratorDeleter = [](CassIterator* ptr) { cass_iterator_free(ptr); }; } // namespace -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { /* implicit */ Result::Result(CassResult const* ptr) : ManagedObject{ptr, resultDeleter} { @@ -66,4 +66,4 @@ ResultIterator::hasMore() const return hasMore_; } -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/Result.h b/src/data/cassandra/impl/Result.h similarity index 97% rename from src/backend/cassandra/impl/Result.h rename to src/data/cassandra/impl/Result.h index b870ac18..b9b12ead 100644 --- a/src/backend/cassandra/impl/Result.h +++ b/src/data/cassandra/impl/Result.h @@ -19,8 +19,8 @@ #pragma once -#include -#include +#include +#include #include #include @@ -31,7 +31,7 @@ #include #include -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { template static constexpr bool unsupported_v = false; @@ -254,4 +254,4 @@ public: } }; -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/RetryPolicy.h b/src/data/cassandra/impl/RetryPolicy.h similarity index 92% rename from src/backend/cassandra/impl/RetryPolicy.h rename to src/data/cassandra/impl/RetryPolicy.h index 8ade4c9b..ee85dfad 100644 --- a/src/backend/cassandra/impl/RetryPolicy.h +++ b/src/data/cassandra/impl/RetryPolicy.h @@ -19,10 +19,10 @@ #pragma once -#include -#include -#include +#include +#include #include +#include #include @@ -30,14 +30,14 @@ #include #include -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { /** * @brief A retry policy that employs exponential backoff */ class ExponentialBackoffRetryPolicy { - clio::Logger log_{"Backend"}; + util::Logger log_{"Backend"}; boost::asio::steady_timer timer_; uint32_t attempt_ = 0u; @@ -91,4 +91,4 @@ public: } }; -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/Session.h b/src/data/cassandra/impl/Session.h similarity index 90% rename from src/backend/cassandra/impl/Session.h rename to src/data/cassandra/impl/Session.h index 9becb1ab..dcb79d8e 100644 --- a/src/backend/cassandra/impl/Session.h +++ b/src/data/cassandra/impl/Session.h @@ -19,11 +19,11 @@ #pragma once -#include +#include #include -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { class Session : public ManagedObject { @@ -35,4 +35,4 @@ public: } }; -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/SslContext.cpp b/src/data/cassandra/impl/SslContext.cpp similarity index 92% rename from src/backend/cassandra/impl/SslContext.cpp rename to src/data/cassandra/impl/SslContext.cpp index baadb619..b4e86294 100644 --- a/src/backend/cassandra/impl/SslContext.cpp +++ b/src/data/cassandra/impl/SslContext.cpp @@ -17,13 +17,13 @@ */ //============================================================================== -#include +#include namespace { static constexpr auto contextDeleter = [](CassSsl* ptr) { cass_ssl_free(ptr); }; } // namespace -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { SslContext::SslContext(std::string const& certificate) : ManagedObject{cass_ssl_new(), contextDeleter} { @@ -34,4 +34,4 @@ SslContext::SslContext(std::string const& certificate) : ManagedObject{cass_ssl_ } } -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/SslContext.h b/src/data/cassandra/impl/SslContext.h similarity index 90% rename from src/backend/cassandra/impl/SslContext.h rename to src/data/cassandra/impl/SslContext.h index 3f551b83..e82b2252 100644 --- a/src/backend/cassandra/impl/SslContext.h +++ b/src/data/cassandra/impl/SslContext.h @@ -19,17 +19,17 @@ #pragma once -#include +#include #include #include -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { struct SslContext : public ManagedObject { explicit SslContext(std::string const& certificate); }; -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/Statement.h b/src/data/cassandra/impl/Statement.h similarity index 96% rename from src/backend/cassandra/impl/Statement.h rename to src/data/cassandra/impl/Statement.h index 1f8d2895..8f242f8f 100644 --- a/src/backend/cassandra/impl/Statement.h +++ b/src/data/cassandra/impl/Statement.h @@ -19,9 +19,9 @@ #pragma once -#include -#include -#include +#include +#include +#include #include #include @@ -33,7 +33,7 @@ #include #include -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { class Statement : public ManagedObject { @@ -161,4 +161,4 @@ public: } }; -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/Tuple.cpp b/src/data/cassandra/impl/Tuple.cpp similarity index 92% rename from src/backend/cassandra/impl/Tuple.cpp rename to src/data/cassandra/impl/Tuple.cpp index 990903b2..56932e91 100644 --- a/src/backend/cassandra/impl/Tuple.cpp +++ b/src/data/cassandra/impl/Tuple.cpp @@ -17,14 +17,14 @@ */ //============================================================================== -#include +#include namespace { static constexpr auto tupleDeleter = [](CassTuple* ptr) { cass_tuple_free(ptr); }; static constexpr auto tupleIteratorDeleter = [](CassIterator* ptr) { cass_iterator_free(ptr); }; } // namespace -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { /* implicit */ Tuple::Tuple(CassTuple* ptr) : ManagedObject{ptr, tupleDeleter} { @@ -40,4 +40,4 @@ TupleIterator::fromTuple(CassValue const* value) return {cass_iterator_from_tuple(value)}; } -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/backend/cassandra/impl/Tuple.h b/src/data/cassandra/impl/Tuple.h similarity index 97% rename from src/backend/cassandra/impl/Tuple.h rename to src/data/cassandra/impl/Tuple.h index cf24bfe1..ffe729a3 100644 --- a/src/backend/cassandra/impl/Tuple.h +++ b/src/data/cassandra/impl/Tuple.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include @@ -28,7 +28,7 @@ #include #include -namespace Backend::Cassandra::detail { +namespace data::cassandra::detail { class Tuple : public ManagedObject { @@ -146,4 +146,4 @@ private: } }; -} // namespace Backend::Cassandra::detail +} // namespace data::cassandra::detail diff --git a/src/etl/ETLService.cpp b/src/etl/ETLService.cpp index f8c7e32a..6b693201 100644 --- a/src/etl/ETLService.cpp +++ b/src/etl/ETLService.cpp @@ -21,8 +21,6 @@ #include -using namespace clio; - // Database must be populated when this starts std::optional ETLService::runETLPipeline(uint32_t startSequence, uint32_t numExtractors) @@ -247,7 +245,7 @@ ETLService::doWork() } ETLService::ETLService( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioc, std::shared_ptr backend, std::shared_ptr subscriptions, diff --git a/src/etl/ETLService.h b/src/etl/ETLService.h index e6257607..0ef8b801 100644 --- a/src/etl/ETLService.h +++ b/src/etl/ETLService.h @@ -19,8 +19,8 @@ #pragma once -#include -#include +#include +#include #include #include #include @@ -31,8 +31,8 @@ #include #include #include -#include #include +#include #include #include @@ -63,15 +63,15 @@ class ETLService using SubscriptionManagerType = SubscriptionManager; using LoadBalancerType = LoadBalancer; using NetworkValidatedLedgersType = NetworkValidatedLedgers; - using DataPipeType = clio::detail::ExtractionDataPipe; - using CacheLoaderType = clio::detail::CacheLoader; - using LedgerFetcherType = clio::detail::LedgerFetcher; - using ExtractorType = clio::detail::Extractor; - using LedgerLoaderType = clio::detail::LedgerLoader; - using LedgerPublisherType = clio::detail::LedgerPublisher; - using TransformerType = clio::detail::Transformer; + using DataPipeType = etl::detail::ExtractionDataPipe; + using CacheLoaderType = etl::detail::CacheLoader; + using LedgerFetcherType = etl::detail::LedgerFetcher; + using ExtractorType = etl::detail::Extractor; + using LedgerLoaderType = etl::detail::LedgerLoader; + using LedgerPublisherType = etl::detail::LedgerPublisher; + using TransformerType = etl::detail::Transformer; - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; std::shared_ptr backend_; std::shared_ptr loadBalancer_; @@ -104,7 +104,7 @@ public: * @param ledgers The network validated ledgers datastructure */ ETLService( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioc, std::shared_ptr backend, std::shared_ptr subscriptions, @@ -113,7 +113,7 @@ public: static std::shared_ptr make_ETLService( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioc, std::shared_ptr backend, std::shared_ptr subscriptions, diff --git a/src/etl/LoadBalancer.cpp b/src/etl/LoadBalancer.cpp index f159b8f6..d400001e 100644 --- a/src/etl/LoadBalancer.cpp +++ b/src/etl/LoadBalancer.cpp @@ -17,14 +17,14 @@ */ //============================================================================== -#include +#include #include #include #include #include -#include #include #include +#include #include #include @@ -36,11 +36,11 @@ #include -using namespace clio; +using namespace util; std::unique_ptr LoadBalancer::make_Source( - clio::Config const& config, + Config const& config, boost::asio::io_context& ioContext, std::shared_ptr backend, std::shared_ptr subscriptions, @@ -57,7 +57,7 @@ LoadBalancer::make_Source( std::shared_ptr LoadBalancer::make_LoadBalancer( - clio::Config const& config, + Config const& config, boost::asio::io_context& ioc, std::shared_ptr backend, std::shared_ptr subscriptions, @@ -67,7 +67,7 @@ LoadBalancer::make_LoadBalancer( } LoadBalancer::LoadBalancer( - clio::Config const& config, + Config const& config, boost::asio::io_context& ioContext, std::shared_ptr backend, std::shared_ptr subscriptions, diff --git a/src/etl/LoadBalancer.h b/src/etl/LoadBalancer.h index 794f14ee..b96faba8 100644 --- a/src/etl/LoadBalancer.h +++ b/src/etl/LoadBalancer.h @@ -19,11 +19,11 @@ #pragma once -#include -#include +#include #include -#include #include +#include +#include #include #include @@ -48,7 +48,7 @@ public: using OptionalGetLedgerResponseType = std::optional; private: - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; std::vector> sources_; std::uint32_t downloadRanges_ = 16; @@ -63,7 +63,7 @@ public: * @param nwvl The network validated ledgers datastructure */ LoadBalancer( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioContext, std::shared_ptr backend, std::shared_ptr subscriptions, @@ -71,7 +71,7 @@ public: static std::shared_ptr make_LoadBalancer( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioc, std::shared_ptr backend, std::shared_ptr subscriptions, @@ -79,7 +79,7 @@ public: static std::unique_ptr make_Source( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioContext, std::shared_ptr backend, std::shared_ptr subscriptions, diff --git a/src/etl/NFTHelpers.cpp b/src/etl/NFTHelpers.cpp index b7923d6a..1798a7e0 100644 --- a/src/etl/NFTHelpers.cpp +++ b/src/etl/NFTHelpers.cpp @@ -22,9 +22,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include std::pair, std::optional> diff --git a/src/etl/NFTHelpers.h b/src/etl/NFTHelpers.h index 92314b82..f3e8fde8 100644 --- a/src/etl/NFTHelpers.h +++ b/src/etl/NFTHelpers.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include diff --git a/src/etl/ProbingSource.cpp b/src/etl/ProbingSource.cpp index e8f2dc46..fb3766fd 100644 --- a/src/etl/ProbingSource.cpp +++ b/src/etl/ProbingSource.cpp @@ -18,12 +18,9 @@ //============================================================================== #include -#include - -using namespace clio; ProbingSource::ProbingSource( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioc, std::shared_ptr backend, std::shared_ptr subscriptions, @@ -199,4 +196,4 @@ ProbingSource::make_PlainHooks() noexcept } return SourceHooks::Action::STOP; }}; -} +}; diff --git a/src/etl/ProbingSource.h b/src/etl/ProbingSource.h index 08e2151b..d46c08e5 100644 --- a/src/etl/ProbingSource.h +++ b/src/etl/ProbingSource.h @@ -19,9 +19,9 @@ #pragma once -#include #include -#include +#include +#include #include #include @@ -44,7 +44,7 @@ public: using GetLedgerResponseType = org::xrpl::rpc::v1::GetLedgerResponse; private: - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; std::mutex mtx_; boost::asio::ssl::context sslCtx_; @@ -65,7 +65,7 @@ public: * @param sslCtx The SSL context to use; defaults to tlsv12 */ ProbingSource( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioc, std::shared_ptr backend, std::shared_ptr subscriptions, diff --git a/src/etl/Source.cpp b/src/etl/Source.cpp index 9f41a594..fb12f27d 100644 --- a/src/etl/Source.cpp +++ b/src/etl/Source.cpp @@ -17,12 +17,11 @@ */ //============================================================================== -#include +#include #include #include #include #include -#include #include #include @@ -35,8 +34,6 @@ #include -using namespace clio; - static boost::beast::websocket::stream_base::timeout make_TimeoutOption() { diff --git a/src/etl/Source.h b/src/etl/Source.h index 0819dc0a..6f37320a 100644 --- a/src/etl/Source.h +++ b/src/etl/Source.h @@ -19,14 +19,14 @@ #pragma once -#include -#include +#include #include #include #include #include -#include #include +#include +#include #include #include @@ -97,10 +97,10 @@ public: } protected: - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; private: - friend clio::detail::ForwardCache; + friend etl::detail::ForwardCache; friend ProbingSource; virtual std::optional @@ -148,7 +148,7 @@ class SourceImpl : public Source std::shared_ptr subscriptions_; LoadBalancer& balancer_; - clio::detail::ForwardCache forwardCache_; + etl::detail::ForwardCache forwardCache_; boost::uuids::uuid uuid_; protected: @@ -176,7 +176,7 @@ public: * Primarly used in read-only mode, to monitor when ledgers are validated. */ SourceImpl( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioContext, std::shared_ptr backend, std::shared_ptr subscriptions, @@ -494,7 +494,7 @@ public: grpc::CompletionQueue cq; void* tag; bool ok = false; - std::vector calls; + std::vector calls; auto markers = getMarkers(numMarkers); for (size_t i = 0; i < markers.size(); ++i) @@ -521,7 +521,7 @@ public: while (numFinished < calls.size() && cq.Next(&tag, &ok)) { assert(tag); - auto ptr = static_cast(tag); + auto ptr = static_cast(tag); if (!ok) { @@ -533,7 +533,7 @@ public: log_.trace() << "Marker prefix = " << ptr->getMarkerPrefix(); auto result = ptr->process(stub_, cq, *backend_, abort, cacheOnly); - if (result != clio::detail::AsyncCallData::CallStatus::MORE) + if (result != etl::detail::AsyncCallData::CallStatus::MORE) { ++numFinished; log_.debug() << "Finished a marker. " @@ -545,7 +545,7 @@ public: edgeKeys.push_back(ptr->getLastKey()); } - if (result == clio::detail::AsyncCallData::CallStatus::ERRORED) + if (result == etl::detail::AsyncCallData::CallStatus::ERRORED) abort = true; if (backend_->cache().size() > progress) @@ -569,7 +569,7 @@ public: if (paused_) return; - if (connected_) + if (isConnected()) hooks_.onDisconnected(ec); connected_ = false; @@ -836,7 +836,7 @@ class PlainSource : public SourceImpl public: PlainSource( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioc, std::shared_ptr backend, std::shared_ptr subscriptions, @@ -876,7 +876,7 @@ class SslSource : public SourceImpl public: SslSource( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioc, std::optional> sslCtx, std::shared_ptr backend, diff --git a/src/etl/impl/AsyncData.h b/src/etl/impl/AsyncData.h index e15442f0..70e0c995 100644 --- a/src/etl/impl/AsyncData.h +++ b/src/etl/impl/AsyncData.h @@ -20,16 +20,16 @@ #pragma once #include -#include +#include #include #include -namespace clio::detail { +namespace etl::detail { class AsyncCallData { - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; std::unique_ptr cur_; std::unique_ptr next_; @@ -120,7 +120,7 @@ public: auto const numObjects = cur_->ledger_objects().objects_size(); log_.debug() << "Writing " << numObjects << " objects"; - std::vector cacheUpdates; + std::vector cacheUpdates; cacheUpdates.reserve(numObjects); for (int i = 0; i < numObjects; ++i) @@ -179,4 +179,4 @@ public: } }; -} // namespace clio::detail +} // namespace etl::detail diff --git a/src/etl/impl/CacheLoader.h b/src/etl/impl/CacheLoader.h index 6c48a603..4b4b3363 100644 --- a/src/etl/impl/CacheLoader.h +++ b/src/etl/impl/CacheLoader.h @@ -19,8 +19,8 @@ #pragma once -#include -#include +#include +#include #include #include @@ -34,7 +34,7 @@ #include #include -namespace clio::detail { +namespace etl::detail { /** * @brief Cache loading interface @@ -44,7 +44,7 @@ class CacheLoader { enum class LoadStyle { ASYNC, SYNC, NOT_AT_ALL }; - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; std::reference_wrapper ioContext_; std::shared_ptr backend_; @@ -73,7 +73,7 @@ class CacheLoader public: CacheLoader( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioc, std::shared_ptr const& backend, CacheType& ledgerCache) @@ -300,13 +300,13 @@ private: auto const& state = response.at("state").as_array(); - std::vector objects; + std::vector objects; objects.reserve(state.size()); for (auto const& ledgerObject : state) { auto const& obj = ledgerObject.as_object(); - Backend::LedgerObject stateObject = {}; + data::LedgerObject stateObject = {}; if (!stateObject.key.parseHex(obj.at("index").as_string().c_str())) { @@ -337,14 +337,14 @@ private: void loadCacheFromDb(uint32_t seq) { - std::vector diff; + std::vector diff; std::vector> cursors; auto append = [](auto&& a, auto&& b) { a.insert(std::end(a), std::begin(b), std::end(b)); }; for (size_t i = 0; i < numCacheDiffs_; ++i) { - append(diff, Backend::synchronousAndRetryOnTimeout([&](auto yield) { + append(diff, data::synchronousAndRetryOnTimeout([&](auto yield) { return backend_->fetchLedgerDiff(seq - i, yield); })); } @@ -387,12 +387,12 @@ private: [this, seq, start, end, numRemaining, startTime, markers](boost::asio::yield_context yield) { std::optional cursor = start; std::string cursorStr = - cursor.has_value() ? ripple::strHex(cursor.value()) : ripple::strHex(Backend::firstKey); + cursor.has_value() ? ripple::strHex(cursor.value()) : ripple::strHex(data::firstKey); log_.debug() << "Starting a cursor: " << cursorStr << " markers = " << *markers; while (not stopping_) { - auto res = Backend::retryOnTimeout([this, seq, &cursor, &yield]() { + auto res = data::retryOnTimeout([this, seq, &cursor, &yield]() { return backend_->fetchLedgerPage(cursor, seq, cachePageFetchSize_, false, yield); }); @@ -431,4 +431,4 @@ private: } }; -} // namespace clio::detail +} // namespace etl::detail diff --git a/src/etl/impl/ExtractionDataPipe.h b/src/etl/impl/ExtractionDataPipe.h index a9f66a99..65060579 100644 --- a/src/etl/impl/ExtractionDataPipe.h +++ b/src/etl/impl/ExtractionDataPipe.h @@ -20,12 +20,12 @@ #pragma once #include -#include +#include #include #include -namespace clio::detail { +namespace etl::detail { /** * @brief A collection of thread safe async queues used by Extractor and Transformer to communicate @@ -40,7 +40,7 @@ public: constexpr static auto TOTAL_MAX_IN_QUEUE = 1000u; private: - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; uint32_t stride_; uint32_t startSequence_; @@ -131,4 +131,4 @@ private: } }; -} // namespace clio::detail +} // namespace etl::detail diff --git a/src/etl/impl/Extractor.h b/src/etl/impl/Extractor.h index 297f2458..e3b4a9e4 100644 --- a/src/etl/impl/Extractor.h +++ b/src/etl/impl/Extractor.h @@ -20,8 +20,8 @@ #pragma once #include -#include #include +#include #include @@ -29,7 +29,7 @@ #include #include -namespace clio::detail { +namespace etl::detail { /** * @brief Extractor thread that is fetching GRPC data and enqueue it on the DataPipeType @@ -37,7 +37,7 @@ namespace clio::detail { template class Extractor { - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; std::reference_wrapper pipe_; std::shared_ptr networkValidatedLedgers_; @@ -90,7 +90,7 @@ private: while (!shouldFinish(currentSequence) && networkValidatedLedgers_->waitUntilValidatedByNetwork(currentSequence)) { - auto [fetchResponse, time] = util::timed>( + auto [fetchResponse, time] = ::util::timed>( [this, currentSequence]() { return ledgerFetcher_.get().fetchDataAndDiff(currentSequence); }); totalTime += time; @@ -137,4 +137,4 @@ private: } }; -} // namespace clio::detail +} // namespace etl::detail diff --git a/src/etl/impl/ForwardCache.cpp b/src/etl/impl/ForwardCache.cpp index a3d7729f..af5fcf22 100644 --- a/src/etl/impl/ForwardCache.cpp +++ b/src/etl/impl/ForwardCache.cpp @@ -24,7 +24,7 @@ #include #include -namespace clio::detail { +namespace etl::detail { void ForwardCache::freshen() @@ -80,4 +80,4 @@ ForwardCache::get(boost::json::object const& request) const return {latestForwarded_.at(*command)}; } -} // namespace clio::detail +} // namespace etl::detail diff --git a/src/etl/impl/ForwardCache.h b/src/etl/impl/ForwardCache.h index 9f7ed1a9..af96887e 100644 --- a/src/etl/impl/ForwardCache.h +++ b/src/etl/impl/ForwardCache.h @@ -19,10 +19,10 @@ #pragma once -#include -#include +#include #include -#include +#include +#include #include #include @@ -33,7 +33,7 @@ class Source; -namespace clio::detail { +namespace etl::detail { /** * @brief Cache for rippled responses @@ -42,19 +42,19 @@ class ForwardCache { using ResponseType = std::optional; - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; mutable std::shared_mutex mtx_; std::unordered_map latestForwarded_; boost::asio::strand strand_; - Source const& source_; + ::Source const& source_; std::uint32_t duration_ = 10; void clear(); public: - ForwardCache(clio::Config const& config, boost::asio::io_context& ioc, Source const& source) + ForwardCache(util::Config const& config, boost::asio::io_context& ioc, Source const& source) : strand_(boost::asio::make_strand(ioc)), source_(source) { if (config.contains("cache")) @@ -79,4 +79,4 @@ public: get(boost::json::object const& command) const; }; -} // namespace clio::detail +} // namespace etl::detail diff --git a/src/etl/impl/LedgerFetcher.h b/src/etl/impl/LedgerFetcher.h index 35cec876..500df0a3 100644 --- a/src/etl/impl/LedgerFetcher.h +++ b/src/etl/impl/LedgerFetcher.h @@ -19,16 +19,16 @@ #pragma once -#include +#include #include -#include +#include #include #include #include -namespace clio::detail { +namespace etl::detail { /** * @brief GRPC Ledger data fetcher @@ -40,7 +40,7 @@ public: using OptionalGetLedgerResponseType = typename LoadBalancerType::OptionalGetLedgerResponseType; private: - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; std::shared_ptr backend_; std::shared_ptr loadBalancer_; @@ -98,4 +98,4 @@ public: } }; -} // namespace clio::detail +} // namespace etl::detail diff --git a/src/etl/impl/LedgerLoader.h b/src/etl/impl/LedgerLoader.h index 10a51da4..28578d17 100644 --- a/src/etl/impl/LedgerLoader.h +++ b/src/etl/impl/LedgerLoader.h @@ -19,13 +19,13 @@ #pragma once -#include +#include #include #include #include -#include #include #include +#include #include @@ -38,7 +38,7 @@ struct FormattedTransactionsData std::vector nfTokensData; }; -namespace clio::detail { +namespace etl::detail { /** * @brief Loads ledger data into the DB @@ -52,7 +52,7 @@ public: using RawLedgerObjectType = typename LoadBalancerType::RawLedgerObjectType; private: - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; std::shared_ptr backend_; std::shared_ptr loadBalancer_; @@ -157,11 +157,11 @@ public: if (!ledgerData) return {}; - ripple::LedgerHeader lgrInfo = util::deserializeHeader(ripple::makeSlice(ledgerData->ledger_header())); + ripple::LedgerHeader lgrInfo = ::util::deserializeHeader(ripple::makeSlice(ledgerData->ledger_header())); - log_.debug() << "Deserialized ledger header. " << util::toString(lgrInfo); + log_.debug() << "Deserialized ledger header. " << ::util::toString(lgrInfo); - auto timeDiff = util::timed>([this, sequence, &lgrInfo, &ledgerData]() { + auto timeDiff = ::util::timed>([this, sequence, &lgrInfo, &ledgerData]() { backend_->startWrites(); log_.debug() << "Started writes"; @@ -184,51 +184,53 @@ public: size_t numWrites = 0; backend_->cache().setFull(); - auto seconds = util::timed([this, edgeKeys = &edgeKeys, sequence, &numWrites]() { - for (auto& key : *edgeKeys) - { - log_.debug() << "Writing edge key = " << ripple::strHex(key); - auto succ = backend_->cache().getSuccessor(*ripple::uint256::fromVoidChecked(key), sequence); - if (succ) - backend_->writeSuccessor(std::move(key), sequence, uint256ToString(succ->key)); - } - - ripple::uint256 prev = Backend::firstKey; - while (auto cur = backend_->cache().getSuccessor(prev, sequence)) - { - assert(cur); - if (prev == Backend::firstKey) - backend_->writeSuccessor(uint256ToString(prev), sequence, uint256ToString(cur->key)); - - if (isBookDir(cur->key, cur->blob)) + auto seconds = + ::util::timed([this, edgeKeys = &edgeKeys, sequence, &numWrites]() { + for (auto& key : *edgeKeys) { - auto base = getBookBase(cur->key); - // make sure the base is not an actual object - if (!backend_->cache().get(cur->key, sequence)) - { - auto succ = backend_->cache().getSuccessor(base, sequence); - assert(succ); - if (succ->key == cur->key) - { - log_.debug() << "Writing book successor = " << ripple::strHex(base) << " - " - << ripple::strHex(cur->key); - - backend_->writeSuccessor( - uint256ToString(base), sequence, uint256ToString(cur->key)); - } - } - - ++numWrites; + log_.debug() << "Writing edge key = " << ripple::strHex(key); + auto succ = + backend_->cache().getSuccessor(*ripple::uint256::fromVoidChecked(key), sequence); + if (succ) + backend_->writeSuccessor(std::move(key), sequence, uint256ToString(succ->key)); } - prev = std::move(cur->key); - if (numWrites % 100000 == 0 && numWrites != 0) - log_.info() << "Wrote " << numWrites << " book successors"; - } + ripple::uint256 prev = data::firstKey; + while (auto cur = backend_->cache().getSuccessor(prev, sequence)) + { + assert(cur); + if (prev == data::firstKey) + backend_->writeSuccessor(uint256ToString(prev), sequence, uint256ToString(cur->key)); - backend_->writeSuccessor(uint256ToString(prev), sequence, uint256ToString(Backend::lastKey)); - ++numWrites; - }); + if (isBookDir(cur->key, cur->blob)) + { + auto base = getBookBase(cur->key); + // make sure the base is not an actual object + if (!backend_->cache().get(cur->key, sequence)) + { + auto succ = backend_->cache().getSuccessor(base, sequence); + assert(succ); + if (succ->key == cur->key) + { + log_.debug() << "Writing book successor = " << ripple::strHex(base) << " - " + << ripple::strHex(cur->key); + + backend_->writeSuccessor( + uint256ToString(base), sequence, uint256ToString(cur->key)); + } + } + + ++numWrites; + } + + prev = std::move(cur->key); + if (numWrites % 100000 == 0 && numWrites != 0) + log_.info() << "Wrote " << numWrites << " book successors"; + } + + backend_->writeSuccessor(uint256ToString(prev), sequence, uint256ToString(data::lastKey)); + ++numWrites; + }); log_.info() << "Looping through cache and submitting all writes took " << seconds << " seconds. numWrites = " << std::to_string(numWrites); @@ -251,4 +253,4 @@ public: } }; -} // namespace clio::detail +} // namespace etl::detail diff --git a/src/etl/impl/LedgerPublisher.h b/src/etl/impl/LedgerPublisher.h index f63ea05c..0336de5c 100644 --- a/src/etl/impl/LedgerPublisher.h +++ b/src/etl/impl/LedgerPublisher.h @@ -19,17 +19,17 @@ #pragma once -#include +#include #include -#include #include #include +#include #include #include -namespace clio::detail { +namespace etl::detail { /** * @brief Publishes ledgers in a synchronized fashion. @@ -45,7 +45,7 @@ namespace clio::detail { template class LedgerPublisher { - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; boost::asio::strand publishStrand_; @@ -113,7 +113,7 @@ public: } else { - auto lgr = Backend::synchronousAndRetryOnTimeout( + auto lgr = data::synchronousAndRetryOnTimeout( [&](auto yield) { return backend_->fetchLedgerBySequence(ledgerSequence, yield); }); assert(lgr); @@ -142,7 +142,7 @@ public: { log_.info() << "Updating cache"; - std::vector diff = Backend::synchronousAndRetryOnTimeout( + std::vector diff = data::synchronousAndRetryOnTimeout( [&](auto yield) { return backend_->fetchLedgerDiff(lgrInfo.seq, yield); }); backend_->cache().update(diff, lgrInfo.seq); // todo: inject cache to update, don't use backend cache @@ -156,10 +156,10 @@ public: // TODO: this probably should be a strategy if (age < 600) { - std::optional fees = Backend::synchronousAndRetryOnTimeout( + std::optional fees = data::synchronousAndRetryOnTimeout( [&](auto yield) { return backend_->fetchFees(lgrInfo.seq, yield); }); - std::vector transactions = Backend::synchronousAndRetryOnTimeout( + std::vector transactions = data::synchronousAndRetryOnTimeout( [&](auto yield) { return backend_->fetchAllTransactionsInLedger(lgrInfo.seq, yield); }); auto ledgerRange = backend_->fetchLedgerRange(); @@ -252,4 +252,4 @@ private: } }; -} // namespace clio::detail +} // namespace etl::detail diff --git a/src/etl/impl/Transformer.h b/src/etl/impl/Transformer.h index b54a8601..5d321561 100644 --- a/src/etl/impl/Transformer.h +++ b/src/etl/impl/Transformer.h @@ -19,12 +19,12 @@ #pragma once -#include +#include #include #include -#include #include #include +#include #include #include @@ -34,7 +34,7 @@ #include #include -namespace clio::detail { +namespace etl::detail { /* * TODO: @@ -53,7 +53,7 @@ class Transformer using GetLedgerResponseType = typename LedgerLoaderType::GetLedgerResponseType; using RawLedgerObjectType = typename LedgerLoaderType::RawLedgerObjectType; - clio::Logger log_{"ETL"}; + util::Logger log_{"ETL"}; std::reference_wrapper pipe_; std::shared_ptr backend_; @@ -167,9 +167,9 @@ private: buildNextLedger(GetLedgerResponseType& rawData) { log_.debug() << "Beginning ledger update"; - ripple::LedgerHeader lgrInfo = util::deserializeHeader(ripple::makeSlice(rawData.ledger_header())); + ripple::LedgerHeader lgrInfo = ::util::deserializeHeader(ripple::makeSlice(rawData.ledger_header())); - log_.debug() << "Deserialized ledger header. " << util::toString(lgrInfo); + log_.debug() << "Deserialized ledger header. " << ::util::toString(lgrInfo); backend_->startWrites(); backend_->writeLedger(lgrInfo, std::move(*rawData.mutable_ledger_header())); @@ -202,10 +202,10 @@ private: backend_->writeNFTTransactions(std::move(insertTxResultOp->nfTokenTxData)); auto [success, duration] = - util::timed>([&]() { return backend_->finishWrites(lgrInfo.seq); }); + ::util::timed>([&]() { return backend_->finishWrites(lgrInfo.seq); }); log_.debug() << "Finished writes. Total time: " << std::to_string(duration); - log_.debug() << "Finished ledger update: " << util::toString(lgrInfo); + log_.debug() << "Finished ledger update: " << ::util::toString(lgrInfo); return {lgrInfo, success}; } @@ -219,7 +219,7 @@ private: void updateCache(ripple::LedgerHeader const& lgrInfo, GetLedgerResponseType& rawData) { - std::vector cacheUpdates; + std::vector cacheUpdates; cacheUpdates.reserve(rawData.ledger_objects().objects_size()); // TODO change these to unordered_set @@ -297,11 +297,11 @@ private: auto lb = backend_->cache().getPredecessor(obj.key, lgrInfo.seq); if (!lb) - lb = {Backend::firstKey, {}}; + lb = {data::firstKey, {}}; auto ub = backend_->cache().getSuccessor(obj.key, lgrInfo.seq); if (!ub) - ub = {Backend::lastKey, {}}; + ub = {data::lastKey, {}}; if (obj.blob.size() == 0) { @@ -332,10 +332,10 @@ private: } else { - backend_->writeSuccessor(uint256ToString(base), lgrInfo.seq, uint256ToString(Backend::lastKey)); + backend_->writeSuccessor(uint256ToString(base), lgrInfo.seq, uint256ToString(data::lastKey)); log_.debug() << "Updating book successor " << ripple::strHex(base) << " - " - << ripple::strHex(Backend::lastKey); + << ripple::strHex(data::lastKey); } } } @@ -359,7 +359,7 @@ private: { auto firstBook = std::move(*obj.mutable_first_book()); if (!firstBook.size()) - firstBook = uint256ToString(Backend::lastKey); + firstBook = uint256ToString(data::lastKey); log_.debug() << "writing book successor " << ripple::strHex(obj.book_base()) << " - " << ripple::strHex(firstBook); @@ -372,10 +372,10 @@ private: { std::string* predPtr = obj.mutable_predecessor(); if (!predPtr->size()) - *predPtr = uint256ToString(Backend::firstKey); + *predPtr = uint256ToString(data::firstKey); std::string* succPtr = obj.mutable_successor(); if (!succPtr->size()) - *succPtr = uint256ToString(Backend::lastKey); + *succPtr = uint256ToString(data::lastKey); if (obj.mod_type() == RawLedgerObjectType::DELETED) { @@ -424,4 +424,4 @@ private: } }; -} // namespace clio::detail +} // namespace etl::detail diff --git a/src/main/Main.cpp b/src/main/Main.cpp index 717bb66e..b8643584 100644 --- a/src/main/Main.cpp +++ b/src/main/Main.cpp @@ -25,12 +25,12 @@ #undef GRPC_ASAN_ENABLED #endif -#include -#include +#include #include #include #include #include +#include #include #include @@ -47,8 +47,9 @@ #include #include -using namespace clio; +using namespace util; using namespace boost::asio; + namespace po = boost::program_options; /** @@ -178,12 +179,12 @@ try io_context ioc{threads}; // Rate limiter, to prevent abuse - auto sweepHandler = IntervalSweepHandler{config, ioc}; - auto whitelistHandler = WhitelistHandler{config}; - auto dosGuard = DOSGuard{config, whitelistHandler, sweepHandler}; + auto sweepHandler = web::IntervalSweepHandler{config, ioc}; + auto whitelistHandler = web::WhitelistHandler{config}; + auto dosGuard = web::DOSGuard{config, whitelistHandler, sweepHandler}; // Interface to the database - auto backend = Backend::make_Backend(ioc, config); + auto backend = data::make_Backend(ioc, config); // Manages clients subscribed to streams auto subscriptions = SubscriptionManager::make_SubscriptionManager(config, backend); @@ -212,7 +213,7 @@ try std::make_shared>(config, backend, rpcEngine, etl, subscriptions); auto ctx = parseCerts(config); auto const ctxRef = ctx ? std::optional>{ctx.value()} : std::nullopt; - auto const httpServer = Server::make_HttpServer(config, ioc, ctxRef, dosGuard, handler); + auto const httpServer = web::make_HttpServer(config, ioc, ctxRef, dosGuard, handler); // Blocks until stopped. // When stopped, shared_ptrs fall out of scope diff --git a/src/rpc/BookChangesHelper.h b/src/rpc/BookChangesHelper.h index 5d731eb9..18d4c13b 100644 --- a/src/rpc/BookChangesHelper.h +++ b/src/rpc/BookChangesHelper.h @@ -53,7 +53,7 @@ public: * @return std::vector Book changes */ [[nodiscard]] static std::vector - compute(std::vector const& transactions) + compute(std::vector const& transactions) { return HandlerImpl{}(transactions); } @@ -66,7 +66,7 @@ private: public: [[nodiscard]] std::vector - operator()(std::vector const& transactions) + operator()(std::vector const& transactions) { for (auto const& tx : transactions) handleBookChange(tx); @@ -176,7 +176,7 @@ private: } void - handleBookChange(Backend::TransactionAndMetadata const& blob) + handleBookChange(data::TransactionAndMetadata const& blob) { auto const [tx, meta] = RPC::deserializeTxPlusMeta(blob); if (!tx || !meta || !tx->isFieldPresent(ripple::sfTransactionType)) @@ -229,8 +229,6 @@ tag_invoke(boost::json::value_from_tag, boost::json::value& jv, BookChange const } [[nodiscard]] boost::json::object const -computeBookChanges( - ripple::LedgerHeader const& lgrInfo, - std::vector const& transactions); +computeBookChanges(ripple::LedgerHeader const& lgrInfo, std::vector const& transactions); } // namespace RPC diff --git a/src/rpc/Factories.cpp b/src/rpc/Factories.cpp index 8401f96d..cf562ff9 100644 --- a/src/rpc/Factories.cpp +++ b/src/rpc/Factories.cpp @@ -21,21 +21,21 @@ #include using namespace std; -using namespace clio; +using namespace util; namespace RPC { -util::Expected +util::Expected make_WsContext( boost::asio::yield_context yc, boost::json::object const& request, - shared_ptr const& session, - util::TagDecoratorFactory const& tagFactory, - Backend::LedgerRange const& range, + shared_ptr const& session, + TagDecoratorFactory const& tagFactory, + data::LedgerRange const& range, string const& clientIp, std::reference_wrapper apiVersionParser) { - using Error = util::Unexpected; + using Error = Unexpected; boost::json::value commandValue = nullptr; if (!request.contains("command") && request.contains("method")) @@ -51,19 +51,19 @@ make_WsContext( return Error{{ClioError::rpcINVALID_API_VERSION, apiVersion.error()}}; string command = commandValue.as_string().c_str(); - return Web::Context(yc, command, *apiVersion, request, session, tagFactory, range, clientIp); + return web::Context(yc, command, *apiVersion, request, session, tagFactory, range, clientIp); } -util::Expected +Expected make_HttpContext( boost::asio::yield_context yc, boost::json::object const& request, - util::TagDecoratorFactory const& tagFactory, - Backend::LedgerRange const& range, + TagDecoratorFactory const& tagFactory, + data::LedgerRange const& range, string const& clientIp, std::reference_wrapper apiVersionParser) { - using Error = util::Unexpected; + using Error = Unexpected; if (!request.contains("method")) return Error{{ClioError::rpcCOMMAND_IS_MISSING}}; @@ -91,7 +91,7 @@ make_HttpContext( if (!apiVersion) return Error{{ClioError::rpcINVALID_API_VERSION, apiVersion.error()}}; - return Web::Context(yc, command, *apiVersion, array.at(0).as_object(), nullptr, tagFactory, range, clientIp); + return web::Context(yc, command, *apiVersion, array.at(0).as_object(), nullptr, tagFactory, range, clientIp); } } // namespace RPC diff --git a/src/rpc/Factories.h b/src/rpc/Factories.h index 69d6ae3f..df4da415 100644 --- a/src/rpc/Factories.h +++ b/src/rpc/Factories.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include @@ -41,22 +41,22 @@ */ namespace RPC { -util::Expected +util::Expected make_WsContext( boost::asio::yield_context yc, boost::json::object const& request, - std::shared_ptr const& session, + std::shared_ptr const& session, util::TagDecoratorFactory const& tagFactory, - Backend::LedgerRange const& range, + data::LedgerRange const& range, std::string const& clientIp, std::reference_wrapper apiVersionParser); -util::Expected +util::Expected make_HttpContext( boost::asio::yield_context yc, boost::json::object const& request, util::TagDecoratorFactory const& tagFactory, - Backend::LedgerRange const& range, + data::LedgerRange const& range, std::string const& clientIp, std::reference_wrapper apiVersionParser); diff --git a/src/rpc/RPCEngine.h b/src/rpc/RPCEngine.h index 593bcf64..b7d97b8e 100644 --- a/src/rpc/RPCEngine.h +++ b/src/rpc/RPCEngine.h @@ -19,10 +19,8 @@ #pragma once -#include -#include +#include #include -#include #include #include #include @@ -31,6 +29,8 @@ #include #include #include +#include +#include #include #include @@ -55,13 +55,13 @@ namespace RPC { template class RPCEngineBase { - clio::Logger perfLog_{"Performance"}; - clio::Logger log_{"RPC"}; + util::Logger perfLog_{"Performance"}; + util::Logger log_{"RPC"}; std::shared_ptr backend_; std::shared_ptr subscriptions_; std::shared_ptr balancer_; - std::reference_wrapper dosGuard_; + std::reference_wrapper dosGuard_; std::reference_wrapper workQueue_; std::reference_wrapper counters_; @@ -76,7 +76,7 @@ public: std::shared_ptr const& subscriptions, std::shared_ptr const& balancer, std::shared_ptr const& etl, - clio::DOSGuard const& dosGuard, + web::DOSGuard const& dosGuard, WorkQueue& workQueue, Counters& counters, std::shared_ptr const& handlerProvider) @@ -93,12 +93,12 @@ public: static std::shared_ptr make_RPCEngine( - clio::Config const& config, + util::Config const& config, std::shared_ptr const& backend, std::shared_ptr const& subscriptions, std::shared_ptr const& balancer, std::shared_ptr const& etl, - clio::DOSGuard const& dosGuard, + web::DOSGuard const& dosGuard, WorkQueue& workQueue, Counters& counters, std::shared_ptr const& handlerProvider) @@ -112,7 +112,7 @@ public: * @param ctx The @ref Context of the request */ Result - buildResponse(Web::Context const& ctx) + buildResponse(web::Context const& ctx) { if (forwardingProxy_.shouldForward(ctx)) return forwardingProxy_.forward(ctx); @@ -149,7 +149,7 @@ public: return Status{v.error()}; } } - catch (Backend::DatabaseTimeout const& t) + catch (data::DatabaseTimeout const& t) { log_.error() << "Database timeout"; notifyTooBusy(); diff --git a/src/rpc/RPCHelpers.cpp b/src/rpc/RPCHelpers.cpp index cd1d4519..66e26f61 100644 --- a/src/rpc/RPCHelpers.cpp +++ b/src/rpc/RPCHelpers.cpp @@ -17,12 +17,12 @@ */ //============================================================================== -#include -#include -#include +#include +#include #include #include #include +#include #include #include @@ -30,11 +30,9 @@ #include #include -using namespace clio; - // local to compilation unit loggers namespace { -clio::Logger gLog{"RPC"}; +util::Logger gLog{"RPC"}; } // namespace namespace RPC { @@ -144,7 +142,7 @@ accountFromStringStrict(std::string const& account) return {}; } std::pair, std::shared_ptr> -deserializeTxPlusMeta(Backend::TransactionAndMetadata const& blobs) +deserializeTxPlusMeta(data::TransactionAndMetadata const& blobs) { try { @@ -173,7 +171,7 @@ deserializeTxPlusMeta(Backend::TransactionAndMetadata const& blobs) } std::pair, std::shared_ptr> -deserializeTxPlusMeta(Backend::TransactionAndMetadata const& blobs, std::uint32_t seq) +deserializeTxPlusMeta(data::TransactionAndMetadata const& blobs, std::uint32_t seq) { auto [tx, meta] = deserializeTxPlusMeta(blobs); @@ -191,7 +189,7 @@ toJson(ripple::STBase const& obj) } std::pair -toExpandedJson(Backend::TransactionAndMetadata const& blobs, NFTokenjson nftEnabled) +toExpandedJson(data::TransactionAndMetadata const& blobs, NFTokenjson nftEnabled) { auto [txn, meta] = deserializeTxPlusMeta(blobs, blobs.ledgerSequence); auto txnJson = toJson(*txn); @@ -300,7 +298,7 @@ parseStringAsUInt(std::string const& value) } std::variant -ledgerInfoFromRequest(std::shared_ptr const& backend, Web::Context const& ctx) +ledgerInfoFromRequest(std::shared_ptr const& backend, web::Context const& ctx) { auto hashValue = ctx.params.contains("ledger_hash") ? ctx.params.at("ledger_hash") : nullptr; @@ -677,10 +675,10 @@ traverseOwnedNodes( std::shared_ptr read( - std::shared_ptr const& backend, + std::shared_ptr const& backend, ripple::Keylet const& keylet, ripple::LedgerHeader const& lgrInfo, - Web::Context const& context) + web::Context const& context) { if (auto const blob = backend->fetchLedgerObject(keylet.key, lgrInfo.seq, context.yield); blob) { @@ -1025,10 +1023,10 @@ transferRate( boost::json::array postProcessOrderBook( - std::vector const& offers, + std::vector const& offers, ripple::Book const& book, ripple::AccountID const& takerID, - Backend::BackendInterface const& backend, + data::BackendInterface const& backend, std::uint32_t const ledgerSequence, boost::asio::yield_context yield) { @@ -1327,7 +1325,7 @@ getNFTID(boost::json::object const& request) bool isAmendmentEnabled( - std::shared_ptr const& backend, + std::shared_ptr const& backend, boost::asio::yield_context yield, uint32_t seq, ripple::uint256 amendmentId) diff --git a/src/rpc/RPCHelpers.h b/src/rpc/RPCHelpers.h index cdcb977e..63e17ba1 100644 --- a/src/rpc/RPCHelpers.h +++ b/src/rpc/RPCHelpers.h @@ -23,7 +23,7 @@ * This file contains a variety of utility functions used when executing the handlers. */ -#include +#include #include #include #include @@ -55,14 +55,14 @@ parseAccountCursor(std::optional jsonCursor); // TODO this function should probably be in a different file and namespace std::pair, std::shared_ptr> -deserializeTxPlusMeta(Backend::TransactionAndMetadata const& blobs); +deserializeTxPlusMeta(data::TransactionAndMetadata const& blobs); // TODO this function should probably be in a different file and namespace std::pair, std::shared_ptr> -deserializeTxPlusMeta(Backend::TransactionAndMetadata const& blobs, std::uint32_t seq); +deserializeTxPlusMeta(data::TransactionAndMetadata const& blobs, std::uint32_t seq); std::pair -toExpandedJson(Backend::TransactionAndMetadata const& blobs, NFTokenjson includeNFTIDs = NFTokenjson::DISABLE); +toExpandedJson(data::TransactionAndMetadata const& blobs, NFTokenjson includeNFTIDs = NFTokenjson::DISABLE); bool insertDeliveredAmount( @@ -95,7 +95,7 @@ generatePubLedgerMessage( std::uint32_t txnCount); std::variant -ledgerInfoFromRequest(std::shared_ptr const& backend, Web::Context const& ctx); +ledgerInfoFromRequest(std::shared_ptr const& backend, web::Context const& ctx); std::variant getLedgerInfoFromHashOrSeq( @@ -131,10 +131,10 @@ traverseOwnedNodes( std::shared_ptr read( - std::shared_ptr const& backend, + std::shared_ptr const& backend, ripple::Keylet const& keylet, ripple::LedgerHeader const& lgrInfo, - Web::Context const& context); + web::Context const& context); std::variant> keypairFromRequst(boost::json::object const& request); @@ -195,10 +195,10 @@ xrpLiquid( boost::json::array postProcessOrderBook( - std::vector const& offers, + std::vector const& offers, ripple::Book const& book, ripple::AccountID const& takerID, - Backend::BackendInterface const& backend, + data::BackendInterface const& backend, std::uint32_t ledgerSequence, boost::asio::yield_context yield); @@ -219,18 +219,18 @@ getNFTID(boost::json::object const& request); bool isAmendmentEnabled( - std::shared_ptr const& backend, + std::shared_ptr const& backend, boost::asio::yield_context yield, uint32_t seq, ripple::uint256 amendmentId); template void -logDuration(Web::Context const& ctx, T const& dur) +logDuration(web::Context const& ctx, T const& dur) { using boost::json::serialize; - static clio::Logger log{"RPC"}; + static util::Logger log{"RPC"}; auto const millis = std::chrono::duration_cast(dur).count(); auto const seconds = std::chrono::duration_cast(dur).count(); auto const msg = fmt::format( diff --git a/src/rpc/WorkQueue.h b/src/rpc/WorkQueue.h index e7028488..08ec654d 100644 --- a/src/rpc/WorkQueue.h +++ b/src/rpc/WorkQueue.h @@ -19,8 +19,8 @@ #pragma once -#include -#include +#include +#include #include #include @@ -41,7 +41,7 @@ class WorkQueue std::atomic_uint64_t curSize_ = 0; uint32_t maxSize_ = std::numeric_limits::max(); - clio::Logger log_{"RPC"}; + util::Logger log_{"RPC"}; boost::asio::thread_pool ioc_; public: @@ -49,9 +49,9 @@ public: ~WorkQueue(); static WorkQueue - make_WorkQueue(clio::Config const& config) + make_WorkQueue(util::Config const& config) { - static clio::Logger log{"RPC"}; + static util::Logger log{"RPC"}; auto const serverConfig = config.section("server"); auto const numThreads = config.valueOr("workers", std::thread::hardware_concurrency()); auto const maxQueueSize = serverConfig.valueOr("max_queue_size", 0); // 0 is no limit diff --git a/src/rpc/common/Types.h b/src/rpc/common/Types.h index 1c934ca8..a523d590 100644 --- a/src/rpc/common/Types.h +++ b/src/rpc/common/Types.h @@ -28,7 +28,7 @@ #include #include -namespace Server { +namespace web { struct ConnectionBase; } @@ -73,7 +73,7 @@ struct VoidOutput struct Context { boost::asio::yield_context yield; - std::shared_ptr session; + std::shared_ptr session; bool isAdmin = false; std::string clientIp; uint32_t apiVersion = 0u; // invalid by default diff --git a/src/rpc/common/impl/APIVersionParser.cpp b/src/rpc/common/impl/APIVersionParser.cpp index 4ea9e3cd..8bd66c7e 100644 --- a/src/rpc/common/impl/APIVersionParser.cpp +++ b/src/rpc/common/impl/APIVersionParser.cpp @@ -17,8 +17,8 @@ */ //============================================================================== -#include #include +#include #include @@ -26,7 +26,7 @@ using namespace std; namespace RPC::detail { -ProductionAPIVersionParser::ProductionAPIVersionParser(clio::Config const& config) +ProductionAPIVersionParser::ProductionAPIVersionParser(util::Config const& config) : ProductionAPIVersionParser( config.valueOr("default", API_VERSION_DEFAULT), config.valueOr("min", API_VERSION_MIN), diff --git a/src/rpc/common/impl/APIVersionParser.h b/src/rpc/common/impl/APIVersionParser.h index 9b79fd61..13749e5d 100644 --- a/src/rpc/common/impl/APIVersionParser.h +++ b/src/rpc/common/impl/APIVersionParser.h @@ -19,10 +19,10 @@ #pragma once -#include -#include #include #include +#include +#include #include #include @@ -31,7 +31,7 @@ namespace RPC::detail { class ProductionAPIVersionParser : public APIVersionParser { - clio::Logger log_{"RPC"}; + util::Logger log_{"RPC"}; uint32_t defaultVersion_; uint32_t minVersion_; @@ -70,7 +70,7 @@ public: << "; default = " << defaultVersion_ << "]"; } - ProductionAPIVersionParser(clio::Config const& config); + ProductionAPIVersionParser(util::Config const& config); util::Expected parse(boost::json::object const& request) const override; diff --git a/src/rpc/common/impl/ForwardingProxy.h b/src/rpc/common/impl/ForwardingProxy.h index 840c3c3d..8aee3bbb 100644 --- a/src/rpc/common/impl/ForwardingProxy.h +++ b/src/rpc/common/impl/ForwardingProxy.h @@ -21,10 +21,10 @@ #include #include -#include #include #include #include +#include #include #include @@ -35,7 +35,7 @@ namespace RPC::detail { template class ForwardingProxy { - clio::Logger log_{"RPC"}; + util::Logger log_{"RPC"}; std::shared_ptr balancer_; std::reference_wrapper counters_; @@ -51,7 +51,7 @@ public: } bool - shouldForward(Web::Context const& ctx) const + shouldForward(web::Context const& ctx) const { if (ctx.method == "subscribe" || ctx.method == "unsubscribe") return false; @@ -91,7 +91,7 @@ public: } Result - forward(Web::Context const& ctx) + forward(web::Context const& ctx) { auto toForward = ctx.params; toForward["command"] = ctx.method; diff --git a/src/rpc/common/impl/HandlerProvider.cpp b/src/rpc/common/impl/HandlerProvider.cpp index 12f9fa2e..e6e1d215 100644 --- a/src/rpc/common/impl/HandlerProvider.cpp +++ b/src/rpc/common/impl/HandlerProvider.cpp @@ -56,7 +56,7 @@ namespace RPC::detail { ProductionHandlerProvider::ProductionHandlerProvider( - clio::Config const& config, + util::Config const& config, std::shared_ptr const& backend, std::shared_ptr const& subscriptionManager, std::shared_ptr const& balancer, diff --git a/src/rpc/common/impl/HandlerProvider.h b/src/rpc/common/impl/HandlerProvider.h index 7bb6764c..c10fae68 100644 --- a/src/rpc/common/impl/HandlerProvider.h +++ b/src/rpc/common/impl/HandlerProvider.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include @@ -50,7 +50,7 @@ class ProductionHandlerProvider final : public HandlerProvider public: ProductionHandlerProvider( - clio::Config const& config, + util::Config const& config, std::shared_ptr const& backend, std::shared_ptr const& subscriptionManager, std::shared_ptr const& balancer, diff --git a/src/rpc/handlers/AccountChannels.h b/src/rpc/handlers/AccountChannels.h index e94d6255..84bd142d 100644 --- a/src/rpc/handlers/AccountChannels.h +++ b/src/rpc/handlers/AccountChannels.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/AccountCurrencies.h b/src/rpc/handlers/AccountCurrencies.h index 599387c1..3af7586d 100644 --- a/src/rpc/handlers/AccountCurrencies.h +++ b/src/rpc/handlers/AccountCurrencies.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/AccountInfo.h b/src/rpc/handlers/AccountInfo.h index dcec5006..fe72ae68 100644 --- a/src/rpc/handlers/AccountInfo.h +++ b/src/rpc/handlers/AccountInfo.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/AccountLines.h b/src/rpc/handlers/AccountLines.h index eb70abc8..21e02aaf 100644 --- a/src/rpc/handlers/AccountLines.h +++ b/src/rpc/handlers/AccountLines.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/AccountNFTs.h b/src/rpc/handlers/AccountNFTs.h index fa9c40b8..5c5681a3 100644 --- a/src/rpc/handlers/AccountNFTs.h +++ b/src/rpc/handlers/AccountNFTs.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/AccountObjects.h b/src/rpc/handlers/AccountObjects.h index efa071a8..9ca9f8f8 100644 --- a/src/rpc/handlers/AccountObjects.h +++ b/src/rpc/handlers/AccountObjects.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/AccountOffers.h b/src/rpc/handlers/AccountOffers.h index 0c05c1ca..611c4fe4 100644 --- a/src/rpc/handlers/AccountOffers.h +++ b/src/rpc/handlers/AccountOffers.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/AccountTx.cpp b/src/rpc/handlers/AccountTx.cpp index ec6479db..7a2b64d6 100644 --- a/src/rpc/handlers/AccountTx.cpp +++ b/src/rpc/handlers/AccountTx.cpp @@ -64,7 +64,7 @@ AccountTxHandler::process(AccountTxHandler::Input input, Context const& ctx) con maxIndex = minIndex = std::get(lgrInfoOrStatus).seq; } - std::optional cursor; + std::optional cursor; // if marker exists if (input.marker) diff --git a/src/rpc/handlers/AccountTx.h b/src/rpc/handlers/AccountTx.h index 3b2c4c69..d2a15685 100644 --- a/src/rpc/handlers/AccountTx.h +++ b/src/rpc/handlers/AccountTx.h @@ -19,13 +19,13 @@ #pragma once -#include -#include +#include #include #include #include #include #include +#include namespace RPC { @@ -36,7 +36,7 @@ namespace RPC { */ class AccountTxHandler { - clio::Logger log_{"RPC"}; + util::Logger log_{"RPC"}; std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/BookChanges.cpp b/src/rpc/handlers/BookChanges.cpp index a2d52805..2df73297 100644 --- a/src/rpc/handlers/BookChanges.cpp +++ b/src/rpc/handlers/BookChanges.cpp @@ -79,9 +79,7 @@ tag_invoke(boost::json::value_to_tag, boost::json::va } [[nodiscard]] boost::json::object const -computeBookChanges( - ripple::LedgerHeader const& lgrInfo, - std::vector const& transactions) +computeBookChanges(ripple::LedgerHeader const& lgrInfo, std::vector const& transactions) { using boost::json::value_from; diff --git a/src/rpc/handlers/BookChanges.h b/src/rpc/handlers/BookChanges.h index 6a085b5b..273a3059 100644 --- a/src/rpc/handlers/BookChanges.h +++ b/src/rpc/handlers/BookChanges.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/BookOffers.h b/src/rpc/handlers/BookOffers.h index 53f147f7..80e22238 100644 --- a/src/rpc/handlers/BookOffers.h +++ b/src/rpc/handlers/BookOffers.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/DepositAuthorized.h b/src/rpc/handlers/DepositAuthorized.h index 545e709a..c732039e 100644 --- a/src/rpc/handlers/DepositAuthorized.h +++ b/src/rpc/handlers/DepositAuthorized.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/GatewayBalances.h b/src/rpc/handlers/GatewayBalances.h index 44d8091c..b70f0a65 100644 --- a/src/rpc/handlers/GatewayBalances.h +++ b/src/rpc/handlers/GatewayBalances.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/Ledger.h b/src/rpc/handlers/Ledger.h index fd65fe26..a3933625 100644 --- a/src/rpc/handlers/Ledger.h +++ b/src/rpc/handlers/Ledger.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/LedgerData.cpp b/src/rpc/handlers/LedgerData.cpp index d4040768..8ce77156 100644 --- a/src/rpc/handlers/LedgerData.cpp +++ b/src/rpc/handlers/LedgerData.cpp @@ -108,7 +108,7 @@ LedgerDataHandler::process(Input input, Context const& ctx) const output.ledgerIndex = lgrInfo.seq; auto const start = std::chrono::system_clock::now(); - std::vector results; + std::vector results; if (input.diffMarker) { diff --git a/src/rpc/handlers/LedgerData.h b/src/rpc/handlers/LedgerData.h index 3d9424c8..5ad670bf 100644 --- a/src/rpc/handlers/LedgerData.h +++ b/src/rpc/handlers/LedgerData.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include @@ -40,7 +40,7 @@ class LedgerDataHandler { // dependencies std::shared_ptr sharedPtrBackend_; - clio::Logger log_{"RPC"}; + util::Logger log_{"RPC"}; static const std::unordered_map TYPES_MAP; diff --git a/src/rpc/handlers/LedgerEntry.h b/src/rpc/handlers/LedgerEntry.h index 3be53fbb..a0d7e242 100644 --- a/src/rpc/handlers/LedgerEntry.h +++ b/src/rpc/handlers/LedgerEntry.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/LedgerRange.h b/src/rpc/handlers/LedgerRange.h index e75fcecd..98a6ae92 100644 --- a/src/rpc/handlers/LedgerRange.h +++ b/src/rpc/handlers/LedgerRange.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include @@ -40,7 +40,7 @@ class LedgerRangeHandler public: struct Output { - Backend::LedgerRange range; + data::LedgerRange range; }; using Result = HandlerReturnType; diff --git a/src/rpc/handlers/NFTBuyOffers.h b/src/rpc/handlers/NFTBuyOffers.h index a2a7beb5..5fda3c41 100644 --- a/src/rpc/handlers/NFTBuyOffers.h +++ b/src/rpc/handlers/NFTBuyOffers.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include namespace RPC { diff --git a/src/rpc/handlers/NFTHistory.cpp b/src/rpc/handlers/NFTHistory.cpp index f9e3900d..837b837e 100644 --- a/src/rpc/handlers/NFTHistory.cpp +++ b/src/rpc/handlers/NFTHistory.cpp @@ -66,7 +66,7 @@ NFTHistoryHandler::process(NFTHistoryHandler::Input input, Context const& ctx) c maxIndex = minIndex = std::get(lgrInfoOrStatus).seq; } - std::optional cursor; + std::optional cursor; // if marker exists if (input.marker) diff --git a/src/rpc/handlers/NFTHistory.h b/src/rpc/handlers/NFTHistory.h index d0dfaae8..b59b378a 100644 --- a/src/rpc/handlers/NFTHistory.h +++ b/src/rpc/handlers/NFTHistory.h @@ -19,13 +19,13 @@ #pragma once -#include -#include +#include #include #include #include #include #include +#include namespace RPC { @@ -36,7 +36,7 @@ namespace RPC { */ class NFTHistoryHandler { - clio::Logger log_{"RPC"}; + util::Logger log_{"RPC"}; std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/NFTInfo.h b/src/rpc/handlers/NFTInfo.h index 75bfb5ff..7b03418a 100644 --- a/src/rpc/handlers/NFTInfo.h +++ b/src/rpc/handlers/NFTInfo.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/NFTOffersCommon.h b/src/rpc/handlers/NFTOffersCommon.h index d8db6f5f..ab81a347 100644 --- a/src/rpc/handlers/NFTOffersCommon.h +++ b/src/rpc/handlers/NFTOffersCommon.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/NFTSellOffers.h b/src/rpc/handlers/NFTSellOffers.h index 60dd634c..877560b7 100644 --- a/src/rpc/handlers/NFTSellOffers.h +++ b/src/rpc/handlers/NFTSellOffers.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include namespace RPC { diff --git a/src/rpc/handlers/NoRippleCheck.h b/src/rpc/handlers/NoRippleCheck.h index 46df3a14..40a8a1e8 100644 --- a/src/rpc/handlers/NoRippleCheck.h +++ b/src/rpc/handlers/NoRippleCheck.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/ServerInfo.h b/src/rpc/handlers/ServerInfo.h index 511df995..97d3fa49 100644 --- a/src/rpc/handlers/ServerInfo.h +++ b/src/rpc/handlers/ServerInfo.h @@ -19,8 +19,8 @@ #pragma once -#include -#include +#include +#include #include
#include #include diff --git a/src/rpc/handlers/Subscribe.h b/src/rpc/handlers/Subscribe.h index 0b05723a..720f2bb5 100644 --- a/src/rpc/handlers/Subscribe.h +++ b/src/rpc/handlers/Subscribe.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include @@ -143,7 +143,7 @@ private: subscribeToStreams( boost::asio::yield_context yield, std::vector const& streams, - std::shared_ptr const& session) const + std::shared_ptr const& session) const { auto response = boost::json::object{}; @@ -167,9 +167,8 @@ private: } void - subscribeToAccounts( - std::vector const& accounts, - std::shared_ptr const& session) const + subscribeToAccounts(std::vector const& accounts, std::shared_ptr const& session) + const { for (auto const& account : accounts) { @@ -181,7 +180,7 @@ private: void subscribeToAccountsProposed( std::vector const& accounts, - std::shared_ptr const& session) const + std::shared_ptr const& session) const { for (auto const& account : accounts) { @@ -193,13 +192,13 @@ private: void subscribeToBooks( std::vector const& books, - std::shared_ptr const& session, + std::shared_ptr const& session, boost::asio::yield_context yield, Output& output) const { static auto constexpr fetchLimit = 200; - std::optional rng; + std::optional rng; for (auto const& internalBook : books) { diff --git a/src/rpc/handlers/TransactionEntry.h b/src/rpc/handlers/TransactionEntry.h index 9f6acc9a..3e5a88ac 100644 --- a/src/rpc/handlers/TransactionEntry.h +++ b/src/rpc/handlers/TransactionEntry.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/Tx.h b/src/rpc/handlers/Tx.h index 1376c405..3a2ce9d8 100644 --- a/src/rpc/handlers/Tx.h +++ b/src/rpc/handlers/Tx.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/rpc/handlers/Unsubscribe.h b/src/rpc/handlers/Unsubscribe.h index bd80a27a..401e0711 100644 --- a/src/rpc/handlers/Unsubscribe.h +++ b/src/rpc/handlers/Unsubscribe.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include #include @@ -111,9 +111,8 @@ public: private: void - unsubscribeFromStreams( - std::vector const& streams, - std::shared_ptr const& session) const + unsubscribeFromStreams(std::vector const& streams, std::shared_ptr const& session) + const { for (auto const& stream : streams) { @@ -135,7 +134,7 @@ private: } void - unsubscribeFromAccounts(std::vector accounts, std::shared_ptr const& session) + unsubscribeFromAccounts(std::vector accounts, std::shared_ptr const& session) const { for (auto const& account : accounts) @@ -148,7 +147,7 @@ private: void unsubscribeFromProposedAccounts( std::vector accountsProposed, - std::shared_ptr const& session) const + std::shared_ptr const& session) const { for (auto const& account : accountsProposed) { @@ -158,8 +157,7 @@ private: } void - unsubscribeFromBooks(std::vector const& books, std::shared_ptr const& session) - const + unsubscribeFromBooks(std::vector const& books, std::shared_ptr const& session) const { for (auto const& orderBook : books) { diff --git a/src/rpc/handlers/VersionHandler.h b/src/rpc/handlers/VersionHandler.h index d35051cf..12567ff7 100644 --- a/src/rpc/handlers/VersionHandler.h +++ b/src/rpc/handlers/VersionHandler.h @@ -43,7 +43,7 @@ public: uint32_t currVersion; }; - explicit VersionHandler(clio::Config const& config) + explicit VersionHandler(util::Config const& config) : apiVersionParser_( config.valueOr("default", API_VERSION_DEFAULT), config.valueOr("min", API_VERSION_MIN), diff --git a/src/subscriptions/SubscriptionManager.cpp b/src/subscriptions/SubscriptionManager.cpp index 9840a77c..febeb556 100644 --- a/src/subscriptions/SubscriptionManager.cpp +++ b/src/subscriptions/SubscriptionManager.cpp @@ -155,7 +155,7 @@ SubscriptionManager::pubLedger( } void -SubscriptionManager::pubTransaction(Backend::TransactionAndMetadata const& blobs, ripple::LedgerHeader const& lgrInfo) +SubscriptionManager::pubTransaction(data::TransactionAndMetadata const& blobs, ripple::LedgerHeader const& lgrInfo) { auto [tx, meta] = RPC::deserializeTxPlusMeta(blobs, lgrInfo.seq); boost::json::object pubObj; @@ -184,12 +184,12 @@ SubscriptionManager::pubTransaction(Backend::TransactionAndMetadata const& blobs { ripple::STAmount ownerFunds; auto fetchFundsSynchronous = [&]() { - Backend::synchronous([&](boost::asio::yield_context yield) { + data::synchronous([&](boost::asio::yield_context yield) { ownerFunds = RPC::accountFunds(*backend_, lgrInfo.seq, amount, account, yield); }); }; - Backend::retryOnTimeout(fetchFundsSynchronous); + data::retryOnTimeout(fetchFundsSynchronous); pubObj["transaction"].as_object()["owner_funds"] = ownerFunds.getText(); } @@ -244,7 +244,7 @@ SubscriptionManager::pubTransaction(Backend::TransactionAndMetadata const& blobs void SubscriptionManager::pubBookChanges( ripple::LedgerHeader const& lgrInfo, - std::vector const& transactions) + std::vector const& transactions) { auto const json = RPC::computeBookChanges(lgrInfo, transactions); auto const bookChangesMsg = std::make_shared(boost::json::serialize(json)); diff --git a/src/subscriptions/SubscriptionManager.h b/src/subscriptions/SubscriptionManager.h index 72ad1283..da9e410e 100644 --- a/src/subscriptions/SubscriptionManager.h +++ b/src/subscriptions/SubscriptionManager.h @@ -19,16 +19,16 @@ #pragma once -#include -#include -#include +#include +#include +#include #include #include #include -using SessionPtrType = std::shared_ptr; +using SessionPtrType = std::shared_ptr; class Subscription { @@ -190,7 +190,7 @@ SubscriptionMap::publish(std::shared_ptr const& message, Key c class SubscriptionManager { - clio::Logger log_{"Subscriptions"}; + util::Logger log_{"Subscriptions"}; std::vector workers_; boost::asio::io_context ioc_; @@ -207,17 +207,17 @@ class SubscriptionManager SubscriptionMap accountProposedSubscribers_; SubscriptionMap bookSubscribers_; - std::shared_ptr backend_; + std::shared_ptr backend_; public: static std::shared_ptr - make_SubscriptionManager(clio::Config const& config, std::shared_ptr const& b) + make_SubscriptionManager(util::Config const& config, std::shared_ptr const& b) { auto numThreads = config.valueOr("subscription_workers", 1); return std::make_shared(numThreads, b); } - SubscriptionManager(std::uint64_t numThreads, std::shared_ptr const& b) + SubscriptionManager(std::uint64_t numThreads, std::shared_ptr const& b) : ledgerSubscribers_(ioc_) , txSubscribers_(ioc_) , txProposedSubscribers_(ioc_) @@ -261,9 +261,7 @@ public: std::uint32_t txnCount); void - pubBookChanges( - ripple::LedgerHeader const& lgrInfo, - std::vector const& transactions); + pubBookChanges(ripple::LedgerHeader const& lgrInfo, std::vector const& transactions); void unsubLedger(SessionPtrType session); @@ -275,7 +273,7 @@ public: unsubTransactions(SessionPtrType session); void - pubTransaction(Backend::TransactionAndMetadata const& blobs, ripple::LedgerHeader const& lgrInfo); + pubTransaction(data::TransactionAndMetadata const& blobs, ripple::LedgerHeader const& lgrInfo); void subAccount(ripple::AccountID const& account, SessionPtrType const& session); diff --git a/src/util/Taggable.h b/src/util/Taggable.h index 08421ce7..2a2aa62c 100644 --- a/src/util/Taggable.h +++ b/src/util/Taggable.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace util { namespace detail { @@ -189,7 +189,7 @@ public: * @brief Instantiates a tag decorator factory from `clio` configuration. * @param config The configuration as a json object */ - explicit TagDecoratorFactory(clio::Config const& config) : type_{config.valueOr("log_tag_style", Type::NONE)} + explicit TagDecoratorFactory(util::Config const& config) : type_{config.valueOr("log_tag_style", Type::NONE)} { } @@ -245,7 +245,7 @@ private: */ class Taggable { - using decorator_t = std::unique_ptr; + using decorator_t = std::unique_ptr; decorator_t tagDecorator_; protected: @@ -265,9 +265,9 @@ public: /** * @brief Getter for tag decorator. - * @return util::BaseTagDecorator const& Reference to the tag decorator + * @return BaseTagDecorator const& Reference to the tag decorator */ - util::BaseTagDecorator const& + BaseTagDecorator const& tag() const { return *tagDecorator_; diff --git a/src/config/Config.cpp b/src/util/config/Config.cpp similarity index 95% rename from src/config/Config.cpp rename to src/util/config/Config.cpp index c24b589e..dd3a9991 100644 --- a/src/config/Config.cpp +++ b/src/util/config/Config.cpp @@ -17,12 +17,12 @@ */ //============================================================================== -#include -#include +#include +#include #include -namespace clio { +namespace util { // Note: `store_(store)` MUST use `()` instead of `{}` otherwise gcc // picks `initializer_list` constructor and anything passed becomes an @@ -183,10 +183,10 @@ ConfigReader::open(std::filesystem::path path) } catch (std::exception const& e) { - LogService::error() << "Could not read configuration file from '" << path.string() << "': " << e.what(); + util::LogService::error() << "Could not read configuration file from '" << path.string() << "': " << e.what(); } return Config{}; } -} // namespace clio +} // namespace util diff --git a/src/config/Config.h b/src/util/config/Config.h similarity index 99% rename from src/config/Config.h rename to src/util/config/Config.h index 16a02133..79a71ffb 100644 --- a/src/config/Config.h +++ b/src/util/config/Config.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include @@ -27,7 +27,7 @@ #include #include -namespace clio { +namespace util { /** * @brief Convenience wrapper to query a JSON configuration file. @@ -412,4 +412,4 @@ public: open(std::filesystem::path path); }; -} // namespace clio +} // namespace util diff --git a/src/config/detail/Helpers.h b/src/util/config/detail/Helpers.h similarity index 98% rename from src/config/detail/Helpers.h rename to src/util/config/detail/Helpers.h index 33c94838..be0af765 100644 --- a/src/config/detail/Helpers.h +++ b/src/util/config/detail/Helpers.h @@ -24,7 +24,7 @@ #include #include -namespace clio::detail { +namespace util::detail { /** * @brief Thrown when a KeyPath related error occurs @@ -161,4 +161,4 @@ typeName() return "double"; } -}; // namespace clio::detail +}; // namespace util::detail diff --git a/src/log/Logger.cpp b/src/util/log/Logger.cpp similarity index 97% rename from src/log/Logger.cpp rename to src/util/log/Logger.cpp index ba19ee86..849f9e26 100644 --- a/src/log/Logger.cpp +++ b/src/util/log/Logger.cpp @@ -17,14 +17,14 @@ */ //============================================================================== -#include -#include +#include +#include #include #include #include -namespace clio { +namespace util { Logger LogService::general_log_ = Logger{"General"}; Logger LogService::alert_log_ = Logger{"Alert"}; @@ -70,7 +70,7 @@ tag_invoke(boost::json::value_to_tag, boost::json::value const& value) } void -LogService::init(Config const& config) +LogService::init(util::Config const& config) { namespace src = boost::log::sources; namespace keywords = boost::log::keywords; @@ -187,4 +187,4 @@ Logger::Pump::pretty_path(source_location_t const& loc, size_t max_depth) const return file_path.substr(idx == std::string::npos ? 0 : idx + 1) + ':' + std::to_string(loc.line()); } -} // namespace clio +} // namespace util \ No newline at end of file diff --git a/src/log/Logger.h b/src/util/log/Logger.h similarity index 99% rename from src/log/Logger.h rename to src/util/log/Logger.h index 96f52e62..13e1b0f0 100644 --- a/src/log/Logger.h +++ b/src/util/log/Logger.h @@ -48,9 +48,9 @@ #include #include -namespace clio { - +namespace util { class Config; + #if defined(HAS_SOURCE_LOCATION) && __has_builtin(__builtin_source_location) using source_location_t = std::source_location; #define CURRENT_SRC_LOCATION source_location_t::current() @@ -303,4 +303,4 @@ public: } }; -}; // namespace clio +}; // namespace util diff --git a/src/webserver/Context.h b/src/webserver/Context.h index ba537127..9ec7f71b 100644 --- a/src/webserver/Context.h +++ b/src/webserver/Context.h @@ -19,9 +19,9 @@ #pragma once -#include -#include +#include #include +#include #include #include @@ -30,7 +30,7 @@ #include #include -namespace Web { +namespace web { struct Context : util::Taggable { @@ -38,8 +38,8 @@ struct Context : util::Taggable std::string method; std::uint32_t apiVersion; boost::json::object params; - std::shared_ptr session; - Backend::LedgerRange range; + std::shared_ptr session; + data::LedgerRange range; std::string clientIp; Context( @@ -47,9 +47,9 @@ struct Context : util::Taggable std::string const& command, std::uint32_t apiVersion, boost::json::object params, - std::shared_ptr const& session, + std::shared_ptr const& session, util::TagDecoratorFactory const& tagFactory, - Backend::LedgerRange const& range, + data::LedgerRange const& range, std::string const& clientIp) : Taggable(tagFactory) , yield(yield) @@ -60,7 +60,7 @@ struct Context : util::Taggable , range(range) , clientIp(clientIp) { - static clio::Logger perfLog{"Performance"}; + static util::Logger perfLog{"Performance"}; perfLog.debug() << tag() << "new Context created"; } @@ -69,4 +69,4 @@ struct Context : util::Taggable operator=(Context&&) = default; }; -} // namespace Web +} // namespace web diff --git a/src/webserver/DOSGuard.h b/src/webserver/DOSGuard.h index da90a559..c9bc0093 100644 --- a/src/webserver/DOSGuard.h +++ b/src/webserver/DOSGuard.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include @@ -30,7 +30,7 @@ #include #include -namespace clio { +namespace web { class BaseDOSGuard { @@ -68,7 +68,7 @@ class BasicDOSGuard : public BaseDOSGuard std::uint32_t const maxFetches_; std::uint32_t const maxConnCount_; std::uint32_t const maxRequestCount_; - clio::Logger log_{"RPC"}; + util::Logger log_{"RPC"}; public: /** @@ -79,7 +79,7 @@ public: * @param SweepHandlerType Sweep handler that implements the sweeping behaviour */ BasicDOSGuard( - clio::Config const& config, + util::Config const& config, WhitelistHandlerType const& whitelistHandler, SweepHandlerType& sweepHandler) : whitelistHandler_{std::cref(whitelistHandler)} @@ -237,7 +237,7 @@ public: private: [[nodiscard]] std::unordered_set const - getWhitelist(clio::Config const& config) const + getWhitelist(util::Config const& config) const { using T = std::unordered_set const; auto whitelist = config.arrayOr("dos_guard.whitelist", {}); @@ -266,7 +266,7 @@ public: * @param config Clio config * @param ctx The boost::asio::io_context */ - IntervalSweepHandler(clio::Config const& config, boost::asio::io_context& ctx) + IntervalSweepHandler(util::Config const& config, boost::asio::io_context& ctx) : sweepInterval_{std::max(1u, static_cast(config.valueOr("dos_guard.sweep_interval", 1.0) * 1000.0))} , ctx_{std::ref(ctx)} , timer_{ctx.get_executor()} @@ -309,6 +309,6 @@ private: } }; -using DOSGuard = BasicDOSGuard; +using DOSGuard = BasicDOSGuard; -} // namespace clio +} // namespace web diff --git a/src/webserver/HttpSession.h b/src/webserver/HttpSession.h index b644c751..2b74a002 100644 --- a/src/webserver/HttpSession.h +++ b/src/webserver/HttpSession.h @@ -22,7 +22,7 @@ #include #include -namespace Server { +namespace web { using tcp = boost::asio::ip::tcp; @@ -32,7 +32,8 @@ using tcp = boost::asio::ip::tcp; * Otherwise, it will pass control to the base class. */ template -class HttpSession : public HttpBase, public std::enable_shared_from_this> +class HttpSession : public detail::HttpBase, + public std::enable_shared_from_this> { boost::beast::tcp_stream stream_; std::reference_wrapper tagFactory_; @@ -42,10 +43,10 @@ public: tcp::socket&& socket, std::string const& ip, std::reference_wrapper tagFactory, - std::reference_wrapper dosGuard, + std::reference_wrapper dosGuard, std::shared_ptr const& handler, boost::beast::flat_buffer buffer) - : HttpBase(ip, tagFactory, dosGuard, handler, std::move(buffer)) + : detail::HttpBase(ip, tagFactory, dosGuard, handler, std::move(buffer)) , stream_(std::move(socket)) , tagFactory_(tagFactory) { @@ -64,7 +65,8 @@ public: { boost::asio::dispatch( stream_.get_executor(), - boost::beast::bind_front_handler(&HttpBase::doRead, this->shared_from_this())); + boost::beast::bind_front_handler( + &detail::HttpBase::doRead, this->shared_from_this())); } void @@ -88,4 +90,4 @@ public: ->run(); } }; -} // namespace Server +} // namespace web diff --git a/src/webserver/PlainWsSession.h b/src/webserver/PlainWsSession.h index 42742509..9a0df754 100644 --- a/src/webserver/PlainWsSession.h +++ b/src/webserver/PlainWsSession.h @@ -21,14 +21,14 @@ #include -namespace Server { +namespace web { /** * @brief The plain WebSocket session class, just to hold the plain stream. Other operations will be handled by the base * class */ template -class PlainWsSession : public WsBase +class PlainWsSession : public detail::WsBase { boost::beast::websocket::stream ws_; @@ -37,10 +37,11 @@ public: boost::asio::ip::tcp::socket&& socket, std::string ip, std::reference_wrapper tagFactory, - std::reference_wrapper dosGuard, + std::reference_wrapper dosGuard, std::shared_ptr const& callback, boost::beast::flat_buffer&& buffer) - : WsBase(ip, tagFactory, dosGuard, callback, std::move(buffer)), ws_(std::move(socket)) + : detail::WsBase(ip, tagFactory, dosGuard, callback, std::move(buffer)) + , ws_(std::move(socket)) { } @@ -64,7 +65,7 @@ class WsUpgrader : public std::enable_shared_from_this> boost::optional> parser_; boost::beast::flat_buffer buffer_; std::reference_wrapper tagFactory_; - std::reference_wrapper dosGuard_; + std::reference_wrapper dosGuard_; http::request req_; std::string ip_; std::shared_ptr const handler_; @@ -74,7 +75,7 @@ public: boost::beast::tcp_stream&& stream, std::string ip, std::reference_wrapper tagFactory, - std::reference_wrapper dosGuard, + std::reference_wrapper dosGuard, std::shared_ptr const& handler, boost::beast::flat_buffer&& b, http::request req) @@ -127,4 +128,4 @@ private: } }; -} // namespace Server +} // namespace web diff --git a/src/webserver/RPCServerHandler.h b/src/webserver/RPCServerHandler.h index 728a0dff..ee5b76d2 100644 --- a/src/webserver/RPCServerHandler.h +++ b/src/webserver/RPCServerHandler.h @@ -45,12 +45,12 @@ class RPCServerHandler util::TagDecoratorFactory const tagFactory_; RPC::detail::ProductionAPIVersionParser apiVersionParser_; // can be injected if needed - clio::Logger log_{"RPC"}; - clio::Logger perfLog_{"Performance"}; + util::Logger log_{"RPC"}; + util::Logger perfLog_{"Performance"}; public: RPCServerHandler( - clio::Config const& config, + util::Config const& config, std::shared_ptr const& backend, std::shared_ptr const& rpcEngine, std::shared_ptr const& etl, @@ -70,7 +70,7 @@ public: * @param connection The connection */ void - operator()(std::string const& reqStr, std::shared_ptr const& connection) + operator()(std::string const& reqStr, std::shared_ptr const& connection) { try { @@ -87,20 +87,20 @@ public: connection->clientIp)) { rpcEngine_->notifyTooBusy(); - Server::detail::ErrorHelper(connection).sendTooBusyError(); + web::detail::ErrorHelper(connection).sendTooBusyError(); } } catch (boost::system::system_error const& ex) { // system_error thrown when json parsing failed rpcEngine_->notifyBadSyntax(); - Server::detail::ErrorHelper(connection).sendJsonParsingError(ex.what()); + web::detail::ErrorHelper(connection).sendJsonParsingError(ex.what()); } catch (std::invalid_argument const& ex) { // thrown when json parses something that is not an object at top level rpcEngine_->notifyBadSyntax(); - Server::detail::ErrorHelper(connection).sendJsonParsingError(ex.what()); + web::detail::ErrorHelper(connection).sendJsonParsingError(ex.what()); } catch (std::exception const& ex) { @@ -117,7 +117,7 @@ public: * @param connection The connection */ void - operator()(boost::beast::error_code _, std::shared_ptr const& connection) + operator()(boost::beast::error_code _, std::shared_ptr const& connection) { if (auto manager = subscriptions_.lock(); manager) manager->cleanup(connection); @@ -128,7 +128,7 @@ private: handleRequest( boost::asio::yield_context yield, boost::json::object&& request, - std::shared_ptr const& connection) + std::shared_ptr const& connection) { log_.info() << connection->tag() << (connection->upgraded ? "ws" : "http") << " received request from work queue: " << util::removeSecret(request) @@ -141,7 +141,7 @@ private: { // for error that happened before the handler, we don't attach any warnings rpcEngine_->notifyNotReady(); - return Server::detail::ErrorHelper(connection, request).sendNotReadyError(); + return web::detail::ErrorHelper(connection, request).sendNotReadyError(); } auto const context = [&] { @@ -173,7 +173,7 @@ private: // we count all those as BadSyntax - as the WS path would. // Although over HTTP these will yield a 400 status with a plain text response (for most). rpcEngine_->notifyBadSyntax(); - return Server::detail::ErrorHelper(connection, request).sendError(err); + return web::detail::ErrorHelper(connection, request).sendError(err); } auto [v, timeDiff] = util::timed([&]() { return rpcEngine_->buildResponse(*context); }); @@ -185,7 +185,7 @@ private: if (auto const status = std::get_if(&v)) { // note: error statuses are counted/notified in buildResponse itself - response = Server::detail::ErrorHelper(connection, request).composeError(*status); + response = web::detail::ErrorHelper(connection, request).composeError(*status); auto const responseStr = boost::json::serialize(response); perfLog_.debug() << context->tag() << "Encountered error: " << responseStr; @@ -250,7 +250,7 @@ private: log_.error() << connection->tag() << "Caught exception: " << ex.what(); rpcEngine_->notifyInternalError(); - return Server::detail::ErrorHelper(connection, request).sendInternalError(); + return web::detail::ErrorHelper(connection, request).sendInternalError(); } } }; diff --git a/src/webserver/Server.h b/src/webserver/Server.h index 1f389895..809c1019 100644 --- a/src/webserver/Server.h +++ b/src/webserver/Server.h @@ -19,14 +19,14 @@ #pragma once -#include +#include #include #include #include #include -namespace Server { +namespace web { /** * @brief The Detector class to detect if the connection is a ssl or not. @@ -40,11 +40,11 @@ class Detector : public std::enable_shared_from_this>::shared_from_this; - clio::Logger log_{"WebServer"}; + util::Logger log_{"WebServer"}; boost::beast::tcp_stream stream_; std::optional> ctx_; std::reference_wrapper tagFactory_; - std::reference_wrapper const dosGuard_; + std::reference_wrapper const dosGuard_; std::shared_ptr const handler_; boost::beast::flat_buffer buffer_; @@ -53,7 +53,7 @@ public: tcp::socket&& socket, std::optional> ctx, std::reference_wrapper tagFactory, - std::reference_wrapper dosGuard, + std::reference_wrapper dosGuard, std::shared_ptr const& handler) : stream_(std::move(socket)) , ctx_(ctx) @@ -124,11 +124,11 @@ class Server : public std::enable_shared_from_this>::shared_from_this; - clio::Logger log_{"WebServer"}; + util::Logger log_{"WebServer"}; std::reference_wrapper ioc_; std::optional> ctx_; util::TagDecoratorFactory tagFactory_; - std::reference_wrapper dosGuard_; + std::reference_wrapper dosGuard_; std::shared_ptr handler_; tcp::acceptor acceptor_; @@ -138,7 +138,7 @@ public: std::optional> ctx, tcp::endpoint endpoint, util::TagDecoratorFactory tagFactory, - clio::DOSGuard& dosGuard, + web::DOSGuard& dosGuard, std::shared_ptr const& callback) : ioc_(std::ref(ioc)) , ctx_(ctx) @@ -221,13 +221,13 @@ using HttpServer = Server; template static std::shared_ptr> make_HttpServer( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioc, std::optional> const& sslCtx, - clio::DOSGuard& dosGuard, + web::DOSGuard& dosGuard, std::shared_ptr const& handler) { - static clio::Logger log{"WebServer"}; + static util::Logger log{"WebServer"}; if (!config.contains("server")) return nullptr; @@ -247,4 +247,4 @@ make_HttpServer( return server; } -} // namespace Server +} // namespace web diff --git a/src/webserver/SslHttpSession.h b/src/webserver/SslHttpSession.h index 4adb47eb..6c88a64c 100644 --- a/src/webserver/SslHttpSession.h +++ b/src/webserver/SslHttpSession.h @@ -22,7 +22,7 @@ #include #include -namespace Server { +namespace web { using tcp = boost::asio::ip::tcp; @@ -32,7 +32,7 @@ using tcp = boost::asio::ip::tcp; * It will also handle the session upgrade to WebSocket. */ template -class SslHttpSession : public HttpBase, +class SslHttpSession : public detail::HttpBase, public std::enable_shared_from_this> { boost::beast::ssl_stream stream_; @@ -44,10 +44,10 @@ public: std::string const& ip, boost::asio::ssl::context& ctx, std::reference_wrapper tagFactory, - std::reference_wrapper dosGuard, + std::reference_wrapper dosGuard, std::shared_ptr const& handler, boost::beast::flat_buffer buffer) - : HttpBase(ip, tagFactory, dosGuard, handler, std::move(buffer)) + : detail::HttpBase(ip, tagFactory, dosGuard, handler, std::move(buffer)) , stream_(std::move(socket), ctx) , tagFactory_(tagFactory) { @@ -120,4 +120,4 @@ public: ->run(); } }; -} // namespace Server +} // namespace web diff --git a/src/webserver/SslWsSession.h b/src/webserver/SslWsSession.h index 7d36c880..d54766b9 100644 --- a/src/webserver/SslWsSession.h +++ b/src/webserver/SslWsSession.h @@ -21,14 +21,14 @@ #include -namespace Server { +namespace web { /** * @brief The SSL WebSocket session class, just to hold the ssl stream. Other operations will be handled by the base * class. */ template -class SslWsSession : public WsBase +class SslWsSession : public detail::WsBase { using StreamType = boost::beast::websocket::stream>; StreamType ws_; @@ -38,10 +38,10 @@ public: boost::beast::ssl_stream&& stream, std::string ip, std::reference_wrapper tagFactory, - std::reference_wrapper dosGuard, + std::reference_wrapper dosGuard, std::shared_ptr const& handler, boost::beast::flat_buffer&& b) - : WsBase(ip, tagFactory, dosGuard, handler, std::move(b)), ws_(std::move(stream)) + : detail::WsBase(ip, tagFactory, dosGuard, handler, std::move(b)), ws_(std::move(stream)) { } @@ -63,7 +63,7 @@ class SslWsUpgrader : public std::enable_shared_from_this boost::beast::flat_buffer buffer_; std::string ip_; std::reference_wrapper tagFactory_; - std::reference_wrapper dosGuard_; + std::reference_wrapper dosGuard_; std::shared_ptr const handler_; http::request req_; @@ -72,7 +72,7 @@ public: boost::beast::ssl_stream stream, std::string ip, std::reference_wrapper tagFactory, - std::reference_wrapper dosGuard, + std::reference_wrapper dosGuard, std::shared_ptr const& handler, boost::beast::flat_buffer&& buf, http::request req) @@ -134,4 +134,4 @@ private: ->run(std::move(req_)); } }; -} // namespace Server +} // namespace web diff --git a/src/webserver/impl/ErrorHandling.h b/src/webserver/impl/ErrorHandling.h index 8b175860..4b81c442 100644 --- a/src/webserver/impl/ErrorHandling.h +++ b/src/webserver/impl/ErrorHandling.h @@ -29,19 +29,19 @@ #include #include -namespace Server::detail { +namespace web::detail { /** * @brief A helper that attempts to match rippled reporting mode HTTP errors as close as possible. */ class ErrorHelper { - std::shared_ptr connection_; + std::shared_ptr connection_; std::optional request_; public: ErrorHelper( - std::shared_ptr const& connection, + std::shared_ptr const& connection, std::optional request = std::nullopt) : connection_{connection}, request_{std::move(request)} { @@ -158,4 +158,4 @@ public: } }; -} // namespace Server::detail +} // namespace web::detail diff --git a/src/webserver/impl/HttpBase.h b/src/webserver/impl/HttpBase.h index 62b6d9b8..b50827af 100644 --- a/src/webserver/impl/HttpBase.h +++ b/src/webserver/impl/HttpBase.h @@ -19,8 +19,8 @@ #pragma once -#include #include
+#include #include #include #include @@ -33,7 +33,7 @@ #include #include -namespace Server { +namespace web::detail { using tcp = boost::asio::ip::tcp; @@ -90,10 +90,10 @@ class HttpBase : public ConnectionBase protected: boost::beast::flat_buffer buffer_; http::request req_; - std::reference_wrapper dosGuard_; + std::reference_wrapper dosGuard_; std::shared_ptr const handler_; - clio::Logger log_{"WebServer"}; - clio::Logger perfLog_{"Performance"}; + util::Logger log_{"WebServer"}; + util::Logger perfLog_{"Performance"}; inline void httpFail(boost::beast::error_code ec, char const* what) @@ -130,7 +130,7 @@ public: HttpBase( std::string const& ip, std::reference_wrapper tagFactory, - std::reference_wrapper dosGuard, + std::reference_wrapper dosGuard, std::shared_ptr const& handler, boost::beast::flat_buffer buffer) : ConnectionBase(tagFactory, ip) @@ -273,4 +273,4 @@ private: }; }; -} // namespace Server +} // namespace web::detail diff --git a/src/webserver/impl/IntervalSweepHandler.h b/src/webserver/impl/IntervalSweepHandler.h new file mode 100644 index 00000000..6e8da34c --- /dev/null +++ b/src/webserver/impl/IntervalSweepHandler.h @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +/* + This file is part of clio: https://github.com/XRPLF/clio + Copyright (c) 2022, the clio developers. + + Permission to use, copy, modify, and distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#pragma once + +#include +#include +#include + +#include +#include +#include + +namespace web::detail { + +/** + * @brief Sweep handler using a steady_timer and boost::asio::io_context. + */ +class IntervalSweepHandler +{ + std::chrono::milliseconds sweepInterval_; + std::reference_wrapper ctx_; + boost::asio::steady_timer timer_; + + web::BaseDOSGuard* dosGuard_ = nullptr; + +public: + /** + * @brief Construct a new interval-based sweep handler + * + * @param config Clio config + * @param ctx The boost::asio::io_context + */ + IntervalSweepHandler(util::Config const& config, boost::asio::io_context& ctx) + : sweepInterval_{std::max(1u, static_cast(config.valueOr("dos_guard.sweep_interval", 1.0) * 1000.0))} + , ctx_{std::ref(ctx)} + , timer_{ctx.get_executor()} + { + } + + ~IntervalSweepHandler() + { + timer_.cancel(); + } + + /** + * @brief This setup member function is called by @ref BasicDOSGuard during + * its initialization. + * + * @param guard Pointer to the dos guard + */ + void + setup(web::BaseDOSGuard* guard) + { + assert(dosGuard_ == nullptr); + dosGuard_ = guard; + assert(dosGuard_ != nullptr); + + createTimer(); + } + +private: + void + createTimer() + { + timer_.expires_after(sweepInterval_); + timer_.async_wait([this](boost::system::error_code const& error) { + if (error == boost::asio::error::operation_aborted) + return; + + dosGuard_->clear(); + boost::asio::post(ctx_.get().get_executor(), [this] { createTimer(); }); + }); + } +}; + +} // namespace web::detail \ No newline at end of file diff --git a/src/webserver/impl/WhitelistHandler.h b/src/webserver/impl/WhitelistHandler.h index 304db64b..0edff5cb 100644 --- a/src/webserver/impl/WhitelistHandler.h +++ b/src/webserver/impl/WhitelistHandler.h @@ -27,7 +27,7 @@ #include #include -namespace clio { +namespace web { /** * @brief A whitelist to remove rate limits of certain IP addresses @@ -139,7 +139,7 @@ class WhitelistHandler Whitelist whitelist_; public: - WhitelistHandler(clio::Config const& config) + WhitelistHandler(util::Config const& config) { std::unordered_set arr = getWhitelist(config); for (auto const& net : arr) @@ -154,7 +154,7 @@ public: private: [[nodiscard]] std::unordered_set const - getWhitelist(clio::Config const& config) const + getWhitelist(util::Config const& config) const { using T = std::unordered_set const; auto whitelist = config.arrayOr("dos_guard.whitelist", {}); @@ -164,4 +164,4 @@ private: boost::transform_iterator(std::end(whitelist), transform)}; } }; -} // namespace clio \ No newline at end of file +} // namespace web \ No newline at end of file diff --git a/src/webserver/impl/WsBase.h b/src/webserver/impl/WsBase.h index 5291a33d..2f90252e 100644 --- a/src/webserver/impl/WsBase.h +++ b/src/webserver/impl/WsBase.h @@ -19,8 +19,8 @@ #pragma once -#include #include +#include #include #include #include @@ -31,7 +31,7 @@ #include #include -namespace Server { +namespace web::detail { /** * @brief Web socket implementation. This class is the base class of the web socket session, it will handle the read and @@ -48,14 +48,14 @@ class WsBase : public ConnectionBase, public std::enable_shared_from_this>::shared_from_this; boost::beast::flat_buffer buffer_; - std::reference_wrapper dosGuard_; + std::reference_wrapper dosGuard_; bool sending_ = false; std::queue> messages_; std::shared_ptr const handler_; protected: - clio::Logger log_{"WebServer"}; - clio::Logger perfLog_{"Performance"}; + util::Logger log_{"WebServer"}; + util::Logger perfLog_{"Performance"}; void wsFail(boost::beast::error_code ec, char const* what) @@ -73,7 +73,7 @@ public: explicit WsBase( std::string ip, std::reference_wrapper tagFactory, - std::reference_wrapper dosGuard, + std::reference_wrapper dosGuard, std::shared_ptr const& handler, boost::beast::flat_buffer&& buffer) : ConnectionBase(tagFactory, ip), buffer_(std::move(buffer)), dosGuard_(dosGuard), handler_(handler) @@ -261,4 +261,4 @@ public: doRead(); } }; -} // namespace Server +} // namespace web::detail diff --git a/src/webserver/interface/Concepts.h b/src/webserver/interface/Concepts.h index 4cc4e510..9df26257 100644 --- a/src/webserver/interface/Concepts.h +++ b/src/webserver/interface/Concepts.h @@ -25,7 +25,7 @@ #include -namespace Server { +namespace web { /** * @brief Each executor fulfills this interface @@ -40,4 +40,4 @@ concept ServerHandler = requires(T handler, std::string const& req, std::shared_ }; // clang-format on -} // namespace Server +} // namespace web diff --git a/src/webserver/interface/ConnectionBase.h b/src/webserver/interface/ConnectionBase.h index a5987b34..8bf47834 100644 --- a/src/webserver/interface/ConnectionBase.h +++ b/src/webserver/interface/ConnectionBase.h @@ -23,7 +23,7 @@ #include -namespace Server { +namespace web { namespace http = boost::beast::http; @@ -76,4 +76,4 @@ public: virtual ~ConnectionBase() = default; }; -} // namespace Server +} // namespace web diff --git a/unittests/Config.cpp b/unittests/ConfigTests.cpp similarity index 99% rename from unittests/Config.cpp rename to unittests/ConfigTests.cpp index 3de1ad85..c08b5c4d 100644 --- a/unittests/Config.cpp +++ b/unittests/ConfigTests.cpp @@ -17,8 +17,8 @@ */ //============================================================================== -#include #include +#include #include #include @@ -28,7 +28,7 @@ #include #include -using namespace clio; +using namespace util; using namespace boost::log; using namespace std; namespace json = boost::json; diff --git a/unittests/DOSGuard.cpp b/unittests/DOSGuardTests.cpp similarity index 95% rename from unittests/DOSGuard.cpp rename to unittests/DOSGuardTests.cpp index 0c5e3435..e19e1b36 100644 --- a/unittests/DOSGuard.cpp +++ b/unittests/DOSGuardTests.cpp @@ -19,7 +19,7 @@ #include -#include +#include #include #include @@ -27,8 +27,9 @@ #include using namespace testing; -using namespace clio; +using namespace util; using namespace std; +using namespace web; namespace json = boost::json; namespace { @@ -58,12 +59,12 @@ using MockWhitelistHandlerType = NiceMock; class FakeSweepHandler { private: - using guard_type = BasicDOSGuard; - guard_type* dosGuard_; + using guardType = BasicDOSGuard; + guardType* dosGuard_; public: void - setup(guard_type* guard) + setup(guardType* guard) { dosGuard_ = guard; } diff --git a/unittests/JsonUtilTest.cpp b/unittests/JsonUtilTests.cpp similarity index 100% rename from unittests/JsonUtilTest.cpp rename to unittests/JsonUtilTests.cpp diff --git a/unittests/Logger.cpp b/unittests/LoggerTests.cpp similarity index 98% rename from unittests/Logger.cpp rename to unittests/LoggerTests.cpp index e976551d..19030f52 100644 --- a/unittests/Logger.cpp +++ b/unittests/LoggerTests.cpp @@ -18,7 +18,7 @@ //============================================================================== #include -using namespace clio; +using namespace util; // Used as a fixture for tests with enabled logging class LoggerTest : public LoggerFixture diff --git a/unittests/Playground.cpp b/unittests/Playground.cpp index 99d5be89..ad2c2475 100644 --- a/unittests/Playground.cpp +++ b/unittests/Playground.cpp @@ -19,7 +19,7 @@ #include -using namespace clio; +using namespace util; /* * Use this file for temporary tests and implementations. diff --git a/unittests/ProfilerTest.cpp b/unittests/ProfilerTests.cpp similarity index 100% rename from unittests/ProfilerTest.cpp rename to unittests/ProfilerTests.cpp diff --git a/unittests/SubscriptionManagerTest.cpp b/unittests/SubscriptionManagerTests.cpp similarity index 97% rename from unittests/SubscriptionManagerTest.cpp rename to unittests/SubscriptionManagerTests.cpp index 3e609308..cc09bddd 100644 --- a/unittests/SubscriptionManagerTest.cpp +++ b/unittests/SubscriptionManagerTests.cpp @@ -30,7 +30,7 @@ using namespace std::chrono_literals; namespace json = boost::json; -using namespace Backend; +using namespace data; using ::testing::Return; // common const @@ -58,14 +58,14 @@ TEST(SubscriptionManagerTest, InitAndReport) "books":0, "book_changes":0 })"; - clio::Config cfg; + util::Config cfg; auto backend = std::make_shared(cfg); auto subManager = SubscriptionManager::make_SubscriptionManager(cfg, backend); EXPECT_EQ(subManager->report(), json::parse(ReportReturn)); } void -CheckSubscriberMessage(std::string out, std::shared_ptr session, int retry = 10) +CheckSubscriberMessage(std::string out, std::shared_ptr session, int retry = 10) { auto sessionPtr = static_cast(session.get()); while (retry-- != 0) @@ -83,10 +83,10 @@ CheckSubscriberMessage(std::string out, std::shared_ptr class SubscriptionManagerSimpleBackendTest : public MockBackendTest { protected: - clio::Config cfg; + util::Config cfg; std::shared_ptr subManagerPtr; util::TagDecoratorFactory tagDecoratorFactory{cfg}; - std::shared_ptr session; + std::shared_ptr session; void SetUp() override { @@ -118,8 +118,8 @@ TEST_F(SubscriptionManagerSimpleBackendTest, ReportCurrentSubscriber) "books":2, "book_changes":2 })"; - std::shared_ptr session1 = std::make_shared(tagDecoratorFactory); - std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session1 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); subManagerPtr->subBookChanges(session1); subManagerPtr->subBookChanges(session2); subManagerPtr->subManifest(session1); @@ -258,7 +258,7 @@ TEST_F(SubscriptionManagerSimpleBackendTest, SubscriptionManagerAccountProposedT auto account = GetAccountIDWithString(ACCOUNT1); subManagerPtr->subProposedAccount(account, session); - std::shared_ptr sessionIdle = std::make_shared(tagDecoratorFactory); + std::shared_ptr sessionIdle = std::make_shared(tagDecoratorFactory); auto accountIdle = GetAccountIDWithString(ACCOUNT2); subManagerPtr->subProposedAccount(accountIdle, sessionIdle); @@ -740,7 +740,7 @@ TEST_F(SubscriptionManagerSimpleBackendTest, SubscriptionManagerOrderBook) CheckSubscriberMessage(OrderbookPublish, session); // trigger by offer cancel meta data - std::shared_ptr session1 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session1 = std::make_shared(tagDecoratorFactory); subManagerPtr->subBook(book, session1); metaObj = CreateMetaDataForCancelOffer(CURRENCY, ISSUER, 22, 3, 1); trans1.metadata = metaObj.getSerializer().peekData(); @@ -829,7 +829,7 @@ TEST_F(SubscriptionManagerSimpleBackendTest, SubscriptionManagerOrderBook) "engine_result":"tesSUCCESS", "engine_result_message":"The transaction was applied. Only final in a validated ledger." })"; - std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); subManagerPtr->subBook(book, session2); metaObj = CreateMetaDataForCreateOffer(CURRENCY, ISSUER, 22, 3, 1); trans1.metadata = metaObj.getSerializer().peekData(); diff --git a/unittests/SubscriptionTest.cpp b/unittests/SubscriptionTests.cpp similarity index 83% rename from unittests/SubscriptionTest.cpp rename to unittests/SubscriptionTests.cpp index 0fe79f19..7c86e1cf 100644 --- a/unittests/SubscriptionTest.cpp +++ b/unittests/SubscriptionTests.cpp @@ -39,7 +39,7 @@ TEST(MessageTest, Message) class SubscriptionTest : public SyncAsioContextTest { protected: - clio::Config cfg; + util::Config cfg; util::TagDecoratorFactory tagDecoratorFactory{cfg}; }; @@ -51,8 +51,8 @@ class SubscriptionMapTest : public SubscriptionTest TEST_F(SubscriptionTest, SubscriptionCount) { Subscription sub(ctx); - std::shared_ptr session1 = std::make_shared(tagDecoratorFactory); - std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session1 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); sub.subscribe(session1); sub.subscribe(session2); ctx.run(); @@ -81,8 +81,8 @@ TEST_F(SubscriptionTest, SubscriptionCount) TEST_F(SubscriptionTest, SubscriptionPublish) { Subscription sub(ctx); - std::shared_ptr session1 = std::make_shared(tagDecoratorFactory); - std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session1 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); sub.subscribe(session1); sub.subscribe(session2); ctx.run(); @@ -108,7 +108,7 @@ TEST_F(SubscriptionTest, SubscriptionPublish) TEST_F(SubscriptionTest, SubscriptionDeadRemoveSubscriber) { Subscription sub(ctx); - std::shared_ptr session1(new MockDeadSession(tagDecoratorFactory)); + std::shared_ptr session1(new MockDeadSession(tagDecoratorFactory)); sub.subscribe(session1); ctx.run(); EXPECT_EQ(sub.count(), 1); @@ -125,9 +125,9 @@ TEST_F(SubscriptionTest, SubscriptionDeadRemoveSubscriber) TEST_F(SubscriptionMapTest, SubscriptionMapCount) { - std::shared_ptr session1 = std::make_shared(tagDecoratorFactory); - std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); - std::shared_ptr session3 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session1 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session3 = std::make_shared(tagDecoratorFactory); SubscriptionMap subMap(ctx); subMap.subscribe(session1, "topic1"); subMap.subscribe(session2, "topic1"); @@ -157,8 +157,8 @@ TEST_F(SubscriptionMapTest, SubscriptionMapCount) TEST_F(SubscriptionMapTest, SubscriptionMapPublish) { - std::shared_ptr session1 = std::make_shared(tagDecoratorFactory); - std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session1 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); SubscriptionMap subMap(ctx); const std::string topic1 = "topic1"; const std::string topic2 = "topic2"; @@ -181,8 +181,8 @@ TEST_F(SubscriptionMapTest, SubscriptionMapPublish) TEST_F(SubscriptionMapTest, SubscriptionMapDeadRemoveSubscriber) { - std::shared_ptr session1(new MockDeadSession(tagDecoratorFactory)); - std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); + std::shared_ptr session1(new MockDeadSession(tagDecoratorFactory)); + std::shared_ptr session2 = std::make_shared(tagDecoratorFactory); SubscriptionMap subMap(ctx); const std::string topic1 = "topic1"; const std::string topic2 = "topic2"; diff --git a/unittests/backend/BackendFactoryTest.cpp b/unittests/data/BackendFactoryTests.cpp similarity index 91% rename from unittests/backend/BackendFactoryTest.cpp rename to unittests/data/BackendFactoryTests.cpp index 12224f17..92e5ddc1 100644 --- a/unittests/backend/BackendFactoryTest.cpp +++ b/unittests/data/BackendFactoryTests.cpp @@ -17,7 +17,7 @@ */ //============================================================================== -#include +#include #include #include @@ -59,7 +59,7 @@ protected: { BackendCassandraFactoryTest::TearDown(); // drop the keyspace for next test - Backend::Cassandra::Handle handle{contactPoints}; + data::cassandra::Handle handle{contactPoints}; EXPECT_TRUE(handle.connect()); handle.execute("DROP KEYSPACE " + std::string{keyspace}); } @@ -67,7 +67,7 @@ protected: TEST_F(BackendCassandraFactoryTest, NoSuchBackend) { - clio::Config cfg{boost::json::parse( + util::Config cfg{boost::json::parse( R"({ "database": { @@ -79,7 +79,7 @@ TEST_F(BackendCassandraFactoryTest, NoSuchBackend) TEST_F(BackendCassandraFactoryTest, CreateCassandraBackendDBDisconnect) { - clio::Config cfg{boost::json::parse(fmt::format( + util::Config cfg{boost::json::parse(fmt::format( R"({{ "database": {{ @@ -99,7 +99,7 @@ TEST_F(BackendCassandraFactoryTest, CreateCassandraBackendDBDisconnect) TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackend) { - clio::Config cfg{boost::json::parse(fmt::format( + util::Config cfg{boost::json::parse(fmt::format( R"({{ "database": {{ @@ -122,7 +122,7 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackend) EXPECT_FALSE(backend->fetchLedgerRange()); // insert range table - Backend::Cassandra::Handle handle{contactPoints}; + data::cassandra::Handle handle{contactPoints}; EXPECT_TRUE(handle.connect()); handle.execute(fmt::format("INSERT INTO {}.ledger_range (is_latest, sequence) VALUES (False, 100)", keyspace)); handle.execute(fmt::format("INSERT INTO {}.ledger_range (is_latest, sequence) VALUES (True, 500)", keyspace)); @@ -140,7 +140,7 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackend) TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackendReadOnlyWithEmptyDB) { - clio::Config cfg{boost::json::parse(fmt::format( + util::Config cfg{boost::json::parse(fmt::format( R"({{ "read_only": true, "database": @@ -160,7 +160,7 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackendReadOnlyWithEmpt TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackendReadOnlyWithDBReady) { - clio::Config cfgReadOnly{boost::json::parse(fmt::format( + util::Config cfgReadOnly{boost::json::parse(fmt::format( R"({{ "read_only": true, "database": @@ -176,7 +176,7 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackendReadOnlyWithDBRe contactPoints, keyspace))}; - clio::Config cfgWrite{boost::json::parse(fmt::format( + util::Config cfgWrite{boost::json::parse(fmt::format( R"({{ "read_only": false, "database": diff --git a/unittests/backend/cassandra/AsyncExecutorTests.cpp b/unittests/data/cassandra/AsyncExecutorTests.cpp similarity index 96% rename from unittests/backend/cassandra/AsyncExecutorTests.cpp rename to unittests/data/cassandra/AsyncExecutorTests.cpp index 52a5cde4..cc6d08f6 100644 --- a/unittests/backend/cassandra/AsyncExecutorTests.cpp +++ b/unittests/data/cassandra/AsyncExecutorTests.cpp @@ -17,16 +17,16 @@ */ //============================================================================== -#include +#include #include -#include -#include +#include +#include #include -using namespace Backend::Cassandra; -using namespace Backend::Cassandra::detail; +using namespace data::cassandra; +using namespace data::cassandra::detail; using namespace testing; class BackendCassandraAsyncExecutorTest : public SyncAsioContextTest diff --git a/unittests/backend/cassandra/BackendTests.cpp b/unittests/data/cassandra/BackendTests.cpp similarity index 97% rename from unittests/backend/cassandra/BackendTests.cpp rename to unittests/data/cassandra/BackendTests.cpp index 5bf530ba..3899a62b 100644 --- a/unittests/backend/cassandra/BackendTests.cpp +++ b/unittests/data/cassandra/BackendTests.cpp @@ -20,21 +20,21 @@ #include #include -#include -#include +#include #include #include +#include #include #include #include -using namespace clio; +using namespace util; using namespace std; using namespace RPC; namespace json = boost::json; -using namespace Backend::Cassandra; +using namespace data::cassandra; namespace { constexpr static auto contactPoints = "127.0.0.1"; @@ -93,7 +93,7 @@ TEST_F(BackendCassandraTest, Basic) ripple::LedgerInfo lgrInfo = util::deserializeHeader(ripple::makeSlice(rawHeaderBlob)); backend->writeLedger(lgrInfo, std::move(rawHeaderBlob)); - backend->writeSuccessor(uint256ToString(Backend::firstKey), lgrInfo.seq, uint256ToString(Backend::lastKey)); + backend->writeSuccessor(uint256ToString(data::firstKey), lgrInfo.seq, uint256ToString(data::lastKey)); ASSERT_TRUE(backend->finishWrites(lgrInfo.seq)); { auto rng = backend->fetchLedgerRange(); @@ -385,8 +385,8 @@ TEST_F(BackendCassandraTest, Basic) backend->writeNFTTransactions(std::move(parsedNFTTxs)); backend->writeLedgerObject(std::string{accountIndexBlob}, lgrInfoNext.seq, std::string{accountBlob}); - backend->writeSuccessor(uint256ToString(Backend::firstKey), lgrInfoNext.seq, std::string{accountIndexBlob}); - backend->writeSuccessor(std::string{accountIndexBlob}, lgrInfoNext.seq, uint256ToString(Backend::lastKey)); + backend->writeSuccessor(uint256ToString(data::firstKey), lgrInfoNext.seq, std::string{accountIndexBlob}); + backend->writeSuccessor(std::string{accountIndexBlob}, lgrInfoNext.seq, uint256ToString(data::lastKey)); ASSERT_TRUE(backend->finishWrites(lgrInfoNext.seq)); } @@ -482,8 +482,7 @@ TEST_F(BackendCassandraTest, Basic) backend->writeLedger(lgrInfoNext, ledgerInfoToBinaryString(lgrInfoNext)); backend->writeLedgerObject(std::string{accountIndexBlob}, lgrInfoNext.seq, std::string{}); - backend->writeSuccessor( - uint256ToString(Backend::firstKey), lgrInfoNext.seq, uint256ToString(Backend::lastKey)); + backend->writeSuccessor(uint256ToString(data::firstKey), lgrInfoNext.seq, uint256ToString(data::lastKey)); ASSERT_TRUE(backend->finishWrites(lgrInfoNext.seq)); } @@ -615,14 +614,13 @@ TEST_F(BackendCassandraTest, Basic) std::string{objs[i].first}, lgrInfo.seq, std::string{objs[i + 1].first}); else backend->writeSuccessor( - std::string{objs[i].first}, lgrInfo.seq, uint256ToString(Backend::lastKey)); + std::string{objs[i].first}, lgrInfo.seq, uint256ToString(data::lastKey)); } if (state.count(lgrInfo.seq - 1)) backend->writeSuccessor( std::string{state[lgrInfo.seq - 1].back().first}, lgrInfo.seq, std::string{objs[0].first}); else - backend->writeSuccessor( - uint256ToString(Backend::firstKey), lgrInfo.seq, std::string{objs[0].first}); + backend->writeSuccessor(uint256ToString(data::firstKey), lgrInfo.seq, std::string{objs[0].first}); } backend->writeAccountTransactions(std::move(accountTx)); @@ -652,8 +650,8 @@ TEST_F(BackendCassandraTest, Basic) } for (auto [account, data] : accountTx) { - std::vector retData; - std::optional cursor; + std::vector retData; + std::optional cursor; do { uint32_t limit = 10; @@ -708,8 +706,8 @@ TEST_F(BackendCassandraTest, Basic) } } - Backend::LedgerPage page; - std::vector retObjs; + data::LedgerPage page; + std::vector retObjs; do { uint32_t limit = 10; @@ -890,7 +888,7 @@ TEST_F(BackendCassandraTest, CacheIntegration) backend->startWrites(); backend->writeLedger(lgrInfo, std::move(rawHeaderBlob)); - backend->writeSuccessor(uint256ToString(Backend::firstKey), lgrInfo.seq, uint256ToString(Backend::lastKey)); + backend->writeSuccessor(uint256ToString(data::firstKey), lgrInfo.seq, uint256ToString(data::lastKey)); ASSERT_TRUE(backend->finishWrites(lgrInfo.seq)); { auto rng = backend->fetchLedgerRange(); @@ -964,8 +962,8 @@ TEST_F(BackendCassandraTest, CacheIntegration) backend->writeLedgerObject(std::string{accountIndexBlob}, lgrInfoNext.seq, std::string{accountBlob}); auto key = ripple::uint256::fromVoidChecked(accountIndexBlob); backend->cache().update({{*key, {accountBlob.begin(), accountBlob.end()}}}, lgrInfoNext.seq); - backend->writeSuccessor(uint256ToString(Backend::firstKey), lgrInfoNext.seq, std::string{accountIndexBlob}); - backend->writeSuccessor(std::string{accountIndexBlob}, lgrInfoNext.seq, uint256ToString(Backend::lastKey)); + backend->writeSuccessor(uint256ToString(data::firstKey), lgrInfoNext.seq, std::string{accountIndexBlob}); + backend->writeSuccessor(std::string{accountIndexBlob}, lgrInfoNext.seq, uint256ToString(data::lastKey)); ASSERT_TRUE(backend->finishWrites(lgrInfoNext.seq)); } @@ -1041,8 +1039,7 @@ TEST_F(BackendCassandraTest, CacheIntegration) auto key = ripple::uint256::fromVoidChecked(accountIndexBlob); backend->cache().update({{*key, {}}}, lgrInfoNext.seq); backend->writeLedgerObject(std::string{accountIndexBlob}, lgrInfoNext.seq, std::string{}); - backend->writeSuccessor( - uint256ToString(Backend::firstKey), lgrInfoNext.seq, uint256ToString(Backend::lastKey)); + backend->writeSuccessor(uint256ToString(data::firstKey), lgrInfoNext.seq, uint256ToString(data::lastKey)); ASSERT_TRUE(backend->finishWrites(lgrInfoNext.seq)); } @@ -1102,7 +1099,7 @@ TEST_F(BackendCassandraTest, CacheIntegration) backend->startWrites(); backend->writeLedger(lgrInfo, std::move(ledgerInfoToBinaryString(lgrInfo))); - std::vector cacheUpdates; + std::vector cacheUpdates; for (auto [key, obj] : objs) { backend->writeLedgerObject(std::string{key}, lgrInfo.seq, std::string{obj}); @@ -1122,14 +1119,13 @@ TEST_F(BackendCassandraTest, CacheIntegration) std::string{objs[i].first}, lgrInfo.seq, std::string{objs[i + 1].first}); else backend->writeSuccessor( - std::string{objs[i].first}, lgrInfo.seq, uint256ToString(Backend::lastKey)); + std::string{objs[i].first}, lgrInfo.seq, uint256ToString(data::lastKey)); } if (state.count(lgrInfo.seq - 1)) backend->writeSuccessor( std::string{state[lgrInfo.seq - 1].back().first}, lgrInfo.seq, std::string{objs[0].first}); else - backend->writeSuccessor( - uint256ToString(Backend::firstKey), lgrInfo.seq, std::string{objs[0].first}); + backend->writeSuccessor(uint256ToString(data::firstKey), lgrInfo.seq, std::string{objs[0].first}); } ASSERT_TRUE(backend->finishWrites(lgrInfo.seq)); @@ -1186,8 +1182,8 @@ TEST_F(BackendCassandraTest, CacheIntegration) } } } - Backend::LedgerPage page; - std::vector retObjs; + data::LedgerPage page; + std::vector retObjs; do { uint32_t limit = 10; diff --git a/unittests/backend/cassandra/BaseTests.cpp b/unittests/data/cassandra/BaseTests.cpp similarity index 98% rename from unittests/backend/cassandra/BaseTests.cpp rename to unittests/data/cassandra/BaseTests.cpp index 1d34f82d..1e303485 100644 --- a/unittests/backend/cassandra/BaseTests.cpp +++ b/unittests/data/cassandra/BaseTests.cpp @@ -19,17 +19,16 @@ #include -#include +#include #include #include #include -using namespace clio; using namespace std; -using namespace Backend::Cassandra; +using namespace data::cassandra; namespace json = boost::json; @@ -368,7 +367,7 @@ TEST_F(BackendCassandraBaseTest, BatchInsertAsync) // write data in bulk { bool complete = false; - std::optional fut; + std::optional fut; { std::vector statements; diff --git a/unittests/backend/cassandra/ExecutionStrategyTests.cpp b/unittests/data/cassandra/ExecutionStrategyTests.cpp similarity index 98% rename from unittests/backend/cassandra/ExecutionStrategyTests.cpp rename to unittests/data/cassandra/ExecutionStrategyTests.cpp index 2048df17..bde18a82 100644 --- a/unittests/backend/cassandra/ExecutionStrategyTests.cpp +++ b/unittests/data/cassandra/ExecutionStrategyTests.cpp @@ -17,15 +17,15 @@ */ //============================================================================== -#include +#include #include -#include +#include #include -using namespace Backend::Cassandra; -using namespace Backend::Cassandra::detail; +using namespace data::cassandra; +using namespace data::cassandra::detail; using namespace testing; class BackendCassandraExecutionStrategyTest : public SyncAsioContextTest diff --git a/unittests/backend/cassandra/RetryPolicyTests.cpp b/unittests/data/cassandra/RetryPolicyTests.cpp similarity index 95% rename from unittests/backend/cassandra/RetryPolicyTests.cpp rename to unittests/data/cassandra/RetryPolicyTests.cpp index d0772af3..3bb0a4c9 100644 --- a/unittests/backend/cassandra/RetryPolicyTests.cpp +++ b/unittests/data/cassandra/RetryPolicyTests.cpp @@ -19,13 +19,13 @@ #include -#include -#include +#include +#include #include -using namespace Backend::Cassandra; -using namespace Backend::Cassandra::detail; +using namespace data::cassandra; +using namespace data::cassandra::detail; using namespace testing; class BackendCassandraRetryPolicyTest : public SyncAsioContextTest diff --git a/unittests/backend/cassandra/SettingsProviderTests.cpp b/unittests/data/cassandra/SettingsProviderTests.cpp similarity index 98% rename from unittests/backend/cassandra/SettingsProviderTests.cpp rename to unittests/data/cassandra/SettingsProviderTests.cpp index 2846de4f..92ed4699 100644 --- a/unittests/backend/cassandra/SettingsProviderTests.cpp +++ b/unittests/data/cassandra/SettingsProviderTests.cpp @@ -20,8 +20,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -30,11 +30,11 @@ #include #include -using namespace clio; +using namespace util; using namespace std; namespace json = boost::json; -using namespace Backend::Cassandra; +using namespace data::cassandra; class SettingsProviderTest : public NoLoggerFixture { diff --git a/unittests/backend/cassandra/impl/FakesAndMocks.h b/unittests/data/cassandra/impl/FakesAndMocks.h similarity index 94% rename from unittests/backend/cassandra/impl/FakesAndMocks.h rename to unittests/data/cassandra/impl/FakesAndMocks.h index 4e506224..75b6f286 100644 --- a/unittests/backend/cassandra/impl/FakesAndMocks.h +++ b/unittests/data/cassandra/impl/FakesAndMocks.h @@ -17,15 +17,15 @@ */ //============================================================================== -#include -#include +#include +#include #include #include -using namespace Backend::Cassandra; -using namespace Backend::Cassandra::detail; +using namespace data::cassandra; +using namespace data::cassandra::detail; struct FakeResult { diff --git a/unittests/etl/CacheLoaderTest.cpp b/unittests/etl/CacheLoaderTests.cpp similarity index 98% rename from unittests/etl/CacheLoaderTest.cpp rename to unittests/etl/CacheLoaderTests.cpp index 124e2dbb..050a367c 100644 --- a/unittests/etl/CacheLoaderTest.cpp +++ b/unittests/etl/CacheLoaderTests.cpp @@ -26,9 +26,9 @@ #include namespace json = boost::json; -using namespace clio::detail; -using namespace clio; -using namespace Backend; +using namespace etl::detail; +using namespace util; +using namespace data; using namespace testing; constexpr static auto SEQ = 30; diff --git a/unittests/etl/ExtractionDataPipeTest.cpp b/unittests/etl/ExtractionDataPipeTests.cpp similarity index 97% rename from unittests/etl/ExtractionDataPipeTest.cpp rename to unittests/etl/ExtractionDataPipeTests.cpp index 5ab8100a..da59277f 100644 --- a/unittests/etl/ExtractionDataPipeTest.cpp +++ b/unittests/etl/ExtractionDataPipeTests.cpp @@ -29,7 +29,7 @@ constexpr static auto START_SEQ = 1234; class ETLExtractionDataPipeTest : public NoLoggerFixture { protected: - clio::detail::ExtractionDataPipe pipe_{STRIDE, START_SEQ}; + etl::detail::ExtractionDataPipe pipe_{STRIDE, START_SEQ}; }; TEST_F(ETLExtractionDataPipeTest, StrideMatchesInput) diff --git a/unittests/etl/ExtractorTest.cpp b/unittests/etl/ExtractorTests.cpp similarity index 98% rename from unittests/etl/ExtractorTest.cpp rename to unittests/etl/ExtractorTests.cpp index 2ebac3ea..487b1d2c 100644 --- a/unittests/etl/ExtractorTest.cpp +++ b/unittests/etl/ExtractorTests.cpp @@ -36,7 +36,7 @@ protected: using ExtractionDataPipeType = MockExtractionDataPipe; using LedgerFetcherType = MockLedgerFetcher; using ExtractorType = - clio::detail::Extractor; + etl::detail::Extractor; ExtractionDataPipeType dataPipe_; std::shared_ptr networkValidatedLedgers_ = diff --git a/unittests/etl/TransformerTest.cpp b/unittests/etl/TransformerTests.cpp similarity index 98% rename from unittests/etl/TransformerTest.cpp rename to unittests/etl/TransformerTests.cpp index 5d96fc41..d73f9e82 100644 --- a/unittests/etl/TransformerTest.cpp +++ b/unittests/etl/TransformerTests.cpp @@ -46,7 +46,7 @@ protected: using ExtractionDataPipeType = MockExtractionDataPipe; using LedgerLoaderType = MockLedgerLoader; using LedgerPublisherType = MockLedgerPublisher; - using TransformerType = clio::detail::Transformer; + using TransformerType = etl::detail::Transformer; ExtractionDataPipeType dataPipe_; LedgerLoaderType ledgerLoader_; diff --git a/unittests/rpc/APIVersionTests.cpp b/unittests/rpc/APIVersionTests.cpp index bdb2bc64..13a391b0 100644 --- a/unittests/rpc/APIVersionTests.cpp +++ b/unittests/rpc/APIVersionTests.cpp @@ -94,7 +94,7 @@ TEST_F(RPCAPIVersionTest, ReturnsParsedVersionIfAllPreconditionsAreMet) TEST_F(RPCAPIVersionTest, GetsValuesFromConfigCorrectly) { - clio::Config cfg{json::parse(fmt::format( + util::Config cfg{json::parse(fmt::format( R"({{ "min": {}, "max": {}, diff --git a/unittests/rpc/AdminVerificationTest.cpp b/unittests/rpc/AdminVerificationTests.cpp similarity index 100% rename from unittests/rpc/AdminVerificationTest.cpp rename to unittests/rpc/AdminVerificationTests.cpp diff --git a/unittests/rpc/AmendmentsTest.cpp b/unittests/rpc/AmendmentsTests.cpp similarity index 100% rename from unittests/rpc/AmendmentsTest.cpp rename to unittests/rpc/AmendmentsTests.cpp diff --git a/unittests/rpc/BaseTests.cpp b/unittests/rpc/BaseTests.cpp index 27d4bcd6..ce2c8dc0 100644 --- a/unittests/rpc/BaseTests.cpp +++ b/unittests/rpc/BaseTests.cpp @@ -33,7 +33,6 @@ #include #include -using namespace clio; using namespace std; using namespace RPC; diff --git a/unittests/rpc/CountersTest.cpp b/unittests/rpc/CountersTests.cpp similarity index 99% rename from unittests/rpc/CountersTest.cpp rename to unittests/rpc/CountersTests.cpp index 95fc8834..d88a0e30 100644 --- a/unittests/rpc/CountersTest.cpp +++ b/unittests/rpc/CountersTests.cpp @@ -25,7 +25,6 @@ #include #include -using namespace clio; using namespace RPC; class RPCCountersTest : public NoLoggerFixture diff --git a/unittests/rpc/ForwardingProxyTests.cpp b/unittests/rpc/ForwardingProxyTests.cpp index 3955bc95..ebb71fe8 100644 --- a/unittests/rpc/ForwardingProxyTests.cpp +++ b/unittests/rpc/ForwardingProxyTests.cpp @@ -22,13 +22,12 @@ #include #include -#include #include +#include #include #include -using namespace clio; using namespace RPC; using namespace testing; @@ -41,7 +40,7 @@ protected: std::shared_ptr handlerProvider = std::make_shared(); MockCounters counters; - clio::Config config; + util::Config config; util::TagDecoratorFactory tagFactory{config}; RPC::detail::ForwardingProxy proxy{ @@ -63,7 +62,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfClioOnly) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_FALSE(res); @@ -83,7 +82,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfProxied) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_TRUE(res); @@ -103,7 +102,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfCurrentLedgerSpecified) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_TRUE(res); @@ -123,7 +122,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfClosedLedgerSpecified) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_TRUE(res); @@ -143,7 +142,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfAccountInfoWithQueueSpe runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_TRUE(res); @@ -163,7 +162,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfLedgerWithQueueSpecifie runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_TRUE(res); @@ -183,7 +182,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfLedgerWithFullSpecified runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_TRUE(res); @@ -203,7 +202,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfLedgerWithAccountsSpeci runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_TRUE(res); @@ -223,7 +222,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfAccountInfoQueueIsFals runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_FALSE(res); @@ -243,7 +242,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfLedgerQueueIsFalse) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_FALSE(res); @@ -263,7 +262,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfLedgerFullIsFalse) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_FALSE(res); @@ -283,7 +282,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfLedgerAccountsIsFalse) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_FALSE(res); @@ -299,7 +298,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfAPIVersionIsV1) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_TRUE(res); @@ -319,7 +318,7 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfAPIVersionIsV2) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_FALSE(res); @@ -335,7 +334,7 @@ TEST_F(RPCForwardingProxyTest, ShouldNeverForwardSubscribe) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_FALSE(res); @@ -351,7 +350,7 @@ TEST_F(RPCForwardingProxyTest, ShouldNeverForwardUnsubscribe) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.shouldForward(ctx); ASSERT_FALSE(res); @@ -379,7 +378,7 @@ TEST_F(RPCForwardingProxyTest, ForwardCallsBalancerWithCorrectParams) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.forward(ctx); @@ -409,7 +408,7 @@ TEST_F(RPCForwardingProxyTest, ForwardingFailYieldsErrorStatus) runSpawn([&](auto yield) { auto const range = mockBackendPtr->fetchLedgerRange(); auto const ctx = - Web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); + web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP); auto const res = proxy.forward(ctx); diff --git a/unittests/rpc/RPCHelpersTest.cpp b/unittests/rpc/RPCHelpersTests.cpp similarity index 100% rename from unittests/rpc/RPCHelpersTest.cpp rename to unittests/rpc/RPCHelpersTests.cpp diff --git a/unittests/rpc/WorkQueueTest.cpp b/unittests/rpc/WorkQueueTests.cpp similarity index 99% rename from unittests/rpc/WorkQueueTest.cpp rename to unittests/rpc/WorkQueueTests.cpp index e1c225a3..b2d89362 100644 --- a/unittests/rpc/WorkQueueTest.cpp +++ b/unittests/rpc/WorkQueueTests.cpp @@ -26,7 +26,7 @@ #include #include -using namespace clio; +using namespace util; namespace { constexpr static auto JSONConfig = R"JSON({ diff --git a/unittests/rpc/handlers/AccountChannelsTest.cpp b/unittests/rpc/handlers/AccountChannelsTests.cpp similarity index 100% rename from unittests/rpc/handlers/AccountChannelsTest.cpp rename to unittests/rpc/handlers/AccountChannelsTests.cpp diff --git a/unittests/rpc/handlers/AccountCurrenciesTest.cpp b/unittests/rpc/handlers/AccountCurrenciesTests.cpp similarity index 100% rename from unittests/rpc/handlers/AccountCurrenciesTest.cpp rename to unittests/rpc/handlers/AccountCurrenciesTests.cpp diff --git a/unittests/rpc/handlers/AccountInfoTest.cpp b/unittests/rpc/handlers/AccountInfoTests.cpp similarity index 100% rename from unittests/rpc/handlers/AccountInfoTest.cpp rename to unittests/rpc/handlers/AccountInfoTests.cpp diff --git a/unittests/rpc/handlers/AccountLinesTest.cpp b/unittests/rpc/handlers/AccountLinesTests.cpp similarity index 100% rename from unittests/rpc/handlers/AccountLinesTest.cpp rename to unittests/rpc/handlers/AccountLinesTests.cpp diff --git a/unittests/rpc/handlers/AccountNFTsTest.cpp b/unittests/rpc/handlers/AccountNFTsTests.cpp similarity index 100% rename from unittests/rpc/handlers/AccountNFTsTest.cpp rename to unittests/rpc/handlers/AccountNFTsTests.cpp diff --git a/unittests/rpc/handlers/AccountObjectsTest.cpp b/unittests/rpc/handlers/AccountObjectsTests.cpp similarity index 100% rename from unittests/rpc/handlers/AccountObjectsTest.cpp rename to unittests/rpc/handlers/AccountObjectsTests.cpp diff --git a/unittests/rpc/handlers/AccountOffersTest.cpp b/unittests/rpc/handlers/AccountOffersTests.cpp similarity index 100% rename from unittests/rpc/handlers/AccountOffersTest.cpp rename to unittests/rpc/handlers/AccountOffersTests.cpp diff --git a/unittests/rpc/handlers/AccountTxTest.cpp b/unittests/rpc/handlers/AccountTxTests.cpp similarity index 100% rename from unittests/rpc/handlers/AccountTxTest.cpp rename to unittests/rpc/handlers/AccountTxTests.cpp diff --git a/unittests/rpc/handlers/BookChangesTest.cpp b/unittests/rpc/handlers/BookChangesTests.cpp similarity index 100% rename from unittests/rpc/handlers/BookChangesTest.cpp rename to unittests/rpc/handlers/BookChangesTests.cpp diff --git a/unittests/rpc/handlers/BookOffersTest.cpp b/unittests/rpc/handlers/BookOffersTests.cpp similarity index 100% rename from unittests/rpc/handlers/BookOffersTest.cpp rename to unittests/rpc/handlers/BookOffersTests.cpp diff --git a/unittests/rpc/handlers/DepositAuthorizedTest.cpp b/unittests/rpc/handlers/DepositAuthorizedTests.cpp similarity index 100% rename from unittests/rpc/handlers/DepositAuthorizedTest.cpp rename to unittests/rpc/handlers/DepositAuthorizedTests.cpp diff --git a/unittests/rpc/handlers/GatewayBalancesTest.cpp b/unittests/rpc/handlers/GatewayBalancesTests.cpp similarity index 100% rename from unittests/rpc/handlers/GatewayBalancesTest.cpp rename to unittests/rpc/handlers/GatewayBalancesTests.cpp diff --git a/unittests/rpc/handlers/LedgerDataTest.cpp b/unittests/rpc/handlers/LedgerDataTests.cpp similarity index 100% rename from unittests/rpc/handlers/LedgerDataTest.cpp rename to unittests/rpc/handlers/LedgerDataTests.cpp diff --git a/unittests/rpc/handlers/LedgerEntryTest.cpp b/unittests/rpc/handlers/LedgerEntryTests.cpp similarity index 100% rename from unittests/rpc/handlers/LedgerEntryTest.cpp rename to unittests/rpc/handlers/LedgerEntryTests.cpp diff --git a/unittests/rpc/handlers/LedgerRangeTest.cpp b/unittests/rpc/handlers/LedgerRangeTests.cpp similarity index 100% rename from unittests/rpc/handlers/LedgerRangeTest.cpp rename to unittests/rpc/handlers/LedgerRangeTests.cpp diff --git a/unittests/rpc/handlers/LedgerTest.cpp b/unittests/rpc/handlers/LedgerTests.cpp similarity index 100% rename from unittests/rpc/handlers/LedgerTest.cpp rename to unittests/rpc/handlers/LedgerTests.cpp diff --git a/unittests/rpc/handlers/NFTBuyOffersTest.cpp b/unittests/rpc/handlers/NFTBuyOffersTests.cpp similarity index 100% rename from unittests/rpc/handlers/NFTBuyOffersTest.cpp rename to unittests/rpc/handlers/NFTBuyOffersTests.cpp diff --git a/unittests/rpc/handlers/NFTHistoryTest.cpp b/unittests/rpc/handlers/NFTHistoryTests.cpp similarity index 100% rename from unittests/rpc/handlers/NFTHistoryTest.cpp rename to unittests/rpc/handlers/NFTHistoryTests.cpp diff --git a/unittests/rpc/handlers/NFTInfoTest.cpp b/unittests/rpc/handlers/NFTInfoTests.cpp similarity index 100% rename from unittests/rpc/handlers/NFTInfoTest.cpp rename to unittests/rpc/handlers/NFTInfoTests.cpp diff --git a/unittests/rpc/handlers/NFTSellOffersTest.cpp b/unittests/rpc/handlers/NFTSellOffersTests.cpp similarity index 100% rename from unittests/rpc/handlers/NFTSellOffersTest.cpp rename to unittests/rpc/handlers/NFTSellOffersTests.cpp diff --git a/unittests/rpc/handlers/NoRippleCheckTest.cpp b/unittests/rpc/handlers/NoRippleCheckTests.cpp similarity index 100% rename from unittests/rpc/handlers/NoRippleCheckTest.cpp rename to unittests/rpc/handlers/NoRippleCheckTests.cpp diff --git a/unittests/rpc/handlers/PingTest.cpp b/unittests/rpc/handlers/PingTests.cpp similarity index 100% rename from unittests/rpc/handlers/PingTest.cpp rename to unittests/rpc/handlers/PingTests.cpp diff --git a/unittests/rpc/handlers/RandomTest.cpp b/unittests/rpc/handlers/RandomTests.cpp similarity index 100% rename from unittests/rpc/handlers/RandomTest.cpp rename to unittests/rpc/handlers/RandomTests.cpp diff --git a/unittests/rpc/handlers/ServerInfoTest.cpp b/unittests/rpc/handlers/ServerInfoTests.cpp similarity index 100% rename from unittests/rpc/handlers/ServerInfoTest.cpp rename to unittests/rpc/handlers/ServerInfoTests.cpp diff --git a/unittests/rpc/handlers/SubscribeTest.cpp b/unittests/rpc/handlers/SubscribeTests.cpp similarity index 99% rename from unittests/rpc/handlers/SubscribeTest.cpp rename to unittests/rpc/handlers/SubscribeTests.cpp index 9df8e9b6..578af73f 100644 --- a/unittests/rpc/handlers/SubscribeTest.cpp +++ b/unittests/rpc/handlers/SubscribeTests.cpp @@ -50,7 +50,7 @@ protected: SetUp() override { HandlerBaseTest::SetUp(); - clio::Config cfg; + util::Config cfg; subManager_ = SubscriptionManager::make_SubscriptionManager(cfg, mockBackendPtr); util::TagDecoratorFactory tagDecoratorFactory{cfg}; session_ = std::make_shared(tagDecoratorFactory); @@ -62,7 +62,7 @@ protected: } std::shared_ptr subManager_; - std::shared_ptr session_; + std::shared_ptr session_; }; struct SubscribeParamTestCaseBundle diff --git a/unittests/rpc/handlers/TransactionEntryTest.cpp b/unittests/rpc/handlers/TransactionEntryTests.cpp similarity index 100% rename from unittests/rpc/handlers/TransactionEntryTest.cpp rename to unittests/rpc/handlers/TransactionEntryTests.cpp diff --git a/unittests/rpc/handlers/TxTest.cpp b/unittests/rpc/handlers/TxTests.cpp similarity index 100% rename from unittests/rpc/handlers/TxTest.cpp rename to unittests/rpc/handlers/TxTests.cpp diff --git a/unittests/rpc/handlers/UnsubscribeTest.cpp b/unittests/rpc/handlers/UnsubscribeTests.cpp similarity index 99% rename from unittests/rpc/handlers/UnsubscribeTest.cpp rename to unittests/rpc/handlers/UnsubscribeTests.cpp index e850239b..b953b341 100644 --- a/unittests/rpc/handlers/UnsubscribeTest.cpp +++ b/unittests/rpc/handlers/UnsubscribeTests.cpp @@ -43,7 +43,7 @@ protected: { HandlerBaseTest::SetUp(); MockSubscriptionManagerTest::SetUp(); - clio::Config cfg; + util::Config cfg; util::TagDecoratorFactory tagDecoratorFactory{cfg}; session_ = std::make_shared(tagDecoratorFactory); } @@ -55,7 +55,7 @@ protected: } std::shared_ptr subManager_; - std::shared_ptr session_; + std::shared_ptr session_; }; struct UnsubscribeParamTestCaseBundle diff --git a/unittests/rpc/handlers/VersionHandlerTest.cpp b/unittests/rpc/handlers/VersionHandlerTests.cpp similarity index 98% rename from unittests/rpc/handlers/VersionHandlerTest.cpp rename to unittests/rpc/handlers/VersionHandlerTests.cpp index 938e0dea..7c374deb 100644 --- a/unittests/rpc/handlers/VersionHandlerTest.cpp +++ b/unittests/rpc/handlers/VersionHandlerTests.cpp @@ -36,7 +36,7 @@ class RPCVersionHandlerTest : public HandlerBaseTest TEST_F(RPCVersionHandlerTest, Default) { - clio::Config cfg{json::parse(fmt::format( + util::Config cfg{json::parse(fmt::format( R"({{ "min": {}, "max": {}, diff --git a/unittests/rpc/handlers/impl/FakesAndMocks.h b/unittests/rpc/handlers/impl/FakesAndMocks.h index c7b38ad8..5fc1f5d8 100644 --- a/unittests/rpc/handlers/impl/FakesAndMocks.h +++ b/unittests/rpc/handlers/impl/FakesAndMocks.h @@ -178,7 +178,7 @@ struct HandlerWithoutInputMock // testing sweep handler by mocking dos guard template -struct BasicDOSGuardMock : public clio::BaseDOSGuard +struct BasicDOSGuardMock : public web::BaseDOSGuard { BasicDOSGuardMock(SweepHandler& handler) { diff --git a/unittests/util/Fixtures.h b/unittests/util/Fixtures.h index 75a87a6b..7e2ae03f 100644 --- a/unittests/util/Fixtures.h +++ b/unittests/util/Fixtures.h @@ -24,7 +24,7 @@ #include "MockETLService.h" #include "MockLoadBalancer.h" #include "MockSubscriptionManager.h" -#include +#include #include #include @@ -34,7 +34,7 @@ #include /** - * @brief Fixture with LogService support. + * @brief Fixture with util::Logger support. */ class LoggerFixture : virtual public ::testing::Test { @@ -58,14 +58,14 @@ class LoggerFixture : virtual public ::testing::Test std::ostream stream_ = std::ostream{&buffer_}; protected: - // Simulates the `LogService::init(config)` call + // Simulates the `util::Logger::init(config)` call void SetUp() override { static std::once_flag once_; std::call_once(once_, [] { boost::log::add_common_attributes(); - boost::log::register_simple_formatter_factory("Severity"); + boost::log::register_simple_formatter_factory("Severity"); }); namespace src = boost::log::sources; @@ -76,9 +76,9 @@ protected: core->remove_all_sinks(); boost::log::add_console_log(stream_, keywords::format = "%Channel%:%Severity% %Message%"); - auto min_severity = expr::channel_severity_filter(clio::log_channel, clio::log_severity); - min_severity["General"] = clio::Severity::DBG; - min_severity["Trace"] = clio::Severity::TRC; + auto min_severity = expr::channel_severity_filter(util::log_channel, util::log_severity); + min_severity["General"] = util::Severity::DBG; + min_severity["Trace"] = util::Severity::TRC; core->set_filter(min_severity); core->set_logging_enabled(true); } @@ -98,7 +98,7 @@ protected: }; /** - * @brief Fixture with LogService support but completely disabled logging. + * @brief Fixture with util::Logger support but completely disabled logging. * * This is meant to be used as a base for other fixtures. */ @@ -194,7 +194,7 @@ struct MockBackendTest : virtual public NoLoggerFixture SetUp() override { NoLoggerFixture::SetUp(); - clio::Config cfg; + util::Config cfg; mockBackendPtr = std::make_shared(cfg); } void diff --git a/unittests/util/MockBackend.h b/unittests/util/MockBackend.h index 52726cb0..56aa41f7 100644 --- a/unittests/util/MockBackend.h +++ b/unittests/util/MockBackend.h @@ -19,14 +19,14 @@ #pragma once -#include +#include #include -using namespace Backend; +using namespace data; struct MockBackend : public BackendInterface { - MockBackend(clio::Config) + MockBackend(util::Config) { } diff --git a/unittests/util/MockCache.h b/unittests/util/MockCache.h index 333b7669..8040778e 100644 --- a/unittests/util/MockCache.h +++ b/unittests/util/MockCache.h @@ -19,19 +19,19 @@ #pragma once -#include +#include #include struct MockCache { - MOCK_METHOD(void, update, (std::vector const& a, uint32_t b, bool c), ()); + MOCK_METHOD(void, update, (std::vector const& a, uint32_t b, bool c), ()); - MOCK_METHOD(std::optional, get, (ripple::uint256 const& a, uint32_t b), (const)); + MOCK_METHOD(std::optional, get, (ripple::uint256 const& a, uint32_t b), (const)); - MOCK_METHOD(std::optional, getSuccessor, (ripple::uint256 const& a, uint32_t b), (const)); + MOCK_METHOD(std::optional, getSuccessor, (ripple::uint256 const& a, uint32_t b), (const)); - MOCK_METHOD(std::optional, getPredecessor, (ripple::uint256 const& a, uint32_t b), (const)); + MOCK_METHOD(std::optional, getPredecessor, (ripple::uint256 const& a, uint32_t b), (const)); MOCK_METHOD(void, setDisabled, (), ()); diff --git a/unittests/util/MockRPCEngine.h b/unittests/util/MockRPCEngine.h index a88918ab..29451958 100644 --- a/unittests/util/MockRPCEngine.h +++ b/unittests/util/MockRPCEngine.h @@ -54,7 +54,7 @@ struct MockAsyncRPCEngine MOCK_METHOD(void, notifyTooBusy, (), ()); MOCK_METHOD(void, notifyUnknownCommand, (), ()); MOCK_METHOD(void, notifyInternalError, (), ()); - MOCK_METHOD(RPC::Result, buildResponse, (Web::Context const&), ()); + MOCK_METHOD(RPC::Result, buildResponse, (web::Context const&), ()); }; struct MockRPCEngine @@ -69,5 +69,5 @@ struct MockRPCEngine MOCK_METHOD(void, notifyTooBusy, (), ()); MOCK_METHOD(void, notifyUnknownCommand, (), ()); MOCK_METHOD(void, notifyInternalError, (), ()); - MOCK_METHOD(RPC::Result, buildResponse, (Web::Context const&), ()); + MOCK_METHOD(RPC::Result, buildResponse, (web::Context const&), ()); }; diff --git a/unittests/util/MockSubscriptionManager.h b/unittests/util/MockSubscriptionManager.h index 8d0a5fb7..927c68dc 100644 --- a/unittests/util/MockSubscriptionManager.h +++ b/unittests/util/MockSubscriptionManager.h @@ -28,7 +28,7 @@ struct MockSubscriptionManager { public: - using session_ptr = std::shared_ptr; + using session_ptr = std::shared_ptr; MockSubscriptionManager() { } @@ -44,7 +44,7 @@ public: MOCK_METHOD( void, pubBookChanges, - (ripple::LedgerInfo const&, std::vector const&), + (ripple::LedgerInfo const&, std::vector const&), ()); MOCK_METHOD(void, unsubLedger, (session_ptr), ()); @@ -53,7 +53,7 @@ public: MOCK_METHOD(void, unsubTransactions, (session_ptr), ()); - MOCK_METHOD(void, pubTransaction, (Backend::TransactionAndMetadata const&, ripple::LedgerInfo const&), ()); + MOCK_METHOD(void, pubTransaction, (data::TransactionAndMetadata const&, ripple::LedgerInfo const&), ()); MOCK_METHOD(void, subAccount, (ripple::AccountID const&, session_ptr&), ()); diff --git a/unittests/util/MockWsBase.h b/unittests/util/MockWsBase.h index 2327d0fb..91103e94 100644 --- a/unittests/util/MockWsBase.h +++ b/unittests/util/MockWsBase.h @@ -21,7 +21,7 @@ #include -struct MockSession : public Server::ConnectionBase +struct MockSession : public web::ConnectionBase { std::string message; void @@ -36,12 +36,12 @@ struct MockSession : public Server::ConnectionBase message += msg; } - MockSession(util::TagDecoratorFactory const& factory) : Server::ConnectionBase(factory, "") + MockSession(util::TagDecoratorFactory const& factory) : web::ConnectionBase(factory, "") { } }; -struct MockDeadSession : public Server::ConnectionBase +struct MockDeadSession : public web::ConnectionBase { void send(std::shared_ptr _) override @@ -55,7 +55,7 @@ struct MockDeadSession : public Server::ConnectionBase { } - MockDeadSession(util::TagDecoratorFactory const& factory) : Server::ConnectionBase(factory, "") + MockDeadSession(util::TagDecoratorFactory const& factory) : web::ConnectionBase(factory, "") { } }; diff --git a/unittests/util/TestObject.cpp b/unittests/util/TestObject.cpp index eb46c459..5da5e8c0 100644 --- a/unittests/util/TestObject.cpp +++ b/unittests/util/TestObject.cpp @@ -18,7 +18,7 @@ //============================================================================== #include "TestObject.h" -#include +#include #include #include @@ -446,10 +446,10 @@ CreateDepositPreauthLedgerObject(std::string_view account, std::string_view auth return depositPreauth; } -Backend::NFT +data::NFT CreateNFT(std::string_view tokenID, std::string_view account, ripple::LedgerIndex seq, ripple::Blob uri, bool isBurned) { - return Backend::NFT{ripple::uint256(tokenID), seq, GetAccountIDWithString(account), uri, isBurned}; + return data::NFT{ripple::uint256(tokenID), seq, GetAccountIDWithString(account), uri, isBurned}; } ripple::STObject @@ -533,7 +533,7 @@ CreateNFTTokenPage( return tokenPage; } -Backend::TransactionAndMetadata +data::TransactionAndMetadata CreateMintNFTTxWithMetadata( std::string_view accountId, uint32_t seq, @@ -589,13 +589,13 @@ CreateMintNFTTxWithMetadata( metaObj.setFieldU8(ripple::sfTransactionResult, ripple::tesSUCCESS); metaObj.setFieldU32(ripple::sfTransactionIndex, 0); - Backend::TransactionAndMetadata ret; + data::TransactionAndMetadata ret; ret.transaction = tx.getSerializer().peekData(); ret.metadata = metaObj.getSerializer().peekData(); return ret; } -Backend::TransactionAndMetadata +data::TransactionAndMetadata CreateAcceptNFTOfferTxWithMetadata(std::string_view accountId, uint32_t seq, uint32_t fee, std::string_view nftId) { // tx @@ -627,14 +627,14 @@ CreateAcceptNFTOfferTxWithMetadata(std::string_view accountId, uint32_t seq, uin metaObj.setFieldU8(ripple::sfTransactionResult, ripple::tesSUCCESS); metaObj.setFieldU32(ripple::sfTransactionIndex, 0); - Backend::TransactionAndMetadata ret; + data::TransactionAndMetadata ret; ret.transaction = tx.getSerializer().peekData(); ret.metadata = metaObj.getSerializer().peekData(); return ret; } // NFTokenCancelOffer can be used to cancel multiple offers -Backend::TransactionAndMetadata +data::TransactionAndMetadata CreateCancelNFTOffersTxWithMetadata( std::string_view accountId, uint32_t seq, @@ -680,13 +680,13 @@ CreateCancelNFTOffersTxWithMetadata( metaObj.setFieldU8(ripple::sfTransactionResult, ripple::tesSUCCESS); metaObj.setFieldU32(ripple::sfTransactionIndex, 0); - Backend::TransactionAndMetadata ret; + data::TransactionAndMetadata ret; ret.transaction = tx.getSerializer().peekData(); ret.metadata = metaObj.getSerializer().peekData(); return ret; } -Backend::TransactionAndMetadata +data::TransactionAndMetadata CreateCreateNFTOfferTxWithMetadata( std::string_view accountId, uint32_t seq, @@ -724,7 +724,7 @@ CreateCreateNFTOfferTxWithMetadata( metaObj.setFieldU8(ripple::sfTransactionResult, ripple::tesSUCCESS); metaObj.setFieldU32(ripple::sfTransactionIndex, 0); - Backend::TransactionAndMetadata ret; + data::TransactionAndMetadata ret; ret.transaction = tx.getSerializer().peekData(); ret.metadata = metaObj.getSerializer().peekData(); return ret; diff --git a/unittests/util/TestObject.h b/unittests/util/TestObject.h index 5dde9619..2c01734b 100644 --- a/unittests/util/TestObject.h +++ b/unittests/util/TestObject.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #include #include @@ -207,7 +207,7 @@ CreateCheckLedgerObject(std::string_view account, std::string_view dest); [[nodiscard]] ripple::STObject CreateDepositPreauthLedgerObject(std::string_view account, std::string_view auth); -[[nodiscard]] Backend::NFT +[[nodiscard]] data::NFT CreateNFT( std::string_view tokenID, std::string_view account, @@ -229,7 +229,7 @@ CreateNFTTokenPage( std::vector> const& tokens, std::optional previousPage); -[[nodiscard]] Backend::TransactionAndMetadata +[[nodiscard]] data::TransactionAndMetadata CreateMintNFTTxWithMetadata( std::string_view accountId, uint32_t seq, @@ -237,20 +237,20 @@ CreateMintNFTTxWithMetadata( uint32_t nfTokenTaxon, std::string_view nftID); -[[nodiscard]] Backend::TransactionAndMetadata +[[nodiscard]] data::TransactionAndMetadata CreateAcceptNFTOfferTxWithMetadata(std::string_view accountId, uint32_t seq, uint32_t fee, std::string_view offerId); -[[nodiscard]] Backend::TransactionAndMetadata +[[nodiscard]] data::TransactionAndMetadata CreateCancelNFTOffersTxWithMetadata( std::string_view accountId, uint32_t seq, uint32_t fee, std::vector const& nftIds); -[[nodiscard]] Backend::TransactionAndMetadata +[[nodiscard]] data::TransactionAndMetadata CreateCreateNFTOfferTxWithMetadata(std::string_view accountId, uint32_t seq, uint32_t fee, std::string_view offerId); -[[nodiscard]] Backend::TransactionAndMetadata +[[nodiscard]] data::TransactionAndMetadata CreateCreateNFTOfferTxWithMetadata( std::string_view accountId, uint32_t seq, diff --git a/unittests/webserver/RPCServerHandlerTest.cpp b/unittests/webserver/RPCServerHandlerTests.cpp similarity index 99% rename from unittests/webserver/RPCServerHandlerTest.cpp rename to unittests/webserver/RPCServerHandlerTests.cpp index 9514face..1a598e4e 100644 --- a/unittests/webserver/RPCServerHandlerTest.cpp +++ b/unittests/webserver/RPCServerHandlerTests.cpp @@ -29,7 +29,7 @@ using namespace std::chrono_literals; constexpr static auto MINSEQ = 10; constexpr static auto MAXSEQ = 30; -struct MockWsBase : public Server::ConnectionBase +struct MockWsBase : public web::ConnectionBase { std::string message; boost::beast::http::status lastStatus = boost::beast::http::status::unknown; @@ -48,7 +48,7 @@ struct MockWsBase : public Server::ConnectionBase lastStatus = status; } - MockWsBase(util::TagDecoratorFactory const& factory) : Server::ConnectionBase(factory, "localhost.fake.ip") + MockWsBase(util::TagDecoratorFactory const& factory) : web::ConnectionBase(factory, "localhost.fake.ip") { } }; @@ -82,7 +82,7 @@ protected: std::shared_ptr tagFactory; std::shared_ptr> handler; std::shared_ptr session; - clio::Config cfg; + util::Config cfg; }; TEST_F(WebRPCServerHandlerTest, HTTPDefaultPath) diff --git a/unittests/webserver/ServerTest.cpp b/unittests/webserver/ServerTests.cpp similarity index 90% rename from unittests/webserver/ServerTest.cpp rename to unittests/webserver/ServerTests.cpp index c270c942..fc894638 100644 --- a/unittests/webserver/ServerTest.cpp +++ b/unittests/webserver/ServerTests.cpp @@ -27,6 +27,10 @@ #include +using namespace util; +using namespace web::detail; +using namespace web; + constexpr static auto JSONData = R"JSON( { "server":{ @@ -143,15 +147,15 @@ protected: // this ctx is for dos timer boost::asio::io_context ctxSync; - clio::Config cfg{boost::json::parse(JSONData)}; - clio::IntervalSweepHandler sweepHandler = clio::IntervalSweepHandler{cfg, ctxSync}; - clio::WhitelistHandler whitelistHandler = clio::WhitelistHandler{cfg}; - clio::DOSGuard dosGuard = clio::DOSGuard{cfg, whitelistHandler, sweepHandler}; + Config cfg{boost::json::parse(JSONData)}; + IntervalSweepHandler sweepHandler = web::IntervalSweepHandler{cfg, ctxSync}; + WhitelistHandler whitelistHandler = web::WhitelistHandler{cfg}; + DOSGuard dosGuard = web::DOSGuard{cfg, whitelistHandler, sweepHandler}; - clio::Config cfgOverload{boost::json::parse(JSONDataOverload)}; - clio::IntervalSweepHandler sweepHandlerOverload = clio::IntervalSweepHandler{cfgOverload, ctxSync}; - clio::WhitelistHandler whitelistHandlerOverload = clio::WhitelistHandler{cfgOverload}; - clio::DOSGuard dosGuardOverload = clio::DOSGuard{cfgOverload, whitelistHandlerOverload, sweepHandlerOverload}; + Config cfgOverload{boost::json::parse(JSONDataOverload)}; + IntervalSweepHandler sweepHandlerOverload = web::IntervalSweepHandler{cfgOverload, ctxSync}; + WhitelistHandler whitelistHandlerOverload = web::WhitelistHandler{cfgOverload}; + DOSGuard dosGuardOverload = web::DOSGuard{cfgOverload, whitelistHandlerOverload, sweepHandlerOverload}; // this ctx is for http server boost::asio::io_context ctx; @@ -164,13 +168,13 @@ class EchoExecutor { public: void - operator()(std::string const& reqStr, std::shared_ptr const& ws) + operator()(std::string const& reqStr, std::shared_ptr const& ws) { ws->send(std::string(reqStr), http::status::ok); } void - operator()(boost::beast::error_code ec, std::shared_ptr const& ws) + operator()(boost::beast::error_code ec, std::shared_ptr const& ws) { } }; @@ -179,13 +183,13 @@ class ExceptionExecutor { public: void - operator()(std::string const& req, std::shared_ptr const& ws) + operator()(std::string const& req, std::shared_ptr const& ws) { throw std::runtime_error("MyError"); } void - operator()(boost::beast::error_code ec, std::shared_ptr const& ws) + operator()(boost::beast::error_code ec, std::shared_ptr const& ws) { } }; @@ -193,20 +197,20 @@ public: namespace { template -static std::shared_ptr> +static std::shared_ptr> makeServerSync( - clio::Config const& config, + util::Config const& config, boost::asio::io_context& ioc, std::optional> const& sslCtx, - clio::DOSGuard& dosGuard, + web::DOSGuard& dosGuard, std::shared_ptr const& handler) { - auto server = std::shared_ptr>(); + auto server = std::shared_ptr>(); std::mutex m; std::condition_variable cv; bool ready = false; boost::asio::dispatch(ioc.get_executor(), [&]() mutable { - server = Server::make_HttpServer(config, ioc, sslCtx, dosGuard, handler); + server = web::make_HttpServer(config, ioc, sslCtx, dosGuard, handler); { std::lock_guard lk(m); ready = true; diff --git a/unittests/webserver/SweepHandlerTest.cpp b/unittests/webserver/SweepHandlerTests.cpp similarity index 96% rename from unittests/webserver/SweepHandlerTest.cpp rename to unittests/webserver/SweepHandlerTests.cpp index 03c73938..67e9bb2e 100644 --- a/unittests/webserver/SweepHandlerTest.cpp +++ b/unittests/webserver/SweepHandlerTests.cpp @@ -17,15 +17,16 @@ */ //============================================================================== -#include #include #include +#include #include #include #include -using namespace clio; +using namespace util; +using namespace web; using namespace testing; constexpr static auto JSONData = R"JSON( diff --git a/unittests/webserver/WhitelistHandlerTest.cpp b/unittests/webserver/WhitelistHandlerTests.cpp similarity index 97% rename from unittests/webserver/WhitelistHandlerTest.cpp rename to unittests/webserver/WhitelistHandlerTests.cpp index d9414a5c..7884e15b 100644 --- a/unittests/webserver/WhitelistHandlerTest.cpp +++ b/unittests/webserver/WhitelistHandlerTests.cpp @@ -16,14 +16,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ //============================================================================== -#include #include +#include #include #include #include -using namespace clio; +using namespace util; +using namespace web; constexpr static auto JSONDataIPV4 = R"JSON( {