mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 06:25:51 +00:00
Add support for calling RPC command at startup from config file.
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
SETUP_LOG();
|
SETUP_LOG();
|
||||||
|
|
||||||
LogPartition TaggedCachePartition("TaggedCache");
|
LogPartition TaggedCachePartition("TaggedCache");
|
||||||
Application* theApp = NULL;
|
Application* theApp = NULL;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <boost/iostreams/concepts.hpp>
|
#include <boost/iostreams/concepts.hpp>
|
||||||
#include <boost/iostreams/stream.hpp>
|
#include <boost/iostreams/stream.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
#include <openssl/buffer.h>
|
#include <openssl/buffer.h>
|
||||||
#include <openssl/evp.h>
|
#include <openssl/evp.h>
|
||||||
@@ -13,6 +14,7 @@
|
|||||||
#include "../json/value.h"
|
#include "../json/value.h"
|
||||||
#include "../json/reader.h"
|
#include "../json/reader.h"
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
#include "RPC.h"
|
#include "RPC.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "RPCErr.h"
|
#include "RPCErr.h"
|
||||||
@@ -54,8 +56,10 @@ std::string EncodeBase64(const std::string& s)
|
|||||||
Json::Value RPCParser::parseAsIs(const Json::Value& jvParams)
|
Json::Value RPCParser::parseAsIs(const Json::Value& jvParams)
|
||||||
{
|
{
|
||||||
Json::Value v(Json::objectValue);
|
Json::Value v(Json::objectValue);
|
||||||
|
|
||||||
if (jvParams.isArray() && (jvParams.size() > 0))
|
if (jvParams.isArray() && (jvParams.size() > 0))
|
||||||
v["params"] = jvParams;
|
v["params"] = jvParams;
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -656,7 +660,7 @@ int commandLineRPC(const std::vector<std::string>& vCmd)
|
|||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value callRPC(const std::string& strIp, const int iPort, const std::string& strUsername, const std::string& strPassword, const std::string& strPath, const std::string& strMethod, const Json::Value& params)
|
Json::Value callRPC(const std::string& strIp, const int iPort, const std::string& strUsername, const std::string& strPassword, const std::string& strPath, const std::string& strMethod, const Json::Value& jvParams)
|
||||||
{
|
{
|
||||||
// Connect to localhost
|
// Connect to localhost
|
||||||
if (!theConfig.QUIET)
|
if (!theConfig.QUIET)
|
||||||
@@ -684,7 +688,7 @@ Json::Value callRPC(const std::string& strIp, const int iPort, const std::string
|
|||||||
// Log(lsDEBUG) << "requesting" << std::endl;
|
// Log(lsDEBUG) << "requesting" << std::endl;
|
||||||
|
|
||||||
// Send request
|
// Send request
|
||||||
std::string strRequest = JSONRPCRequest(strMethod, params, Json::Value(1));
|
std::string strRequest = JSONRPCRequest(strMethod, jvParams, Json::Value(1));
|
||||||
// cLog(lsDEBUG) << "send request " << strMethod << " : " << strRequest << std::endl;
|
// cLog(lsDEBUG) << "send request " << strMethod << " : " << strRequest << std::endl;
|
||||||
|
|
||||||
std::string strPost = createHTTPPost(strPath, strRequest, mapRequestHeaders);
|
std::string strPost = createHTTPPost(strPath, strRequest, mapRequestHeaders);
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
//
|
//
|
||||||
// TODO: Check permissions on config file before using it.
|
// TODO: Check permissions on config file before using it.
|
||||||
//
|
//
|
||||||
|
#include <algorithm>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "HashPrefixes.h"
|
#include "HashPrefixes.h"
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
#include <boost/algorithm/string.hpp>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#define SECTION_ACCOUNT_PROBE_MAX "account_probe_max"
|
#define SECTION_ACCOUNT_PROBE_MAX "account_probe_max"
|
||||||
#define SECTION_CLUSTER_NODES "cluster_nodes"
|
#define SECTION_CLUSTER_NODES "cluster_nodes"
|
||||||
#define SECTION_DATABASE_PATH "database_path"
|
#define SECTION_DATABASE_PATH "database_path"
|
||||||
@@ -36,6 +37,7 @@
|
|||||||
#define SECTION_RPC_ALLOW_REMOTE "rpc_allow_remote"
|
#define SECTION_RPC_ALLOW_REMOTE "rpc_allow_remote"
|
||||||
#define SECTION_RPC_IP "rpc_ip"
|
#define SECTION_RPC_IP "rpc_ip"
|
||||||
#define SECTION_RPC_PORT "rpc_port"
|
#define SECTION_RPC_PORT "rpc_port"
|
||||||
|
#define SECTION_RPC_STARTUP "rpc_startup"
|
||||||
#define SECTION_SNTP "sntp_servers"
|
#define SECTION_SNTP "sntp_servers"
|
||||||
#define SECTION_VALIDATORS_FILE "validators_file"
|
#define SECTION_VALIDATORS_FILE "validators_file"
|
||||||
#define SECTION_VALIDATION_QUORUM "validation_quorum"
|
#define SECTION_VALIDATION_QUORUM "validation_quorum"
|
||||||
@@ -268,6 +270,21 @@ void Config::load()
|
|||||||
SNTP_SERVERS = *smtTmp;
|
SNTP_SERVERS = *smtTmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
smtTmp = sectionEntries(secConfig, SECTION_RPC_STARTUP);
|
||||||
|
if (smtTmp)
|
||||||
|
{
|
||||||
|
BOOST_FOREACH(const std::string& strJson, *smtTmp)
|
||||||
|
{
|
||||||
|
Json::Reader jrReader;
|
||||||
|
Json::Value jvCommand;
|
||||||
|
|
||||||
|
if (!jrReader.parse(strJson, jvCommand))
|
||||||
|
throw std::runtime_error(boost::str(boost::format("Couldn't parse ["SECTION_RPC_STARTUP"] command: %s") % strJson));
|
||||||
|
|
||||||
|
RPC_STARTUP.push_back(jvCommand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sectionSingleB(secConfig, SECTION_DATABASE_PATH, DATABASE_PATH))
|
if (sectionSingleB(secConfig, SECTION_DATABASE_PATH, DATABASE_PATH))
|
||||||
DATA_DIR = DATABASE_PATH;
|
DATA_DIR = DATABASE_PATH;
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
#ifndef __CONFIG__
|
#ifndef __CONFIG__
|
||||||
#define __CONFIG__
|
#define __CONFIG__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "RippleAddress.h"
|
#include "RippleAddress.h"
|
||||||
#include "ParseSection.h"
|
#include "ParseSection.h"
|
||||||
#include "SerializedTypes.h"
|
#include "SerializedTypes.h"
|
||||||
|
|
||||||
#include <string>
|
#include "../json/value.h"
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
|
|
||||||
#define ENABLE_INSECURE 0 // 1, to enable unnecessary features.
|
#define ENABLE_INSECURE 0 // 1, to enable unnecessary features.
|
||||||
|
|
||||||
@@ -110,6 +112,7 @@ public:
|
|||||||
std::string RPC_USER;
|
std::string RPC_USER;
|
||||||
std::string RPC_PASSWORD;
|
std::string RPC_PASSWORD;
|
||||||
bool RPC_ALLOW_REMOTE;
|
bool RPC_ALLOW_REMOTE;
|
||||||
|
std::vector<Json::Value> RPC_STARTUP;
|
||||||
|
|
||||||
// Validation
|
// Validation
|
||||||
RippleAddress VALIDATION_SEED, VALIDATION_PUB, VALIDATION_PRIV;
|
RippleAddress VALIDATION_SEED, VALIDATION_PUB, VALIDATION_PRIV;
|
||||||
|
|||||||
@@ -9,8 +9,9 @@
|
|||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "CallRPC.h"
|
#include "CallRPC.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "RPCHandler.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
@@ -26,6 +27,21 @@ void setupServer()
|
|||||||
|
|
||||||
void startServer()
|
void startServer()
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
// Execute start up rpc commands.
|
||||||
|
//
|
||||||
|
BOOST_FOREACH(const Json::Value& jvCommand, theConfig.RPC_STARTUP)
|
||||||
|
{
|
||||||
|
if (!theConfig.QUIET)
|
||||||
|
cerr << "Startup RPC: " << jvCommand << endl;
|
||||||
|
|
||||||
|
RPCHandler rhHandler(&theApp->getOPs());
|
||||||
|
|
||||||
|
std::cerr << "Result: "
|
||||||
|
<< rhHandler.doCommand(jvCommand, RPCHandler::ADMIN)
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
theApp->run(); // Blocks till we get a stop RPC.
|
theApp->run(); // Blocks till we get a stop RPC.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user