From 14d38a1a8d8c2880ae3db2e859c35e8b7777ff8b Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Fri, 24 Apr 2015 17:27:06 -0700 Subject: [PATCH] Fix --rpc_ip and --rpc_port (RIPD-679) This reverts commit 2b040569e79280a2b5071de540601f71bf06fe18. --- .gitignore | 1 + src/ripple/app/main/Main.cpp | 37 +++++++++++++++++++++++++++++++ src/ripple/core/Config.h | 8 ++++++- src/ripple/net/impl/RPCCall.cpp | 17 +++++++++++++- src/ripple/server/ServerHandler.h | 4 ++-- 5 files changed, 63 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f521ddee45..f20e141821 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ Release/*.* tmp # Ignore database directory. +db/ db/*.db db/*.db-* diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index 512e2609a7..01d2189dda 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -245,6 +245,8 @@ int run (int argc, char** argv) ("help,h", "Display this message.") ("conf", po::value (), "Specify the configuration file.") ("rpc", "Perform rpc command (default).") + ("rpc_ip", po::value (), "Specify the IP address for RPC command. Format: [':']") + ("rpc_port", po::value (), "Specify the port number for RPC command.") ("standalone,a", "Run with no peers.") ("shutdowntest", po::value ()->implicit_value (""), "Perform shutdown tests.") ("unittest,u", po::value ()->implicit_value (""), "Perform unit tests.") @@ -419,6 +421,41 @@ int run (int argc, char** argv) if (iResult == 0) { // These overrides must happen after the config file is loaded. + + // Override the RPC destination IP address + // + if (vm.count ("rpc_ip")) + { + try + { + getConfig().rpc_ip = + boost::asio::ip::address_v4::from_string( + vm["rpc_ip"].as()); + } + catch(...) + { + std::cerr << + "Invalid rpc_ip = " << vm["rpc_ip"].as(); + return -1; + } + } + + // Override the RPC destination port number + // + if (vm.count ("rpc_port")) + { + try + { + getConfig().rpc_port = vm["rpc_port"].as(); + } + catch(...) + { + std::cerr << + "Invalid rpc_port = " << vm["rpc_port"].as(); + return -1; + } + } + if (vm.count ("quorum")) { getConfig ().VALIDATION_QUORUM = vm["quorum"].as (); diff --git a/src/ripple/core/Config.h b/src/ripple/core/Config.h index 44bc9a349e..9b1fa99b89 100644 --- a/src/ripple/core/Config.h +++ b/src/ripple/core/Config.h @@ -28,8 +28,10 @@ #include #include #include -#include +#include // VFALCO FIX: This include should not be here +#include // VFALCO FIX: This include should not be here #include +#include #include #include #include @@ -251,6 +253,10 @@ public: std::string SSL_VERIFY_FILE; std::string SSL_VERIFY_DIR; + // These override the command line client settings + boost::optional rpc_ip; + boost::optional rpc_port; + public: Config (); diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index 3eb905d910..c55e549623 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -1018,7 +1018,22 @@ int RPCCall::fromCommandLine (const std::vector& vCmd) } else { - auto const setup = setup_ServerHandler(getConfig(), std::cerr); + ServerHandler::Setup setup; + try + { + std::stringstream ss; + setup = setup_ServerHandler(getConfig(), ss); + } + catch(...) + { + // ignore any exceptions, so the command + // line client works without a config file + } + + if (getConfig().rpc_ip) + setup.client.ip = getConfig().rpc_ip->to_string(); + if (getConfig().rpc_port) + setup.client.port = *getConfig().rpc_port; Json::Value jvParams (Json::arrayValue); diff --git a/src/ripple/server/ServerHandler.h b/src/ripple/server/ServerHandler.h index de394954de..784731c437 100644 --- a/src/ripple/server/ServerHandler.h +++ b/src/ripple/server/ServerHandler.h @@ -47,9 +47,9 @@ public: // Memberspace struct client_t { - bool secure; + bool secure = false; std::string ip; - std::uint16_t port; + std::uint16_t port = 0; std::string user; std::string password; std::string admin_user;