From b343b0929a16b5ccbf60e9c60b8a22c7014602bd Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 9 Jul 2013 15:05:11 -0700 Subject: [PATCH] Refactor RPCServer --- Builds/VisualStudio2012/RippleD.vcxproj | 11 +- .../VisualStudio2012/RippleD.vcxproj.filters | 10 +- TODO.txt | 2 + modules/ripple_app/basics/ripple_RPCServer.h | 39 --- .../basics/ripple_RPCServerHandler.cpp | 98 +++++++ .../basics/ripple_RPCServerHandler.h | 27 ++ modules/ripple_app/ripple_app.cpp | 4 +- .../basics/ripple_RPCServer.cpp | 248 +++++++----------- modules/ripple_net/basics/ripple_RPCServer.h | 68 +++++ modules/ripple_net/ripple_net.cpp | 1 + modules/ripple_net/ripple_net.h | 1 + src/cpp/ripple/RPC.h | 51 ++-- src/cpp/ripple/RPCDoor.cpp | 9 +- src/cpp/ripple/RPCDoor.h | 5 +- src/cpp/ripple/RPCHandler.cpp | 2 +- src/cpp/ripple/RPCHandler.h | 2 +- src/cpp/ripple/ripple_Application.cpp | 4 +- 17 files changed, 350 insertions(+), 232 deletions(-) delete mode 100644 modules/ripple_app/basics/ripple_RPCServer.h create mode 100644 modules/ripple_app/basics/ripple_RPCServerHandler.cpp create mode 100644 modules/ripple_app/basics/ripple_RPCServerHandler.h rename modules/{ripple_app => ripple_net}/basics/ripple_RPCServer.cpp (53%) create mode 100644 modules/ripple_net/basics/ripple_RPCServer.h diff --git a/Builds/VisualStudio2012/RippleD.vcxproj b/Builds/VisualStudio2012/RippleD.vcxproj index 7190389fa8..6fa102db2b 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj +++ b/Builds/VisualStudio2012/RippleD.vcxproj @@ -19,7 +19,7 @@ - + true true true @@ -370,6 +370,12 @@ true true + + true + true + true + true + @@ -1316,7 +1322,7 @@ - + @@ -1393,6 +1399,7 @@ + diff --git a/Builds/VisualStudio2012/RippleD.vcxproj.filters b/Builds/VisualStudio2012/RippleD.vcxproj.filters index 0fb4c1e93f..288bf4aca6 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2012/RippleD.vcxproj.filters @@ -843,9 +843,12 @@ [1] Ripple\ripple_net\basics - + [1] Ripple\ripple_app\basics + + [1] Ripple\ripple_net\basics + @@ -1575,9 +1578,12 @@ [1] Ripple\ripple_net\basics - + [1] Ripple\ripple_app\basics + + [1] Ripple\ripple_net\basics + diff --git a/TODO.txt b/TODO.txt index 5b8c719b60..609a60feb6 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,6 +2,8 @@ RIPPLE TODO -------------------------------------------------------------------------------- +- Tidy up convenience functions in RPC.h + - Maybe rename RPCServer to RPCClientServicer - Take away the "I" prefix from abstract interface classes, in both the class diff --git a/modules/ripple_app/basics/ripple_RPCServer.h b/modules/ripple_app/basics/ripple_RPCServer.h deleted file mode 100644 index c38dc3db3d..0000000000 --- a/modules/ripple_app/basics/ripple_RPCServer.h +++ /dev/null @@ -1,39 +0,0 @@ -//------------------------------------------------------------------------------ -/* - Copyright (c) 2011-2013, OpenCoin, Inc. -*/ -//============================================================================== - -#ifndef RIPPLE_RPCSERVER_H_INCLUDED -#define RIPPLE_RPCSERVER_H_INCLUDED - -// VFALCO NOTE This looks like intrusve shared object? -// -class RPCServer - : public boost::enable_shared_from_this - , LeakChecked -{ -public: - typedef boost::shared_ptr pointer; - -public: - static pointer New ( - boost::asio::io_service& io_service, - boost::asio::ssl::context& context, - NetworkOPs* mNetOps); - - virtual AutoSocket& getSocket () = 0; - - // VFALCO TODO Remove this since it exposes boost - virtual boost::asio::ip::tcp::socket& getRawSocket () = 0; - - virtual void connected () = 0; - - /** Retrieve the remote address as a string. - - @return A std::string representing the remote address. - */ - virtual std::string getRemoteAddressText () = 0; -}; - -#endif diff --git a/modules/ripple_app/basics/ripple_RPCServerHandler.cpp b/modules/ripple_app/basics/ripple_RPCServerHandler.cpp new file mode 100644 index 0000000000..faa90eb227 --- /dev/null +++ b/modules/ripple_app/basics/ripple_RPCServerHandler.cpp @@ -0,0 +1,98 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +RPCServerHandler::RPCServerHandler (NetworkOPs& networkOPs) + : m_networkOPs (networkOPs) +{ +} + +std::string RPCServerHandler::createResponse ( + int statusCode, + std::string const& description) +{ + return HTTPReply (statusCode, description); +} + +bool RPCServerHandler::isAuthorized ( + std::map const& headers) +{ + return HTTPAuthorized (headers); +} + +std::string RPCServerHandler::processRequest (std::string const& request, std::string const& remoteAddress) +{ + Json::Value jvRequest; + { + Json::Reader reader; + + if (! reader.parse (request, jvRequest) || + jvRequest.isNull () || + ! jvRequest.isObject ()) + { + return createResponse (400, "Unable to parse request"); + } + } + + int role = iAdminGet (jvRequest, remoteAddress); + + // Parse id now so errors from here on will have the id + // + // VFALCO NOTE Except that "id" isn't included in the following errors... + // + Json::Value const id = jvRequest ["id"]; + + Json::Value const method = jvRequest ["method"]; + + if (method.isNull ()) + { + return createResponse (400, "Null method"); + } + else if (! method.isString ()) + { + return createResponse (400, "method is not string"); + } + + std::string strMethod = method.asString (); + + // Parse params + Json::Value params = jvRequest ["params"]; + + if (params.isNull ()) + { + params = Json::Value (Json::arrayValue); + } + else if (!params.isArray ()) + { + return HTTPReply (400, "params unparseable"); + } + + // VFALCO TODO Shouldn't we handle this earlier? + // + if (role == RPCHandler::FORBID) + { + // VFALCO TODO Needs implementing + // FIXME Needs implementing + // XXX This needs rate limiting to prevent brute forcing password. + return HTTPReply (403, "Forbidden"); + } + + std::string response; + + WriteLog (lsINFO, RPCServer) << params; + + RPCHandler rpcHandler (&m_networkOPs); + + LoadType loadType = LT_RPCReference; + + Json::Value const result = rpcHandler.doRpcCommand (strMethod, params, role, &loadType); + // VFALCO NOTE We discard loadType since there is no endpoint to punish + + WriteLog (lsINFO, RPCServer) << result; + + response = JSONRPCReply (result, Json::Value (), id); + + return createResponse (200, response); +} diff --git a/modules/ripple_app/basics/ripple_RPCServerHandler.h b/modules/ripple_app/basics/ripple_RPCServerHandler.h new file mode 100644 index 0000000000..537ff265e4 --- /dev/null +++ b/modules/ripple_app/basics/ripple_RPCServerHandler.h @@ -0,0 +1,27 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +#ifndef RIPPLE_RPCSERVERHANDLER_H_INCLUDED +#define RIPPLE_RPCSERVERHANDLER_H_INCLUDED + +/** Handles RPC requests. +*/ +class RPCServerHandler : public RPCServer::Handler +{ +public: + explicit RPCServerHandler (NetworkOPs& networkOPs); + + std::string createResponse (int statusCode, std::string const& description); + + bool isAuthorized (std::map const& headers); + + std::string processRequest (std::string const& request, std::string const& remoteAddress); + +private: + NetworkOPs& m_networkOPs; +}; + +#endif diff --git a/modules/ripple_app/ripple_app.cpp b/modules/ripple_app/ripple_app.cpp index 09d67fac86..01f1813cf0 100644 --- a/modules/ripple_app/ripple_app.cpp +++ b/modules/ripple_app/ripple_app.cpp @@ -182,7 +182,7 @@ namespace ripple #include "basics/ripple_Version.h" // VFALCO TODO Should this be private? #include "basics/ripple_BuildVersion.h" // private -#include "basics/ripple_RPCServer.h" +#include "basics/ripple_RPCServerHandler.h" #include "src/cpp/ripple/RPCDoor.h" // needs RPCServer @@ -229,7 +229,7 @@ static const uint64 tenTo17m1 = tenTo17 - 1; #if ! defined (RIPPLE_MAIN_PART) || RIPPLE_MAIN_PART == 1 -#include "basics/ripple_RPCServer.cpp" +#include "basics/ripple_RPCServerHandler.cpp" #include "src/cpp/ripple/Ledger.cpp" #include "src/cpp/ripple/ripple_SHAMapDelta.cpp" diff --git a/modules/ripple_app/basics/ripple_RPCServer.cpp b/modules/ripple_net/basics/ripple_RPCServer.cpp similarity index 53% rename from modules/ripple_app/basics/ripple_RPCServer.cpp rename to modules/ripple_net/basics/ripple_RPCServer.cpp index 7c2f5afb13..6aa5c803c0 100644 --- a/modules/ripple_app/basics/ripple_RPCServer.cpp +++ b/modules/ripple_net/basics/ripple_RPCServer.cpp @@ -6,35 +6,42 @@ SETUP_LOG (RPCServer) -// VFALCO TODO Make this a language constant -#ifndef RPC_MAXIMUM_QUERY -#define RPC_MAXIMUM_QUERY (1024*1024) -#endif - -class RPCServerImp - : public RPCServer +class RPCServerImp : public RPCServer, LeakChecked { public: - typedef boost::shared_ptr pointer; - RPCServerImp ( boost::asio::io_service& io_service, boost::asio::ssl::context& context, - NetworkOPs* nopNetwork) - : mNetOps (nopNetwork) + Handler& handler) + : m_handler (handler) , mSocket (io_service, context) , mStrand (io_service) { - mRole = RPCHandler::GUEST; + } + + //-------------------------------------------------------------------------- +private: + enum + { + maxQueryBytes = 1024 * 1024 + }; + + void connected () + { + boost::asio::async_read_until ( + mSocket, + mLineBuffer, + "\r\n", + mStrand.wrap (boost::bind ( + &RPCServerImp::handle_read_line, + boost::static_pointer_cast (shared_from_this ()), + boost::asio::placeholders::error))); } //-------------------------------------------------------------------------- -private: void handle_write (const boost::system::error_code& e) { - //Log::out() << "async_write complete " << e; - if (!e) { HTTPRequest::Action action = mHTTPRequest.requestDone (false); @@ -61,7 +68,9 @@ private: if (e != boost::asio::error::operation_aborted) { - //connection_manager_.stop(shared_from_this()); + // VFALCO TODO What is this for? It was commented out. + // + //connection_manager_.stop (shared_from_this ()); } } @@ -69,80 +78,79 @@ private: void handle_read_line (const boost::system::error_code& e) { - if (e) - return; - - HTTPRequest::Action action = mHTTPRequest.consume (mLineBuffer); - - if (action == HTTPRequest::haDO_REQUEST) + if (! e) { - // request with no body - WriteLog (lsWARNING, RPCServer) << "RPC HTTP request with no body"; + HTTPRequest::Action action = mHTTPRequest.consume (mLineBuffer); - mSocket.async_shutdown (mStrand.wrap (boost::bind ( - &RPCServerImp::handle_shutdown, - boost::static_pointer_cast (shared_from_this ()), - boost::asio::placeholders::error))); - - return; - } - else if (action == HTTPRequest::haREAD_LINE) - { - boost::asio::async_read_until ( - mSocket, - mLineBuffer, - "\r\n", - mStrand.wrap (boost::bind ( - &RPCServerImp::handle_read_line, - boost::static_pointer_cast (shared_from_this ()), - boost::asio::placeholders::error))); - } - else if (action == HTTPRequest::haREAD_RAW) - { - int rLen = mHTTPRequest.getDataSize (); - - if ((rLen < 0) || (rLen > RPC_MAXIMUM_QUERY)) + if (action == HTTPRequest::haDO_REQUEST) { - WriteLog (lsWARNING, RPCServer) << "Illegal RPC request length " << rLen; + // request with no body + WriteLog (lsWARNING, RPCServer) << "RPC HTTP request with no body"; mSocket.async_shutdown (mStrand.wrap (boost::bind ( &RPCServerImp::handle_shutdown, boost::static_pointer_cast (shared_from_this ()), boost::asio::placeholders::error))); - - return; } - - int alreadyHave = mLineBuffer.size (); - - if (alreadyHave < rLen) + else if (action == HTTPRequest::haREAD_LINE) { - mQueryVec.resize (rLen - alreadyHave); - - boost::asio::async_read ( + boost::asio::async_read_until ( mSocket, - boost::asio::buffer (mQueryVec), + mLineBuffer, + "\r\n", mStrand.wrap (boost::bind ( - &RPCServerImp::handle_read_req, + &RPCServerImp::handle_read_line, boost::static_pointer_cast (shared_from_this ()), boost::asio::placeholders::error))); + } + else if (action == HTTPRequest::haREAD_RAW) + { + int rLen = mHTTPRequest.getDataSize (); - WriteLog (lsTRACE, RPCServer) << "Waiting for completed request: " << rLen; + if ((rLen < 0) || (rLen > maxQueryBytes)) + { + WriteLog (lsWARNING, RPCServer) << "Illegal RPC request length " << rLen; + + mSocket.async_shutdown (mStrand.wrap (boost::bind ( + &RPCServerImp::handle_shutdown, + boost::static_pointer_cast (shared_from_this ()), + boost::asio::placeholders::error))); + } + else + { + int alreadyHave = mLineBuffer.size (); + + if (alreadyHave < rLen) + { + mQueryVec.resize (rLen - alreadyHave); + + boost::asio::async_read ( + mSocket, + boost::asio::buffer (mQueryVec), + mStrand.wrap (boost::bind ( + &RPCServerImp::handle_read_req, + boost::static_pointer_cast (shared_from_this ()), + boost::asio::placeholders::error))); + + WriteLog (lsTRACE, RPCServer) << "Waiting for completed request: " << rLen; + } + else + { + // we have the whole thing + mQueryVec.resize (0); + + handle_read_req (e); + } + } } else { - // we have the whole thing - mQueryVec.resize (0); - handle_read_req (e); + mSocket.async_shutdown (mStrand.wrap (boost::bind ( + &RPCServerImp::handle_shutdown, + boost::static_pointer_cast (shared_from_this ()), + boost::asio::placeholders::error))); } } - else - { - mSocket.async_shutdown (mStrand.wrap (boost::bind ( - &RPCServerImp::handle_shutdown, - boost::static_pointer_cast (shared_from_this ()), - boost::asio::placeholders::error))); - } } //-------------------------------------------------------------------------- @@ -153,16 +161,21 @@ private: if (mLineBuffer.size ()) { - req.assign (boost::asio::buffer_cast (mLineBuffer.data ()), mLineBuffer.size ()); + req.assign (boost::asio::buffer_cast (mLineBuffer.data ()), mLineBuffer.size ()); + mLineBuffer.consume (mLineBuffer.size ()); } req += strCopy (mQueryVec); - if (!HTTPAuthorized (mHTTPRequest.peekHeaders ())) - mReplyStr = HTTPReply (403, "Forbidden"); + if (! m_handler.isAuthorized (mHTTPRequest.peekHeaders ())) + { + mReplyStr = m_handler.createResponse (403, "Forbidden"); + } else + { mReplyStr = handleRequest (req); + } boost::asio::async_write ( mSocket, @@ -182,48 +195,20 @@ private: //-------------------------------------------------------------------------- - std::string handleRequest (const std::string& requestStr) + // JSON-RPC request must contain "method", "params", and "id" fields. + // + std::string handleRequest (const std::string& request) { - WriteLog (lsTRACE, RPCServer) << "handleRequest " << requestStr; + WriteLog (lsTRACE, RPCServer) << "handleRequest " << request; - Json::Value id; - - // Parse request - Json::Value jvRequest; - Json::Reader reader; - - if (!reader.parse (requestStr, jvRequest) || jvRequest.isNull () || !jvRequest.isObject ()) - return (HTTPReply (400, "unable to parse request")); - - // Parse id now so errors from here on will have the id - id = jvRequest["id"]; - - // Parse method - Json::Value valMethod = jvRequest["method"]; - - if (valMethod.isNull ()) - return (HTTPReply (400, "null method")); - - if (!valMethod.isString ()) - return (HTTPReply (400, "method is not string")); - - std::string strMethod = valMethod.asString (); - - // Parse params - Json::Value valParams = jvRequest["params"]; - - if (valParams.isNull ()) - { - valParams = Json::Value (Json::arrayValue); - } - else if (!valParams.isArray ()) - { - return HTTPReply (400, "params unparseable"); - } + // Figure out the remote address. + // VFALCO TODO Clean up this try/catch nonsense. + // + std::string remoteAddress; try { - mRole = iAdminGet (jvRequest, mSocket.PlainSocket ().remote_endpoint ().address ().to_string ()); + remoteAddress = mSocket.PlainSocket ().remote_endpoint ().address ().to_string (); } catch (...) { @@ -231,25 +216,7 @@ private: return ""; } - if (RPCHandler::FORBID == mRole) - { - // XXX This needs rate limiting to prevent brute forcing password. - return HTTPReply (403, "Forbidden"); - } - - RPCHandler mRPCHandler (mNetOps); - - WriteLog (lsINFO, RPCServer) << valParams; - LoadType loadType = LT_RPCReference; - Json::Value result = mRPCHandler.doRpcCommand (strMethod, valParams, mRole, &loadType); - - // VFALCO NOTE We discard loadType since there is no endpoint to punish - - WriteLog (lsINFO, RPCServer) << result; - - std::string strReply = JSONRPCReply (result, Json::Value (), id); - - return HTTPReply (200, strReply); + return m_handler.processRequest (request, remoteAddress); } //-------------------------------------------------------------------------- @@ -268,21 +235,6 @@ private: //-------------------------------------------------------------------------- - void connected () - { - //Log::out() << "RPC request"; - boost::asio::async_read_until ( - mSocket, - mLineBuffer, - "\r\n", - mStrand.wrap (boost::bind ( - &RPCServerImp::handle_read_line, - boost::static_pointer_cast (shared_from_this ()), - boost::asio::placeholders::error))); - } - - //-------------------------------------------------------------------------- - std::string getRemoteAddressText () { std::string address; @@ -293,7 +245,7 @@ private: } private: - NetworkOPs* const mNetOps; + Handler& m_handler; AutoSocket mSocket; boost::asio::io_service::strand mStrand; @@ -303,8 +255,6 @@ private: std::string mReplyStr; HTTPRequest mHTTPRequest; - - int mRole; }; //------------------------------------------------------------------------------ @@ -312,7 +262,7 @@ private: RPCServer::pointer RPCServer::New ( boost::asio::io_service& io_service, boost::asio::ssl::context& context, - NetworkOPs* mNetOps) + Handler& handler) { - return pointer (new RPCServerImp (io_service, context, mNetOps)); + return pointer (new RPCServerImp (io_service, context, handler)); } diff --git a/modules/ripple_net/basics/ripple_RPCServer.h b/modules/ripple_net/basics/ripple_RPCServer.h new file mode 100644 index 0000000000..1290180ecd --- /dev/null +++ b/modules/ripple_net/basics/ripple_RPCServer.h @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +#ifndef RIPPLE_RPCSERVER_H_INCLUDED +#define RIPPLE_RPCSERVER_H_INCLUDED + +/** Provides RPC services to a client. + + Each client has a separate instance of this object. +*/ +// VFALCO NOTE This looks like intrusve shared object? +// +class RPCServer : public boost::enable_shared_from_this +{ +public: + typedef boost::shared_ptr pointer; + +public: + /** Handles a RPC client request. + */ + class Handler + { + public: + virtual ~Handler () { } + + /** Construct a HTTP response string. + */ + virtual std::string createResponse (int statusCode, std::string const& description) = 0; + + /** Determine if the connection is authorized. + */ + virtual bool isAuthorized (std::map const& headers) = 0; + + /** Produce a response for a given request. + + @param request The RPC request string. + @return The server's response. + */ + virtual std::string processRequest (std::string const& request, std::string const& remoteAddress) = 0; + }; + + static pointer New ( + boost::asio::io_service& io_service, + boost::asio::ssl::context& context, + Handler& handler); + + /** Called when the connection is established. + */ + virtual void connected () = 0; + + // VFALCO TODO AutoSocket exposes all sorts of boost::asio interface + virtual AutoSocket& getSocket () = 0; + + // VFALCO TODO Remove this since it exposes boost + virtual boost::asio::ip::tcp::socket& getRawSocket () = 0; + + /** Retrieve the remote address as a string. + + @return A std::string representing the remote address. + */ + // VFALCO TODO Replace the return type with a dedicated class. + virtual std::string getRemoteAddressText () = 0; +}; + +#endif diff --git a/modules/ripple_net/ripple_net.cpp b/modules/ripple_net/ripple_net.cpp index a13d24b9fe..37310919d4 100644 --- a/modules/ripple_net/ripple_net.cpp +++ b/modules/ripple_net/ripple_net.cpp @@ -22,5 +22,6 @@ namespace ripple #include "basics/ripple_HTTPRequest.cpp" #include "basics/ripple_HttpsClient.cpp" +#include "basics/ripple_RPCServer.cpp" } diff --git a/modules/ripple_net/ripple_net.h b/modules/ripple_net/ripple_net.h index 91758b7029..43d05e3b97 100644 --- a/modules/ripple_net/ripple_net.h +++ b/modules/ripple_net/ripple_net.h @@ -29,6 +29,7 @@ namespace ripple #include "basics/ripple_HTTPRequest.h" #include "basics/ripple_HttpsClient.h" +#include "basics/ripple_RPCServer.h" } diff --git a/src/cpp/ripple/RPC.h b/src/cpp/ripple/RPC.h index 771141ded4..1b7cedad14 100644 --- a/src/cpp/ripple/RPC.h +++ b/src/cpp/ripple/RPC.h @@ -4,44 +4,33 @@ */ //============================================================================== -#ifndef __RPC_h__ -#define __RPC_h__ - -enum http_status_type -{ - ok = 200, - created = 201, - accepted = 202, - no_content = 204, - multiple_choices = 300, - moved_permanently = 301, - moved_temporarily = 302, - not_modified = 304, - bad_request = 400, - unauthorized = 401, - forbidden = 403, - not_found = 404, - internal_server_error = 500, - not_implemented = 501, - bad_gateway = 502, - service_unavailable = 503 -}; +#ifndef RIPPLE_RPC_H_INCLUDED +#define RIPPLE_RPC_H_INCLUDED +// VFALCO TODO Wrap these up into a class. It looks like they just do some +// convenience packaging of JSON data from the pieces. It looks +// Ripple client protocol-specific. +// extern std::string JSONRPCRequest (const std::string& strMethod, const Json::Value& params, const Json::Value& id); -extern std::string createHTTPPost (const std::string& strHost, const std::string& strPath, const std::string& strMsg, - const std::map& mapRequestHeaders); - -extern int ReadHTTP (std::basic_istream& stream, - std::map& mapHeadersRet, std::string& strMessageRet); - -extern std::string HTTPReply (int nStatus, const std::string& strMsg); - extern std::string JSONRPCReply (const Json::Value& result, const Json::Value& error, const Json::Value& id); extern Json::Value JSONRPCError (int code, const std::string& message); -extern bool HTTPAuthorized (const std::map& mapHeaders); +extern std::string createHTTPPost (const std::string& strHost, const std::string& strPath, const std::string& strMsg, + const std::map& mapRequestHeaders); + +extern std::string HTTPReply (int nStatus, const std::string& strMsg); + +// VFALCO TODO Create a HTTPHeaders class with a nice interface instead of the std::map +// +extern bool HTTPAuthorized (std::map const& mapHeaders); + +// VFALCO NOTE This one looks like it does some sort of stream i/o +// +extern int ReadHTTP (std::basic_istream& stream, + std::map& mapHeadersRet, + std::string& strMessageRet); #endif diff --git a/src/cpp/ripple/RPCDoor.cpp b/src/cpp/ripple/RPCDoor.cpp index 006213a200..6c7f30cd06 100644 --- a/src/cpp/ripple/RPCDoor.cpp +++ b/src/cpp/ripple/RPCDoor.cpp @@ -6,11 +6,14 @@ SETUP_LOG (RPCDoor) +// VFALCO TODO Clean up this loose extern +// extern void initSSLContext (boost::asio::ssl::context& context, std::string key_file, std::string cert_file, std::string chain_file); -RPCDoor::RPCDoor (boost::asio::io_service& io_service) - : mAcceptor (io_service, +RPCDoor::RPCDoor (boost::asio::io_service& io_service, RPCServer::Handler& handler) + : m_rpcServerHandler (handler) + , mAcceptor (io_service, boost::asio::ip::tcp::endpoint (boost::asio::ip::address::from_string (theConfig.getRpcIP ()), theConfig.getRpcPort ())) , mDelayTimer (io_service) , mSSLContext (boost::asio::ssl::context::sslv23) @@ -30,7 +33,7 @@ RPCDoor::~RPCDoor () void RPCDoor::startListening () { - RPCServer::pointer new_connection = RPCServer::New (mAcceptor.get_io_service (), mSSLContext, &getApp().getOPs ()); + RPCServer::pointer new_connection = RPCServer::New (mAcceptor.get_io_service (), mSSLContext, m_rpcServerHandler); mAcceptor.set_option (boost::asio::ip::tcp::acceptor::reuse_address (true)); mAcceptor.async_accept (new_connection->getRawSocket (), diff --git a/src/cpp/ripple/RPCDoor.h b/src/cpp/ripple/RPCDoor.h index 40d00f9d13..c9d1562e69 100644 --- a/src/cpp/ripple/RPCDoor.h +++ b/src/cpp/ripple/RPCDoor.h @@ -14,10 +14,13 @@ Handles incoming connections from people making RPC Requests class RPCDoor : LeakChecked { public: - explicit RPCDoor (boost::asio::io_service& io_service); + explicit RPCDoor ( + boost::asio::io_service& io_service, + RPCServer::Handler& handler); ~RPCDoor (); private: + RPCServer::Handler& m_rpcServerHandler; boost::asio::ip::tcp::acceptor mAcceptor; boost::asio::deadline_timer mDelayTimer; boost::asio::ssl::context mSSLContext; diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index db364bacf7..822ebc4563 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -3520,7 +3520,7 @@ Json::Value RPCHandler::doUnsubscribe (Json::Value params, LoadType* loadType, S // // JSON-RPC provides a method and an array of params. JSON-RPC is used as a transport for a command and a request object. The // command is the method. The request object is supplied as the first element of the params. -Json::Value RPCHandler::doRpcCommand (const std::string& strMethod, Json::Value& jvParams, int iRole, LoadType* loadType) +Json::Value RPCHandler::doRpcCommand (const std::string& strMethod, Json::Value const& jvParams, int iRole, LoadType* loadType) { WriteLog (lsTRACE, RPCHandler) << "doRpcCommand:" << strMethod << ":" << jvParams; diff --git a/src/cpp/ripple/RPCHandler.h b/src/cpp/ripple/RPCHandler.h index c9298e07b2..f2931c6cad 100644 --- a/src/cpp/ripple/RPCHandler.h +++ b/src/cpp/ripple/RPCHandler.h @@ -34,7 +34,7 @@ public: Json::Value doCommand (const Json::Value& jvRequest, int role, LoadType* loadType); - Json::Value doRpcCommand (const std::string& strCommand, Json::Value& jvParams, int iRole, LoadType* loadType); + Json::Value doRpcCommand (const std::string& strCommand, Json::Value const& jvParams, int iRole, LoadType* loadType); private: typedef Json::Value (RPCHandler::*doFuncPtr) ( diff --git a/src/cpp/ripple/ripple_Application.cpp b/src/cpp/ripple/ripple_Application.cpp index 1389378474..d0c86c4b2e 100644 --- a/src/cpp/ripple/ripple_Application.cpp +++ b/src/cpp/ripple/ripple_Application.cpp @@ -221,6 +221,7 @@ private: InboundLedgers m_inboundLedgers; TransactionMaster mMasterTransaction; NetworkOPs mNetOps; + RPCServerHandler m_rpcServerHandler; NodeCache mTempNodeCache; HashedObjectStore mHashedObjectStore; SLECache mSLECache; @@ -281,6 +282,7 @@ Application::Application () , mIOService ((theConfig.NODE_SIZE >= 2) ? 2 : 1) , mIOWork (mIOService) , mNetOps (&mLedgerMaster) + , m_rpcServerHandler (mNetOps) , mTempNodeCache ("NodeCache", 16384, 90) , mHashedObjectStore (16384, 300) , mSLECache ("LedgerEntryCache", 4096, 120) @@ -589,7 +591,7 @@ void Application::setup () { try { - mRPCDoor = new RPCDoor (mIOService); + mRPCDoor = new RPCDoor (mIOService, m_rpcServerHandler); } catch (const std::exception& e) {