Add rpc_ip and rpc_port command line overrides

This commit is contained in:
Vinnie Falco
2013-07-03 18:09:56 -07:00
parent fe3deb750a
commit 437f10b247
7 changed files with 104 additions and 14 deletions

View File

@@ -31,6 +31,9 @@ WEBSOCKET TODO
RIPPLE TODO RIPPLE TODO
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
- Class to represent IP and Port number, with members to print, check syntax,
etc... replace the boost calls.
- Remove dependence on JobQueue, LoadFeeTrack, and NetworkOPs from LoadManager - Remove dependence on JobQueue, LoadFeeTrack, and NetworkOPs from LoadManager
by providing an observer (beast::ListenerList or Listeners). This way by providing an observer (beast::ListenerList or Listeners). This way
LoadManager does not need stopThread() function. LoadManager does not need stopThread() function.

View File

@@ -209,6 +209,7 @@ void Config::setup (const std::string& strConf, bool bTestNet, bool bQuiet)
Config::Config () Config::Config ()
: SSL_CONTEXT (boost::asio::ssl::context::sslv23) : SSL_CONTEXT (boost::asio::ssl::context::sslv23)
, m_rpcPort (5001)
{ {
// //
// Defaults // Defaults
@@ -218,7 +219,6 @@ Config::Config ()
NETWORK_START_TIME = 1319844908; NETWORK_START_TIME = 1319844908;
PEER_PORT = SYSTEM_PEER_PORT; PEER_PORT = SYSTEM_PEER_PORT;
RPC_PORT = 5001;
RPC_SECURE = 0; RPC_SECURE = 0;
WEBSOCKET_PORT = SYSTEM_WEBSOCKET_PORT; WEBSOCKET_PORT = SYSTEM_WEBSOCKET_PORT;
WEBSOCKET_PUBLIC_PORT = SYSTEM_WEBSOCKET_PUBLIC_PORT; WEBSOCKET_PUBLIC_PORT = SYSTEM_WEBSOCKET_PUBLIC_PORT;
@@ -373,14 +373,14 @@ void Config::load ()
(void) SectionSingleB (secConfig, SECTION_RPC_ADMIN_PASSWORD, RPC_ADMIN_PASSWORD); (void) SectionSingleB (secConfig, SECTION_RPC_ADMIN_PASSWORD, RPC_ADMIN_PASSWORD);
(void) SectionSingleB (secConfig, SECTION_RPC_ADMIN_USER, RPC_ADMIN_USER); (void) SectionSingleB (secConfig, SECTION_RPC_ADMIN_USER, RPC_ADMIN_USER);
(void) SectionSingleB (secConfig, SECTION_RPC_IP, RPC_IP); (void) SectionSingleB (secConfig, SECTION_RPC_IP, m_rpcIP);
(void) SectionSingleB (secConfig, SECTION_RPC_PASSWORD, RPC_PASSWORD); (void) SectionSingleB (secConfig, SECTION_RPC_PASSWORD, RPC_PASSWORD);
(void) SectionSingleB (secConfig, SECTION_RPC_USER, RPC_USER); (void) SectionSingleB (secConfig, SECTION_RPC_USER, RPC_USER);
(void) SectionSingleB (secConfig, SECTION_NODE_DB, NODE_DB); (void) SectionSingleB (secConfig, SECTION_NODE_DB, NODE_DB);
(void) SectionSingleB (secConfig, SECTION_LDB_EPHEMERAL, LDB_EPHEMERAL); (void) SectionSingleB (secConfig, SECTION_LDB_EPHEMERAL, LDB_EPHEMERAL);
if (SectionSingleB (secConfig, SECTION_RPC_PORT, strTemp)) if (SectionSingleB (secConfig, SECTION_RPC_PORT, strTemp))
RPC_PORT = boost::lexical_cast<int> (strTemp); m_rpcPort = boost::lexical_cast<int> (strTemp);
if (SectionSingleB (secConfig, "ledger_creator" , strTemp)) if (SectionSingleB (secConfig, "ledger_creator" , strTemp))
LEDGER_CREATOR = boost::lexical_cast<bool> (strTemp); LEDGER_CREATOR = boost::lexical_cast<bool> (strTemp);

View File

@@ -160,9 +160,59 @@ public:
std::string WEBSOCKET_SSL_CHAIN; std::string WEBSOCKET_SSL_CHAIN;
std::string WEBSOCKET_SSL_KEY; std::string WEBSOCKET_SSL_KEY;
//----------------------------------------------------------------------------
//
// VFALCO NOTE Please follow this style for modifying or adding code in the file.
//
public:
/** Get the client or server RPC IP address.
@note The string may not always be in a valid parsable state.
@return A string representing the address.
*/
std::string getRpcIP () const { return m_rpcIP; }
/** Get the client or server RPC port number.
@note The port number may be invalid (out of range or zero)
@return The RPC port number.
*/
int getRpcPort () const { return m_rpcPort; }
/** Set the client or server RPC IP.
@note The string is not syntax-checked.
@param newIP A string representing the IP address to use.
*/
void setRpcIP (std::string const& newIP) { m_rpcIP = newIP; }
/** Set the client or server RPC port number.
@note The port number is not range checked.
@param newPort The RPC port number to use.
*/
void setRpcPort (int newPort) { m_rpcPort = newPort; }
/** Convert the RPC/port combination to a readable string.
*/
String const getRpcAddress ()
{
return String (m_rpcIP.c_str ()) << ":" << m_rpcPort;
}
private:
std::string m_rpcIP;
// VFALCO TODO This should be a short.
int m_rpcPort;
//
//----------------------------------------------------------------------------
public:
// RPC parameters // RPC parameters
std::string RPC_IP;
int RPC_PORT;
std::vector<std::string> RPC_ADMIN_ALLOW; std::vector<std::string> RPC_ADMIN_ALLOW;
std::string RPC_ADMIN_PASSWORD; std::string RPC_ADMIN_PASSWORD;
std::string RPC_ADMIN_USER; std::string RPC_ADMIN_USER;
@@ -175,6 +225,7 @@ public:
std::string RPC_SSL_CERT; std::string RPC_SSL_CERT;
std::string RPC_SSL_CHAIN; std::string RPC_SSL_CHAIN;
std::string RPC_SSL_KEY; std::string RPC_SSL_KEY;
//----------------------------------------------------------------------------
// Path searching // Path searching
int PATH_SEARCH_SIZE; int PATH_SEARCH_SIZE;

View File

@@ -878,12 +878,13 @@ int commandLineRPC (const std::vector<std::string>& vCmd)
callRPC ( callRPC (
isService, isService,
theConfig.RPC_IP, theConfig.RPC_PORT, theConfig.getRpcIP (),
theConfig.RPC_USER, theConfig.RPC_PASSWORD, theConfig.getRpcPort (),
theConfig.RPC_USER,
theConfig.RPC_PASSWORD,
"", "",
jvRequest.isMember ("method") // Allow parser to rewrite method. jvRequest.isMember ("method") // Allow parser to rewrite method.
? jvRequest["method"].asString () ? jvRequest["method"].asString () : vCmd[0],
: vCmd[0],
jvParams, // Parsed, execute. jvParams, // Parsed, execute.
false, false,
BIND_TYPE (callRPCHandler, &jvOutput, P_1)); BIND_TYPE (callRPCHandler, &jvOutput, P_1));

View File

@@ -11,11 +11,11 @@ extern void initSSLContext (boost::asio::ssl::context& context,
RPCDoor::RPCDoor (boost::asio::io_service& io_service) RPCDoor::RPCDoor (boost::asio::io_service& io_service)
: mAcceptor (io_service, : mAcceptor (io_service,
boost::asio::ip::tcp::endpoint (boost::asio::ip::address::from_string (theConfig.RPC_IP), theConfig.RPC_PORT)) boost::asio::ip::tcp::endpoint (boost::asio::ip::address::from_string (theConfig.getRpcIP ()), theConfig.getRpcPort ()))
, mDelayTimer (io_service) , mDelayTimer (io_service)
, mSSLContext (boost::asio::ssl::context::sslv23) , mSSLContext (boost::asio::ssl::context::sslv23)
{ {
WriteLog (lsINFO, RPCDoor) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE; WriteLog (lsINFO, RPCDoor) << "RPC port: " << theConfig.getRpcAddress().toRawUTF8() << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
if (theConfig.RPC_SECURE != 0) if (theConfig.RPC_SECURE != 0)
initSSLContext (mSSLContext, theConfig.RPC_SSL_KEY, theConfig.RPC_SSL_CERT, theConfig.RPC_SSL_CHAIN); initSSLContext (mSSLContext, theConfig.RPC_SSL_KEY, theConfig.RPC_SSL_CERT, theConfig.RPC_SSL_CHAIN);
@@ -25,7 +25,7 @@ RPCDoor::RPCDoor (boost::asio::io_service& io_service)
RPCDoor::~RPCDoor () RPCDoor::~RPCDoor ()
{ {
WriteLog (lsINFO, RPCDoor) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE; WriteLog (lsINFO, RPCDoor) << "RPC port: " << theConfig.getRpcAddress().toRawUTF8() << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
} }
void RPCDoor::startListening () void RPCDoor::startListening ()

View File

@@ -588,7 +588,7 @@ void Application::setup ()
// //
// Allow RPC connections. // Allow RPC connections.
// //
if (!theConfig.RPC_IP.empty () && theConfig.RPC_PORT) if (! theConfig.getRpcIP().empty () && theConfig.getRpcPort() != 0)
{ {
try try
{ {

View File

@@ -57,6 +57,10 @@ void printHelp (const po::options_description& desc)
cerr << desc << endl; cerr << desc << endl;
cerr << "Options: " << endl;
cerr << " -rpc-ip=<ip-address>[':'<port-number>]" << endl;
cerr << " -rpc-port=<port-number>" << endl;
cerr << endl;
cerr << "Commands: " << endl; cerr << "Commands: " << endl;
cerr << " account_info <account>|<nickname>|<seed>|<pass_phrase>|<key> [<ledger>] [strict]" << endl; cerr << " account_info <account>|<nickname>|<seed>|<pass_phrase>|<key> [<ledger>] [strict]" << endl;
cerr << " account_lines <account> <account>|\"\" [<ledger>]" << endl; cerr << " account_lines <account> <account>|\"\" [<ledger>]" << endl;
@@ -155,6 +159,7 @@ int rippleMain (int argc, char** argv)
int iResult = 0; int iResult = 0;
po::variables_map vm; // Map of options. po::variables_map vm; // Map of options.
// VFALCO TODO Replace boost program options with something from Beast.
// //
// Set up option parsing. // Set up option parsing.
// //
@@ -163,6 +168,8 @@ int rippleMain (int argc, char** argv)
("help,h", "Display this message.") ("help,h", "Display this message.")
("conf", po::value<std::string> (), "Specify the configuration file.") ("conf", po::value<std::string> (), "Specify the configuration file.")
("rpc", "Perform rpc command (default).") ("rpc", "Perform rpc command (default).")
("rpc_ip", po::value <std::string> (), "Specify the IP address for RPC command.")
("rpc_port", po::value <int> (), "Specify the port number for RPC command.")
("standalone,a", "Run with no peers.") ("standalone,a", "Run with no peers.")
("testnet,t", "Run in test net mode.") ("testnet,t", "Run in test net mode.")
("unittest,u", "Perform unit tests.") ("unittest,u", "Perform unit tests.")
@@ -232,13 +239,21 @@ int rippleMain (int argc, char** argv)
} }
if (vm.count ("quiet")) if (vm.count ("quiet"))
{
Log::setMinSeverity (lsFATAL, true); Log::setMinSeverity (lsFATAL, true);
}
else if (vm.count ("verbose")) else if (vm.count ("verbose"))
{
Log::setMinSeverity (lsTRACE, true); Log::setMinSeverity (lsTRACE, true);
}
else else
{
Log::setMinSeverity (lsINFO, true); Log::setMinSeverity (lsINFO, true);
}
// VFALCO TODO make these singletons that initialize statically // VFALCO TODO make this a singleton that initializes statically
// Or could make it a SharedSingleton
//
LEFInit (); LEFInit ();
if (vm.count ("unittest")) if (vm.count ("unittest"))
@@ -283,6 +298,26 @@ int rippleMain (int argc, char** argv)
theConfig.VALIDATION_QUORUM = 2; theConfig.VALIDATION_QUORUM = 2;
} }
if (iResult == 0)
{
// These overrides must happen after the config file is loaded.
// Override the RPC destination IP address
//
if (vm.count ("rpc_ip"))
{
theConfig.setRpcIP (vm ["rpc_ip"].as <std::string> ());
}
// Override the RPC destination port number
//
if (vm.count ("rpc_port"))
{
// VFALCO TODO This should be a short.
theConfig.setRpcPort (vm ["rpc_port"].as <int> ());
}
}
if (iResult) if (iResult)
{ {
nothing (); nothing ();