From 849e1ce5f41afcaefb8634a1dd1312f0612d2883 Mon Sep 17 00:00:00 2001 From: Tom Ritchford Date: Mon, 10 Aug 2015 16:26:43 -0400 Subject: [PATCH] Bring some constants into RPC::Tuning.h. --- src/ripple/rpc/handlers/LedgerData.cpp | 7 ++---- src/ripple/rpc/impl/Tuning.h | 24 +++++++++++++++------ src/ripple/server/impl/ServerHandlerImp.cpp | 3 ++- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/ripple/rpc/handlers/LedgerData.cpp b/src/ripple/rpc/handlers/LedgerData.cpp index 1fc16c534e..6963a51786 100644 --- a/src/ripple/rpc/handlers/LedgerData.cpp +++ b/src/ripple/rpc/handlers/LedgerData.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -40,9 +41,6 @@ namespace ripple { // marker: resume point, if any Json::Value doLedgerData (RPC::Context& context) { - static int const BINARY_PAGE_LENGTH = 2048; - static int const JSON_PAGE_LENGTH = 256; - std::shared_ptr lpLedger; auto const& params = context.params; @@ -61,8 +59,6 @@ Json::Value doLedgerData (RPC::Context& context) bool isBinary = params[jss::binary].asBool(); int limit = -1; - int maxLimit = isBinary ? BINARY_PAGE_LENGTH : JSON_PAGE_LENGTH; - if (params.isMember (jss::limit)) { Json::Value const& jLimit = params[jss::limit]; @@ -72,6 +68,7 @@ Json::Value doLedgerData (RPC::Context& context) limit = jLimit.asInt (); } + auto maxLimit = RPC::Tuning::pageLength(isBinary); if ((limit < 0) || ((limit > maxLimit) && (context.role != Role::ADMIN))) limit = maxLimit; diff --git a/src/ripple/rpc/impl/Tuning.h b/src/ripple/rpc/impl/Tuning.h index 0dab69028a..0f0bdf3ee3 100644 --- a/src/ripple/rpc/impl/Tuning.h +++ b/src/ripple/rpc/impl/Tuning.h @@ -47,12 +47,24 @@ static LimitRange const bookOffers = {0, 0, 400}; /** Limits for the no_ripple_check command. */ static LimitRange const noRippleCheck = {10, 300, 400}; -static int const defaultAutoFillFeeMultiplier (10); -static int const maxPathfindsInProgress (2); -static int const maxPathfindJobCount (50); -static int const maxJobQueueClients (500); -static int const maxValidatedLedgerAge (120); -static int const maxRequestSize (1000000); +static int const defaultAutoFillFeeMultiplier = 10; +static int const maxPathfindsInProgress = 2; +static int const maxPathfindJobCount = 50; +static int const maxJobQueueClients = 500; +static int const maxValidatedLedgerAge = 120; +static int const maxRequestSize = 1000000; + +/** Maximum number of pages in one response from a binary LedgerData request. */ +static int const binaryPageLength = 2048; + +/** Maximum number of pages in one response from a Json LedgerData request. */ +static int const jsonPageLength = 256; + +/** Maximum number of pages in a LedgerData response. */ +inline int pageLength(bool isBinary) +{ + return isBinary ? binaryPageLength : jsonPageLength; +} } // Tuning /** @} */ diff --git a/src/ripple/server/impl/ServerHandlerImp.cpp b/src/ripple/server/impl/ServerHandlerImp.cpp index b1c4cf60bb..f868777410 100644 --- a/src/ripple/server/impl/ServerHandlerImp.cpp +++ b/src/ripple/server/impl/ServerHandlerImp.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include // @@ -237,7 +238,7 @@ ServerHandlerImp::processRequest ( Json::Value jsonRPC; { Json::Reader reader; - if ((request.size () > 1000000) || + if ((request.size () > RPC::Tuning::maxRequestSize) || ! reader.parse (request, jsonRPC) || ! jsonRPC || ! jsonRPC.isObject ())