diff --git a/reporting/P2pProxy.cpp b/reporting/P2pProxy.cpp index dc2f29bc3..c091eab4a 100644 --- a/reporting/P2pProxy.cpp +++ b/reporting/P2pProxy.cpp @@ -18,43 +18,22 @@ //============================================================================== #include -#include - -namespace ripple { - -boost::json::object -forwardToP2p(boost::json::object const& request, ReportingETL& etl) -{ - return etl.getETLLoadBalancer().forwardToP2p(request); -} - -std::unique_ptr -getP2pForwardingStub(ReportingETL& etl) -{ - return etl - .getETLLoadBalancer() - .getP2pForwardingStub(); -} +#include // We only forward requests where ledger_index is "current" or "closed" // otherwise, attempt to handle here bool shouldForwardToP2p(boost::json::object const& request) { + if(request.contains("forward") && request.at("forward").is_bool()) + return request.at("forward").as_bool(); + std::string strCommand = request.contains("command") ? request.at("command").as_string().c_str() : request.at("method").as_string().c_str(); - BOOST_LOG_TRIVIAL(info) << "COMMAND:" << strCommand; - BOOST_LOG_TRIVIAL(info) << "REQUEST:" << request; - - auto handler = forwardCommands.find(strCommand) != forwardCommands.end(); - if (!handler) - { - BOOST_LOG_TRIVIAL(error) - << "Error getting handler. command = " << strCommand; - return false; - } + if (forwardCommands.find(strCommand) != forwardCommands.end()) + return true; if (request.contains("ledger_index")) { @@ -66,7 +45,5 @@ shouldForwardToP2p(boost::json::object const& request) } } - return true; + return false; } - -} // namespace ripple diff --git a/reporting/P2pProxy.h b/reporting/P2pProxy.h index ba7825726..7309744a9 100644 --- a/reporting/P2pProxy.h +++ b/reporting/P2pProxy.h @@ -20,93 +20,12 @@ #ifndef RIPPLE_APP_REPORTING_P2PPROXY_H_INCLUDED #define RIPPLE_APP_REPORTING_P2PPROXY_H_INCLUDED -#include - -#include "org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h" -#include - -namespace ripple { -/// Forward a JSON request to a p2p node and return the response -/// @param context context of the request -/// @return response from p2p node -Json::Value -forwardToP2p(RPC::JsonContext& context); +#include /// Whether a request should be forwarded, based on request parameters -/// @param context context of the request +/// @param request request json /// @return true if should be forwarded bool -shouldForwardToP2p(RPC::JsonContext& context); +shouldForwardToP2p(boost::json::object const& request); -template -bool -needCurrentOrClosed(Request& request) -{ - // These are the only gRPC requests that specify a ledger - if constexpr ( - std::is_same:: - value || - std::is_same::value || - std::is_same:: - value || - std::is_same::value) - { - if (request.ledger().ledger_case() == - org::xrpl::rpc::v1::LedgerSpecifier::LedgerCase::kShortcut) - { - if (request.ledger().shortcut() != - org::xrpl::rpc::v1::LedgerSpecifier::SHORTCUT_VALIDATED && - request.ledger().shortcut() != - org::xrpl::rpc::v1::LedgerSpecifier::SHORTCUT_UNSPECIFIED) - return true; - } - } - // GetLedgerDiff specifies two ledgers - else if constexpr (std::is_same< - Request, - org::xrpl::rpc::v1::GetLedgerDiffRequest>::value) - { - auto help = [](auto specifier) { - if (specifier.ledger_case() == - org::xrpl::rpc::v1::LedgerSpecifier::LedgerCase::kShortcut) - { - if (specifier.shortcut() != - org::xrpl::rpc::v1::LedgerSpecifier:: - SHORTCUT_VALIDATED && - specifier.shortcut() != - org::xrpl::rpc::v1::LedgerSpecifier:: - SHORTCUT_UNSPECIFIED) - return true; - } - return false; - }; - return help(request.base_ledger()) || help(request.desired_ledger()); - } - return false; -} - -/// Whether a request should be forwarded, based on request parameters -/// @param context context of the request -/// @condition required condition for the request -/// @return true if should be forwarded -template -bool -shouldForwardToP2p(RPC::GRPCContext& context, RPC::Condition condition) -{ - if (!context.app.config().reporting()) - return false; - if (condition == RPC::NEEDS_CURRENT_LEDGER || - condition == RPC::NEEDS_CLOSED_LEDGER) - return true; - - return needCurrentOrClosed(context.params); -} - -/// Get stub used to forward gRPC requests to a p2p node -/// @param context context of the request -/// @return stub to forward requests -std::unique_ptr -getP2pForwardingStub(RPC::Context& context); - -} // namespace ripple #endif diff --git a/reporting/server/session.cpp b/reporting/server/session.cpp index 10c71c2c5..f5e826915 100644 --- a/reporting/server/session.cpp +++ b/reporting/server/session.cpp @@ -1,4 +1,5 @@ #include +#include void fail(boost::beast::error_code ec, char const* what) @@ -17,7 +18,7 @@ buildResponse( BOOST_LOG_TRIVIAL(info) << "Received rpc command : " << request; boost::json::object response; - if (forwardCommands.find(command) != forwardCommands.end()) + if (shouldForwardToP2p(request)) return etl.getETLLoadBalancer().forwardToP2p(request); switch (commandMap[command]) diff --git a/reporting/server/session.h b/reporting/server/session.h index 5c70c5294..9d4d82706 100644 --- a/reporting/server/session.h +++ b/reporting/server/session.h @@ -73,7 +73,11 @@ static std::unordered_map commandMap{ static std::unordered_set forwardCommands{ "submit", - "fee" + "submit_multisigned", + "fee", + "path_find", + "ripple_path_find", + "manifest" }; boost::json::object