Fix --rpc_ip and --rpc_port (RIPD-679)

This reverts commit 2b040569e7.
This commit is contained in:
Vinnie Falco
2015-04-24 17:27:06 -07:00
parent 9114f3d2e6
commit 98c915b2ca
5 changed files with 63 additions and 4 deletions

1
.gitignore vendored
View File

@@ -31,6 +31,7 @@ Release/*.*
tmp
# Ignore database directory.
db/
db/*.db
db/*.db-*

View File

@@ -245,6 +245,8 @@ int run (int argc, char** argv)
("help,h", "Display this message.")
("conf", po::value<std::string> (), "Specify the configuration file.")
("rpc", "Perform rpc command (default).")
("rpc_ip", po::value <std::string> (), "Specify the IP address for RPC command. Format: <ip-address>[':'<port-number>]")
("rpc_port", po::value <int> (), "Specify the port number for RPC command.")
("standalone,a", "Run with no peers.")
("shutdowntest", po::value <std::string> ()->implicit_value (""), "Perform shutdown tests.")
("unittest,u", po::value <std::string> ()->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<std::string>());
}
catch(...)
{
std::cerr <<
"Invalid rpc_ip = " << vm["rpc_ip"].as<std::string>();
return -1;
}
}
// Override the RPC destination port number
//
if (vm.count ("rpc_port"))
{
try
{
getConfig().rpc_port = vm["rpc_port"].as<int>();
}
catch(...)
{
std::cerr <<
"Invalid rpc_port = " << vm["rpc_port"].as<std::string>();
return -1;
}
}
if (vm.count ("quorum"))
{
getConfig ().VALIDATION_QUORUM = vm["quorum"].as <int> ();

View File

@@ -28,8 +28,10 @@
#include <beast/net/IPEndpoint.h>
#include <beast/module/core/files/File.h>
#include <beast/utility/ci_char_traits.h>
#include <boost/filesystem.hpp>
#include <boost/asio/ip/tcp.hpp> // VFALCO FIX: This include should not be here
#include <boost/filesystem.hpp> // VFALCO FIX: This include should not be here
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include <cstdint>
#include <map>
#include <string>
@@ -251,6 +253,10 @@ public:
std::string SSL_VERIFY_FILE;
std::string SSL_VERIFY_DIR;
// These override the command line client settings
boost::optional<boost::asio::ip::address_v4> rpc_ip;
boost::optional<std::uint16_t> rpc_port;
public:
Config ();

View File

@@ -1019,7 +1019,22 @@ int RPCCall::fromCommandLine (const std::vector<std::string>& 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);

View File

@@ -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;