mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 18:45:52 +00:00
Hide RPCServer implementation
This commit is contained in:
@@ -19,6 +19,12 @@
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\modules\ripple_app\basics\ripple_RPCServer.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\ripple_app.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -358,7 +364,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_net\client\ripple_HttpsClient.cpp">
|
||||
<ClCompile Include="..\..\modules\ripple_net\basics\ripple_HttpsClient.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
@@ -860,12 +866,6 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\cpp\ripple\RPCServer.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\cpp\ripple\RPCSub.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -1316,6 +1316,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\BeastConfig.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\basics\ripple_BuildVersion.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\basics\ripple_RPCServer.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\basics\ripple_Version.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\ripple_app.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_basics\containers\ripple_KeyCache.h" />
|
||||
@@ -1391,7 +1392,7 @@
|
||||
<ClInclude Include="..\..\modules\ripple_json\ripple_json.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_leveldb\ripple_leveldb.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_net\basics\ripple_HTTPRequest.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_net\client\ripple_HttpsClient.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_net\basics\ripple_HttpsClient.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_net\ripple_net.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_sqlite\ripple_sqlite.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_websocket\autosocket\ripple_AutoSocket.h" />
|
||||
@@ -1471,7 +1472,6 @@
|
||||
<ClInclude Include="..\..\src\cpp\ripple\RPCDoor.h" />
|
||||
<ClInclude Include="..\..\src\cpp\ripple\RPCErr.h" />
|
||||
<ClInclude Include="..\..\src\cpp\ripple\RPCHandler.h" />
|
||||
<ClInclude Include="..\..\src\cpp\ripple\RPCServer.h" />
|
||||
<ClInclude Include="..\..\src\cpp\ripple\RPCSub.h" />
|
||||
<ClInclude Include="..\..\src\cpp\ripple\ScriptData.h" />
|
||||
<ClInclude Include="..\..\src\cpp\ripple\SerializedValidation.h" />
|
||||
|
||||
@@ -145,12 +145,6 @@
|
||||
<Filter Include="[1] Ripple\ripple_net\basics">
|
||||
<UniqueIdentifier>{febf2e7e-f071-4a6c-9b81-68498fc8ea57}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="[1] Ripple\ripple_net\client">
|
||||
<UniqueIdentifier>{10893147-455d-4a9e-ad3b-ec12d296a03d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="[1] Ripple\ripple_net\peer">
|
||||
<UniqueIdentifier>{03c077b7-8ae4-4e00-9eb5-78295cfd377d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\Subtrees\sqlite\sqlite3.c">
|
||||
@@ -846,11 +840,11 @@
|
||||
<ClCompile Include="..\..\modules\ripple_net\basics\ripple_HTTPRequest.cpp">
|
||||
<Filter>[1] Ripple\ripple_net\basics</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\cpp\ripple\RPCServer.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\_network</Filter>
|
||||
<ClCompile Include="..\..\modules\ripple_net\basics\ripple_HttpsClient.cpp">
|
||||
<Filter>[1] Ripple\ripple_net\basics</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_net\client\ripple_HttpsClient.cpp">
|
||||
<Filter>[1] Ripple\ripple_net\client</Filter>
|
||||
<ClCompile Include="..\..\modules\ripple_app\basics\ripple_RPCServer.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\basics</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -1578,11 +1572,11 @@
|
||||
<ClInclude Include="..\..\modules\ripple_net\basics\ripple_HTTPRequest.h">
|
||||
<Filter>[1] Ripple\ripple_net\basics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\cpp\ripple\RPCServer.h">
|
||||
<Filter>[1] Ripple\ripple_app\_network</Filter>
|
||||
<ClInclude Include="..\..\modules\ripple_net\basics\ripple_HttpsClient.h">
|
||||
<Filter>[1] Ripple\ripple_net\basics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_net\client\ripple_HttpsClient.h">
|
||||
<Filter>[1] Ripple\ripple_net\client</Filter>
|
||||
<ClInclude Include="..\..\modules\ripple_app\basics\ripple_RPCServer.h">
|
||||
<Filter>[1] Ripple\ripple_app\basics</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
307
modules/ripple_app/basics/ripple_RPCServer.cpp
Normal file
307
modules/ripple_app/basics/ripple_RPCServer.cpp
Normal file
@@ -0,0 +1,307 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
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
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr<RPCServer> pointer;
|
||||
|
||||
RPCServerImp (
|
||||
boost::asio::io_service& io_service,
|
||||
boost::asio::ssl::context& context,
|
||||
NetworkOPs* nopNetwork)
|
||||
: mNetOps (nopNetwork)
|
||||
, mSocket (io_service, context)
|
||||
, mStrand (io_service)
|
||||
{
|
||||
mRole = RPCHandler::GUEST;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
void handle_write (const boost::system::error_code& e)
|
||||
{
|
||||
//Log::out() << "async_write complete " << e;
|
||||
|
||||
if (!e)
|
||||
{
|
||||
HTTPRequest::Action action = mHTTPRequest.requestDone (false);
|
||||
|
||||
if (action == HTTPRequest::haCLOSE_CONN)
|
||||
{
|
||||
mSocket.async_shutdown (mStrand.wrap (boost::bind (
|
||||
&RPCServerImp::handle_shutdown,
|
||||
boost::static_pointer_cast <RPCServerImp> (shared_from_this()),
|
||||
boost::asio::placeholders::error)));
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::asio::async_read_until (
|
||||
mSocket,
|
||||
mLineBuffer,
|
||||
"\r\n",
|
||||
mStrand.wrap (boost::bind (
|
||||
&RPCServerImp::handle_read_line,
|
||||
boost::static_pointer_cast <RPCServerImp> (shared_from_this()),
|
||||
boost::asio::placeholders::error)));
|
||||
}
|
||||
}
|
||||
|
||||
if (e != boost::asio::error::operation_aborted)
|
||||
{
|
||||
//connection_manager_.stop(shared_from_this());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void handle_read_line (const boost::system::error_code& e)
|
||||
{
|
||||
if (e)
|
||||
return;
|
||||
|
||||
HTTPRequest::Action action = mHTTPRequest.consume (mLineBuffer);
|
||||
|
||||
if (action == HTTPRequest::haDO_REQUEST)
|
||||
{
|
||||
// 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 <RPCServerImp> (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 <RPCServerImp> (shared_from_this ()),
|
||||
boost::asio::placeholders::error)));
|
||||
}
|
||||
else if (action == HTTPRequest::haREAD_RAW)
|
||||
{
|
||||
int rLen = mHTTPRequest.getDataSize ();
|
||||
|
||||
if ((rLen < 0) || (rLen > RPC_MAXIMUM_QUERY))
|
||||
{
|
||||
WriteLog (lsWARNING, RPCServer) << "Illegal RPC request length " << rLen;
|
||||
|
||||
mSocket.async_shutdown (mStrand.wrap (boost::bind (
|
||||
&RPCServerImp::handle_shutdown,
|
||||
boost::static_pointer_cast <RPCServerImp> (shared_from_this ()),
|
||||
boost::asio::placeholders::error)));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
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 <RPCServerImp> (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
|
||||
{
|
||||
mSocket.async_shutdown (mStrand.wrap (boost::bind (
|
||||
&RPCServerImp::handle_shutdown,
|
||||
boost::static_pointer_cast <RPCServerImp> (shared_from_this ()),
|
||||
boost::asio::placeholders::error)));
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void handle_read_req (const boost::system::error_code& ec)
|
||||
{
|
||||
std::string req;
|
||||
|
||||
if (mLineBuffer.size ())
|
||||
{
|
||||
req.assign (boost::asio::buffer_cast<const char*> (mLineBuffer.data ()), mLineBuffer.size ());
|
||||
mLineBuffer.consume (mLineBuffer.size ());
|
||||
}
|
||||
|
||||
req += strCopy (mQueryVec);
|
||||
|
||||
if (!HTTPAuthorized (mHTTPRequest.peekHeaders ()))
|
||||
mReplyStr = HTTPReply (403, "Forbidden");
|
||||
else
|
||||
mReplyStr = handleRequest (req);
|
||||
|
||||
boost::asio::async_write (
|
||||
mSocket,
|
||||
boost::asio::buffer (mReplyStr),
|
||||
mStrand.wrap (boost::bind (
|
||||
&RPCServerImp::handle_write,
|
||||
boost::static_pointer_cast <RPCServerImp> (shared_from_this ()),
|
||||
boost::asio::placeholders::error)));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void handle_shutdown (const boost::system::error_code& ec)
|
||||
{
|
||||
// nothing to do, we just keep the object alive
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
std::string handleRequest (const std::string& requestStr)
|
||||
{
|
||||
WriteLog (lsTRACE, RPCServer) << "handleRequest " << requestStr;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
mRole = iAdminGet (jvRequest, mSocket.PlainSocket ().remote_endpoint ().address ().to_string ());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// endpoint already disconnected
|
||||
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);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
AutoSocket& getSocket ()
|
||||
{
|
||||
return mSocket;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
boost::asio::ip::tcp::socket& getRawSocket ()
|
||||
{
|
||||
return mSocket.PlainSocket ();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
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 <RPCServerImp> (shared_from_this ()),
|
||||
boost::asio::placeholders::error)));
|
||||
}
|
||||
|
||||
private:
|
||||
NetworkOPs* const mNetOps;
|
||||
|
||||
AutoSocket mSocket;
|
||||
boost::asio::io_service::strand mStrand;
|
||||
|
||||
boost::asio::streambuf mLineBuffer;
|
||||
Blob mQueryVec;
|
||||
std::string mReplyStr;
|
||||
|
||||
HTTPRequest mHTTPRequest;
|
||||
|
||||
int mRole;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
RPCServer::pointer RPCServer::New (
|
||||
boost::asio::io_service& io_service,
|
||||
boost::asio::ssl::context& context,
|
||||
NetworkOPs* mNetOps)
|
||||
{
|
||||
return pointer (new RPCServerImp (io_service, context, mNetOps));
|
||||
}
|
||||
33
modules/ripple_app/basics/ripple_RPCServer.h
Normal file
33
modules/ripple_app/basics/ripple_RPCServer.h
Normal file
@@ -0,0 +1,33 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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 <RPCServer>
|
||||
, LeakChecked <RPCServer>
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr <RPCServer> 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;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -169,8 +169,6 @@ namespace ripple
|
||||
#include "src/cpp/ripple/PaymentTransactor.h"
|
||||
#include "src/cpp/ripple/PeerDoor.h"
|
||||
#include "src/cpp/ripple/RPC.h"
|
||||
#include "src/cpp/ripple/RPCServer.h"
|
||||
#include "src/cpp/ripple/RPCDoor.h"
|
||||
#include "src/cpp/ripple/RPCErr.h"
|
||||
#include "src/cpp/ripple/RPCSub.h"
|
||||
#include "src/cpp/ripple/RegularKeySetTransactor.h"
|
||||
@@ -184,6 +182,9 @@ 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 "src/cpp/ripple/RPCDoor.h" // needs RPCServer
|
||||
|
||||
}
|
||||
|
||||
@@ -228,6 +229,8 @@ static const uint64 tenTo17m1 = tenTo17 - 1;
|
||||
|
||||
#if ! defined (RIPPLE_MAIN_PART) || RIPPLE_MAIN_PART == 1
|
||||
|
||||
#include "basics/ripple_RPCServer.cpp"
|
||||
|
||||
#include "src/cpp/ripple/Ledger.cpp"
|
||||
#include "src/cpp/ripple/ripple_SHAMapDelta.cpp"
|
||||
#include "src/cpp/ripple/ripple_SHAMapNode.cpp"
|
||||
@@ -312,7 +315,6 @@ static DH* handleTmpDh (SSL* ssl, int is_export, int iKeyLength)
|
||||
#include "src/cpp/ripple/RegularKeySetTransactor.cpp"
|
||||
#include "src/cpp/ripple/ripple_RippleState.cpp"
|
||||
#include "src/cpp/ripple/RPCDoor.cpp"
|
||||
#include "src/cpp/ripple/RPCServer.cpp"
|
||||
#include "src/cpp/ripple/ScriptData.cpp"
|
||||
#include "src/cpp/ripple/SNTPClient.cpp"
|
||||
#include "src/cpp/ripple/TransactionCheck.cpp"
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
#ifndef RIPPLE_HTTPSCLIENT_H_INCLUDED
|
||||
#define RIPPLE_HTTPSCLIENT_H_INCLUDED
|
||||
|
||||
// VFALCO TODO Make this an abstract interface.
|
||||
//
|
||||
/** Provides an asynchronous HTTPS client implementation.
|
||||
*/
|
||||
|
||||
class HttpsClient
|
||||
: public boost::enable_shared_from_this <HttpsClient>
|
||||
, LeakChecked <HttpsClient>
|
||||
@@ -21,7 +21,6 @@ namespace ripple
|
||||
{
|
||||
|
||||
#include "basics/ripple_HTTPRequest.cpp"
|
||||
|
||||
#include "client/ripple_HttpsClient.cpp"
|
||||
#include "basics/ripple_HttpsClient.cpp"
|
||||
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ namespace ripple
|
||||
{
|
||||
|
||||
#include "basics/ripple_HTTPRequest.h"
|
||||
|
||||
#include "client/ripple_HttpsClient.h"
|
||||
#include "basics/ripple_HttpsClient.h"
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ RPCDoor::~RPCDoor ()
|
||||
|
||||
void RPCDoor::startListening ()
|
||||
{
|
||||
RPCServer::pointer new_connection = RPCServer::create (mAcceptor.get_io_service (), mSSLContext, &getApp().getOPs ());
|
||||
RPCServer::pointer new_connection = RPCServer::New (mAcceptor.get_io_service (), mSSLContext, &getApp().getOPs ());
|
||||
mAcceptor.set_option (boost::asio::ip::tcp::acceptor::reuse_address (true));
|
||||
|
||||
mAcceptor.async_accept (new_connection->getRawSocket (),
|
||||
|
||||
@@ -1,207 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RPC_MAXIMUM_QUERY
|
||||
#define RPC_MAXIMUM_QUERY (1024*1024)
|
||||
#endif
|
||||
|
||||
SETUP_LOG (RPCServer)
|
||||
|
||||
RPCServer::RPCServer (boost::asio::io_service& io_service, boost::asio::ssl::context& context, NetworkOPs* nopNetwork)
|
||||
: mNetOps (nopNetwork), mSocket (io_service, context), mStrand(io_service)
|
||||
{
|
||||
mRole = RPCHandler::GUEST;
|
||||
}
|
||||
|
||||
void RPCServer::connected ()
|
||||
{
|
||||
//Log::out() << "RPC request";
|
||||
boost::asio::async_read_until (mSocket, mLineBuffer, "\r\n",
|
||||
mStrand.wrap (boost::bind (&RPCServer::handle_read_line, shared_from_this (), boost::asio::placeholders::error)));
|
||||
}
|
||||
|
||||
void RPCServer::handle_read_req (const boost::system::error_code& e)
|
||||
{
|
||||
std::string req;
|
||||
|
||||
if (mLineBuffer.size ())
|
||||
{
|
||||
req.assign (boost::asio::buffer_cast<const char*> (mLineBuffer.data ()), mLineBuffer.size ());
|
||||
mLineBuffer.consume (mLineBuffer.size ());
|
||||
}
|
||||
|
||||
req += strCopy (mQueryVec);
|
||||
|
||||
if (!HTTPAuthorized (mHTTPRequest.peekHeaders ()))
|
||||
mReplyStr = HTTPReply (403, "Forbidden");
|
||||
else
|
||||
mReplyStr = handleRequest (req);
|
||||
|
||||
boost::asio::async_write (mSocket, boost::asio::buffer (mReplyStr),
|
||||
mStrand.wrap (boost::bind (&RPCServer::handle_write, shared_from_this (), boost::asio::placeholders::error)));
|
||||
}
|
||||
|
||||
void RPCServer::handle_read_line (const boost::system::error_code& e)
|
||||
{
|
||||
if (e)
|
||||
return;
|
||||
|
||||
HTTPRequest::Action action = mHTTPRequest.consume (mLineBuffer);
|
||||
|
||||
if (action == HTTPRequest::haDO_REQUEST)
|
||||
{
|
||||
// request with no body
|
||||
WriteLog (lsWARNING, RPCServer) << "RPC HTTP request with no body";
|
||||
mSocket.async_shutdown (mStrand.wrap (boost::bind (&RPCServer::handle_shutdown, 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 (&RPCServer::handle_read_line, shared_from_this (),
|
||||
boost::asio::placeholders::error)));
|
||||
}
|
||||
else if (action == HTTPRequest::haREAD_RAW)
|
||||
{
|
||||
int rLen = mHTTPRequest.getDataSize ();
|
||||
|
||||
if ((rLen < 0) || (rLen > RPC_MAXIMUM_QUERY))
|
||||
{
|
||||
WriteLog (lsWARNING, RPCServer) << "Illegal RPC request length " << rLen;
|
||||
mSocket.async_shutdown (mStrand.wrap (boost::bind (&RPCServer::handle_shutdown, shared_from_this(), boost::asio::placeholders::error)));
|
||||
return;
|
||||
}
|
||||
|
||||
int alreadyHave = mLineBuffer.size ();
|
||||
|
||||
if (alreadyHave < rLen)
|
||||
{
|
||||
mQueryVec.resize (rLen - alreadyHave);
|
||||
boost::asio::async_read (mSocket, boost::asio::buffer (mQueryVec),
|
||||
mStrand.wrap (boost::bind (&RPCServer::handle_read_req, 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
|
||||
mSocket.async_shutdown (mStrand.wrap (boost::bind (&RPCServer::handle_shutdown, shared_from_this(), boost::asio::placeholders::error)));
|
||||
}
|
||||
|
||||
std::string RPCServer::handleRequest (const std::string& requestStr)
|
||||
{
|
||||
WriteLog (lsTRACE, RPCServer) << "handleRequest " << requestStr;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
mRole = iAdminGet (jvRequest, mSocket.PlainSocket ().remote_endpoint ().address ().to_string ());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// endpoint already disconnected
|
||||
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);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// now, expire, n
|
||||
bool RPCServer::parseAcceptRate (const std::string& sAcceptRate)
|
||||
{
|
||||
if (!sAcceptRate.compare ("expire"))
|
||||
0;
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void RPCServer::handle_write (const boost::system::error_code& e)
|
||||
{
|
||||
//Log::out() << "async_write complete " << e;
|
||||
|
||||
if (!e)
|
||||
{
|
||||
HTTPRequest::Action action = mHTTPRequest.requestDone (false);
|
||||
|
||||
if (action == HTTPRequest::haCLOSE_CONN)
|
||||
mSocket.async_shutdown (mStrand.wrap (boost::bind (&RPCServer::handle_shutdown, shared_from_this(), boost::asio::placeholders::error)));
|
||||
else
|
||||
{
|
||||
boost::asio::async_read_until (mSocket, mLineBuffer, "\r\n",
|
||||
mStrand.wrap (boost::bind (&RPCServer::handle_read_line, shared_from_this (), boost::asio::placeholders::error)));
|
||||
}
|
||||
}
|
||||
|
||||
if (e != boost::asio::error::operation_aborted)
|
||||
{
|
||||
//connection_manager_.stop(shared_from_this());
|
||||
}
|
||||
}
|
||||
|
||||
// nothing to do, we just keep the object alive
|
||||
void RPCServer::handle_shutdown (const boost::system::error_code& e)
|
||||
{
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
@@ -1,67 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef __RPCSERVER__
|
||||
#define __RPCSERVER__
|
||||
|
||||
class RPCServer
|
||||
: public boost::enable_shared_from_this<RPCServer>
|
||||
, LeakChecked <RPCServer>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef boost::shared_ptr<RPCServer> pointer;
|
||||
|
||||
private:
|
||||
|
||||
NetworkOPs* mNetOps;
|
||||
|
||||
AutoSocket mSocket;
|
||||
boost::asio::io_service::strand mStrand;
|
||||
|
||||
boost::asio::streambuf mLineBuffer;
|
||||
Blob mQueryVec;
|
||||
std::string mReplyStr;
|
||||
|
||||
HTTPRequest mHTTPRequest;
|
||||
|
||||
|
||||
int mRole;
|
||||
|
||||
RPCServer (boost::asio::io_service& io_service, boost::asio::ssl::context& ssl_context, NetworkOPs* nopNetwork);
|
||||
|
||||
RPCServer (const RPCServer&); // no implementation
|
||||
RPCServer& operator= (const RPCServer&); // no implementation
|
||||
|
||||
void handle_write (const boost::system::error_code& ec);
|
||||
void handle_read_line (const boost::system::error_code& ec);
|
||||
void handle_read_req (const boost::system::error_code& ec);
|
||||
void handle_shutdown (const boost::system::error_code& ec);
|
||||
|
||||
std::string handleRequest (const std::string& requestStr);
|
||||
|
||||
public:
|
||||
static pointer create (boost::asio::io_service& io_service, boost::asio::ssl::context& context, NetworkOPs* mNetOps)
|
||||
{
|
||||
return pointer (new RPCServer (io_service, context, mNetOps));
|
||||
}
|
||||
|
||||
AutoSocket& getSocket ()
|
||||
{
|
||||
return mSocket;
|
||||
}
|
||||
|
||||
boost::asio::ip::tcp::socket& getRawSocket ()
|
||||
{
|
||||
return mSocket.PlainSocket ();
|
||||
}
|
||||
|
||||
void connected ();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// vim:ts=4
|
||||
Reference in New Issue
Block a user