mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-24 21:15:58 +00:00
Refactor RPC connect.
This commit is contained in:
@@ -113,6 +113,19 @@ Json::Value RPCParser::parseAccountTransactions(const Json::Value& jvParams)
|
||||
return jvRequest;
|
||||
}
|
||||
|
||||
// connect <ip> [port]
|
||||
Json::Value RPCParser::parseConnect(const Json::Value& jvParams)
|
||||
{
|
||||
Json::Value jvRequest(Json::objectValue);
|
||||
|
||||
jvRequest["ip"] = jvParams[0u].asString();
|
||||
|
||||
if (jvParams.size() == 2)
|
||||
jvRequest["port"] = jvParams[1u].asUInt();
|
||||
|
||||
return jvRequest;
|
||||
}
|
||||
|
||||
Json::Value RPCParser::parseEvented(const Json::Value& jvParams)
|
||||
{
|
||||
return rpcError(rpcNO_EVENTS);
|
||||
@@ -193,7 +206,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
|
||||
{ "accept_ledger", &RPCParser::parseAsIs, 0, 0 },
|
||||
{ "account_info", &RPCParser::parseAccountInfo, 1, 2 },
|
||||
{ "account_tx", &RPCParser::parseAccountTransactions, 2, 3 },
|
||||
// { "connect", &RPCParser::doConnect, 1, 2, true, false, optNone },
|
||||
{ "connect", &RPCParser::parseConnect, 1, 2 },
|
||||
// { "data_delete", &RPCParser::doDataDelete, 1, 1, true, false, optNone },
|
||||
// { "data_fetch", &RPCParser::doDataFetch, 1, 1, true, false, optNone },
|
||||
// { "data_store", &RPCParser::doDataStore, 2, 2, true, false, optNone },
|
||||
|
||||
@@ -14,6 +14,7 @@ protected:
|
||||
Json::Value parseAsIs(const Json::Value& jvParams);
|
||||
Json::Value parseAccountInfo(const Json::Value& jvParams);
|
||||
Json::Value parseAccountTransactions(const Json::Value& jvParams);
|
||||
Json::Value parseConnect(const Json::Value& jvParams);
|
||||
|
||||
Json::Value parseSubmit(const Json::Value& jvParams);
|
||||
Json::Value parseEvented(const Json::Value& jvParams);
|
||||
|
||||
@@ -321,29 +321,18 @@ Json::Value RPCHandler::doAccountInfo(Json::Value jvRequest)
|
||||
return jvResult;
|
||||
}
|
||||
|
||||
Json::Value RPCHandler::doConnect(Json::Value params)
|
||||
// {
|
||||
// ip: <string>,
|
||||
// port: <number>
|
||||
// }
|
||||
// XXX Might allow domain for manual connections.
|
||||
Json::Value RPCHandler::doConnect(Json::Value jvParams)
|
||||
{
|
||||
if (theConfig.RUN_STANDALONE)
|
||||
return "cannot connect in standalone mode";
|
||||
|
||||
// connect <ip> [port]
|
||||
std::string strIp;
|
||||
int iPort = -1;
|
||||
|
||||
// XXX Might allow domain for manual connections.
|
||||
if (!extractString(strIp, params, 0))
|
||||
return rpcError(rpcHOST_IP_MALFORMED);
|
||||
|
||||
if (params.size() == 2)
|
||||
{
|
||||
std::string strPort;
|
||||
|
||||
// YYY Should make an extract int.
|
||||
if (!extractString(strPort, params, 1))
|
||||
return rpcError(rpcPORT_MALFORMED);
|
||||
|
||||
iPort = lexical_cast_s<int>(strPort);
|
||||
}
|
||||
std::string strIp = jvParams["ip"].asString();
|
||||
int iPort = jvParams.isMember("port") ? jvParams["port"].asInt() : -1;
|
||||
|
||||
// XXX Validate legal IP and port
|
||||
theApp->getConnectionPool().connectTo(strIp, iPort);
|
||||
|
||||
Reference in New Issue
Block a user