Skip to content

Commit

Permalink
Fix review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kuznetsss committed Nov 18, 2024
1 parent 75346ea commit 908b7e3
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/app/ClioApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ ClioApplication::run(bool const useNgWebServer)
LOG(util::LogService::error()) << "Error creating admin verifier: " << expectedAdminVerifier.error();
return EXIT_FAILURE;
}
auto adminVerifier = std::move(expectedAdminVerifier).value();
auto const adminVerifier = std::move(expectedAdminVerifier).value();

auto httpServer = web::ng::make_Server(config_, ioc);

Expand Down
1 change: 1 addition & 0 deletions src/feed/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <memory>

namespace feed {

using Subscriber = web::SubscriptionContextInterface;
using SubscriberPtr = Subscriber*;
using SubscriberSharedPtr = std::shared_ptr<Subscriber>;
Expand Down
10 changes: 5 additions & 5 deletions src/rpc/handlers/Subscribe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "data/BackendInterface.hpp"
#include "data/Types.hpp"
#include "feed/SubscriptionManagerInterface.hpp"
#include "feed/Types.hpp"
#include "rpc/Errors.hpp"
#include "rpc/JS.hpp"
#include "rpc/RPCHelpers.hpp"
Expand All @@ -30,7 +31,6 @@
#include "rpc/common/Specs.hpp"
#include "rpc/common/Types.hpp"
#include "rpc/common/Validators.hpp"
#include "web/SubscriptionContextInterface.hpp"

#include <boost/asio/spawn.hpp>
#include <boost/json/array.hpp>
Expand Down Expand Up @@ -139,7 +139,7 @@ boost::json::object
SubscribeHandler::subscribeToStreams(
boost::asio::yield_context yield,
std::vector<std::string> const& streams,
web::SubscriptionContextPtr const& session
feed::SubscriberSharedPtr const& session
) const
{
auto response = boost::json::object{};
Expand All @@ -166,7 +166,7 @@ SubscribeHandler::subscribeToStreams(
void
SubscribeHandler::subscribeToAccountsProposed(
std::vector<std::string> const& accounts,
web::SubscriptionContextPtr const& session
feed::SubscriberSharedPtr const& session
) const
{
for (auto const& account : accounts) {
Expand All @@ -178,7 +178,7 @@ SubscribeHandler::subscribeToAccountsProposed(
void
SubscribeHandler::subscribeToAccounts(
std::vector<std::string> const& accounts,
web::SubscriptionContextPtr const& session
feed::SubscriberSharedPtr const& session
) const
{
for (auto const& account : accounts) {
Expand All @@ -190,7 +190,7 @@ SubscribeHandler::subscribeToAccounts(
void
SubscribeHandler::subscribeToBooks(
std::vector<OrderBook> const& books,
web::SubscriptionContextPtr const& session,
feed::SubscriberSharedPtr const& session,
boost::asio::yield_context yield,
Output& output
) const
Expand Down
10 changes: 5 additions & 5 deletions src/rpc/handlers/Subscribe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

#include "data/BackendInterface.hpp"
#include "feed/SubscriptionManagerInterface.hpp"
#include "feed/Types.hpp"
#include "rpc/common/Specs.hpp"
#include "rpc/common/Types.hpp"
#include "web/SubscriptionContextInterface.hpp"

#include <boost/asio/spawn.hpp>
#include <boost/json/array.hpp>
Expand Down Expand Up @@ -129,20 +129,20 @@ class SubscribeHandler {
subscribeToStreams(
boost::asio::yield_context yield,
std::vector<std::string> const& streams,
web::SubscriptionContextPtr const& session
feed::SubscriberSharedPtr const& session
) const;

void
subscribeToAccounts(std::vector<std::string> const& accounts, web::SubscriptionContextPtr const& session) const;
subscribeToAccounts(std::vector<std::string> const& accounts, feed::SubscriberSharedPtr const& session) const;

void
subscribeToAccountsProposed(std::vector<std::string> const& accounts, web::SubscriptionContextPtr const& session)
subscribeToAccountsProposed(std::vector<std::string> const& accounts, feed::SubscriberSharedPtr const& session)
const;

void
subscribeToBooks(
std::vector<OrderBook> const& books,
web::SubscriptionContextPtr const& session,
feed::SubscriberSharedPtr const& session,
boost::asio::yield_context yield,
Output& output
) const;
Expand Down
5 changes: 3 additions & 2 deletions src/util/CoroutineGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
#include <boost/asio/steady_timer.hpp>

#include <cstddef>
#include <cstdint>
#include <functional>
#include <optional>
#include <utility>

namespace util {

CoroutineGroup::CoroutineGroup(boost::asio::yield_context yield, std::optional<int64_t> maxChildren)
CoroutineGroup::CoroutineGroup(boost::asio::yield_context yield, std::optional<size_t> maxChildren)
: timer_{yield.get_executor(), boost::asio::steady_timer::duration::max()}, maxChildren_{maxChildren}
{
}
Expand Down Expand Up @@ -91,6 +90,8 @@ CoroutineGroup::isFull() const
void
CoroutineGroup::onCoroutineCompleted()
{
ASSERT(childrenCounter_ != 0, "onCoroutineCompleted() called more times than the number of child coroutines");

--childrenCounter_;
if (childrenCounter_ == 0)
timer_.cancel();
Expand Down
7 changes: 3 additions & 4 deletions src/util/CoroutineGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include <atomic>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <optional>

Expand All @@ -37,8 +36,8 @@ namespace util {
*/
class CoroutineGroup {
boost::asio::steady_timer timer_;
std::optional<int64_t> maxChildren_;
std::atomic_int64_t childrenCounter_{0};
std::optional<size_t> maxChildren_;
std::atomic_size_t childrenCounter_{0};

public:
/**
Expand All @@ -48,7 +47,7 @@ class CoroutineGroup {
* @param maxChildren The maximum number of coroutines that can be spawned at the same time. If not provided, there
* is no limit
*/
CoroutineGroup(boost::asio::yield_context yield, std::optional<int64_t> maxChildren = std::nullopt);
CoroutineGroup(boost::asio::yield_context yield, std::optional<size_t> maxChildren = std::nullopt);

/**
* @brief Destroy the Coroutine Group object
Expand Down
2 changes: 1 addition & 1 deletion src/web/AdminVerificationStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ make_AdminVerificationStrategy(util::Config const& config)
if (adminPassword.has_value() and localAdmin.has_value() and *localAdmin)
return std::unexpected{"Admin config error: 'local_admin' and admin_password can not be set together."};

if (localAdmin.has_value() and not*localAdmin and not adminPassword.has_value()) {
if (localAdmin.has_value() and !*localAdmin and !adminPassword.has_value()) {
return std::unexpected{
"Admin config error: either 'local_admin' should be enabled or 'admin_password' must be specified."
};
Expand Down
2 changes: 1 addition & 1 deletion src/web/RPCServerHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class RPCServerHandler {
return rpc::make_WsContext(
yield,
request,
connection->subscriptionContext(tagFactory_),
connection->makeSubscriptionContext(tagFactory_),
tagFactory_.with(connection->tag()),
*range,
connection->clientIp,
Expand Down
2 changes: 1 addition & 1 deletion src/web/impl/HttpBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class HttpBase : public ConnectionBase {
}

SubscriptionContextPtr
subscriptionContext(util::TagDecoratorFactory const&) override
makeSubscriptionContext(util::TagDecoratorFactory const&) override
{
ASSERT(false, "SubscriptionContext can't be created for a HTTP connection");
std::unreachable();
Expand Down
2 changes: 1 addition & 1 deletion src/web/impl/WsBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class WsBase : public ConnectionBase, public std::enable_shared_from_this<WsBase
* @return The subscription context for this connection.
*/
SubscriptionContextPtr
subscriptionContext(util::TagDecoratorFactory const& factory) override
makeSubscriptionContext(util::TagDecoratorFactory const& factory) override
{
if (subscriptionContext_ == nullptr) {
subscriptionContext_ = std::make_shared<SubscriptionContext>(factory, shared_from_this());
Expand Down
2 changes: 1 addition & 1 deletion src/web/interface/ConnectionBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct ConnectionBase : public util::Taggable {
* @return The subscription context for this connection.
*/
virtual SubscriptionContextPtr
subscriptionContext(util::TagDecoratorFactory const& factory) = 0;
makeSubscriptionContext(util::TagDecoratorFactory const& factory) = 0;

/**
* @brief Indicates whether the connection had an error and is considered dead.
Expand Down
2 changes: 1 addition & 1 deletion src/web/ng/Response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Response::intoHttpResponse() &&
}

boost::asio::const_buffer
Response::intoWsResponse() const&
Response::asWsResponse() const&
{
ASSERT(std::holds_alternative<std::string>(data_), "Response must contain WebSocket data");
auto const& message = std::get<std::string>(data_);
Expand Down
3 changes: 2 additions & 1 deletion src/web/ng/Response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <string>
#include <variant>

namespace web::ng {

/**
Expand Down Expand Up @@ -91,7 +92,7 @@ class Response {
* @return The message of the response as a const buffer.
*/
boost::asio::const_buffer
intoWsResponse() const&;
asWsResponse() const&;
};

} // namespace web::ng
1 change: 1 addition & 0 deletions src/web/ng/impl/ErrorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ ErrorHelper::makeError(rpc::Status const& err) const
case rpc::ClioError::rpcINVALID_HOT_WALLET:
case rpc::ClioError::rpcFIELD_NOT_FOUND_TRANSACTION:
case rpc::ClioError::rpcMALFORMED_ORACLE_DOCUMENT_ID:
case rpc::ClioError::rpcMALFORMED_AUTHORIZED_CREDENTIALS:
case rpc::ClioError::etlCONNECTION_ERROR:
case rpc::ClioError::etlREQUEST_ERROR:
case rpc::ClioError::etlREQUEST_TIMEOUT:
Expand Down
2 changes: 1 addition & 1 deletion src/web/ng/impl/WsConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class WsConnection : public WsConnectionBase {
std::chrono::steady_clock::duration timeout = DEFAULT_TIMEOUT
) override
{
return sendBuffer(response.intoWsResponse(), yield, timeout);
return sendBuffer(response.asWsResponse(), yield, timeout);
}

std::expected<Request, Error>
Expand Down
2 changes: 1 addition & 1 deletion tests/common/web/interface/ConnectionBaseMock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct ConnectionBaseMock : web::ConnectionBase {
MOCK_METHOD(void, send, (std::shared_ptr<std::string>), (override));
MOCK_METHOD(
web::SubscriptionContextPtr,
subscriptionContext,
makeSubscriptionContext,
(util::TagDecoratorFactory const& factory),
(override)
);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/web/RPCServerHandlerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct MockWsBase : public web::ConnectionBase {
}

SubscriptionContextPtr
subscriptionContext(util::TagDecoratorFactory const&) override
makeSubscriptionContext(util::TagDecoratorFactory const&) override
{
return {};
}
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/web/ng/ResponseTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ TEST_F(ResponseDeathTest, asConstBufferWithHttpData)
{
Request const request{http::request<http::string_body>{http::verb::get, "/", 11}};
web::ng::Response const response{boost::beast::http::status::ok, "message", request};
EXPECT_DEATH(response.intoWsResponse(), "");
EXPECT_DEATH(response.asWsResponse(), "");
}

struct ResponseTest : testing::Test {
Expand Down Expand Up @@ -104,7 +104,7 @@ TEST_F(ResponseTest, asConstBuffer)
std::string const responseMessage = "response message";
web::ng::Response const response{responseStatus_, responseMessage, request};

auto const buffer = response.intoWsResponse();
auto const buffer = response.asWsResponse();
EXPECT_EQ(buffer.size(), responseMessage.size());

std::string const messageFromBuffer{static_cast<char const*>(buffer.data()), buffer.size()};
Expand All @@ -117,7 +117,7 @@ TEST_F(ResponseTest, asConstBufferJson)
boost::json::object const responseMessage{{"key", "value"}};
web::ng::Response const response{responseStatus_, responseMessage, request};

auto const buffer = response.intoWsResponse();
auto const buffer = response.asWsResponse();
EXPECT_EQ(buffer.size(), boost::json::serialize(responseMessage).size());

std::string const messageFromBuffer{static_cast<char const*>(buffer.data()), buffer.size()};
Expand Down

0 comments on commit 908b7e3

Please sign in to comment.