Inject Config:

* Use dependency injections instead
* Remove deprecated fee interfaces
This commit is contained in:
Nik Bougalis
2015-09-18 12:15:12 -07:00
committed by Vinnie Falco
parent c7b3153958
commit fa796a2eb5
57 changed files with 541 additions and 688 deletions

View File

@@ -20,7 +20,6 @@
#include <BeastConfig.h>
#include <ripple/basics/Log.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/core/Config.h>
#include <ripple/net/HTTPClient.h>
#include <ripple/websocket/AutoSocket.h>
#include <beast/asio/placeholders.h>
@@ -40,27 +39,28 @@ namespace ripple {
class HTTPClientSSLContext
{
public:
HTTPClientSSLContext ()
HTTPClientSSLContext (Config const& config)
: m_context (boost::asio::ssl::context::sslv23)
, verify_ (config.SSL_VERIFY)
{
boost::system::error_code ec;
if (getConfig().SSL_VERIFY_FILE.empty ())
if (config.SSL_VERIFY_FILE.empty ())
{
m_context.set_default_verify_paths (ec);
if (ec && getConfig().SSL_VERIFY_DIR.empty ())
if (ec && config.SSL_VERIFY_DIR.empty ())
throw std::runtime_error (boost::str (
boost::format ("Failed to set_default_verify_paths: %s") % ec.message ()));
}
else
{
m_context.load_verify_file (getConfig().SSL_VERIFY_FILE);
m_context.load_verify_file (config.SSL_VERIFY_FILE);
}
if (! getConfig().SSL_VERIFY_DIR.empty ())
if (! config.SSL_VERIFY_DIR.empty ())
{
m_context.add_verify_path (getConfig().SSL_VERIFY_DIR, ec);
m_context.add_verify_path (config.SSL_VERIFY_DIR, ec);
if (ec)
throw std::runtime_error (boost::str (
@@ -73,15 +73,21 @@ public:
return m_context;
}
bool sslVerify() const
{
return verify_;
}
private:
boost::asio::ssl::context m_context;
bool verify_;
};
boost::optional<HTTPClientSSLContext> httpClientSSLContext;
void HTTPClient::initializeSSLContext ()
void HTTPClient::initializeSSLContext (Config const& config)
{
httpClientSSLContext.emplace ();
httpClientSSLContext.emplace (config);
}
//------------------------------------------------------------------------------
@@ -101,7 +107,7 @@ public:
, mResponseMax (responseMax)
, mDeadline (io_service)
{
if (!getConfig ().SSL_VERIFY)
if (!httpClientSSLContext->sslVerify())
mSocket.SSLSocket ().set_verify_mode (boost::asio::ssl::verify_none);
}
@@ -290,7 +296,7 @@ public:
{
WriteLog (lsTRACE, HTTPClient) << "Connected.";
if (getConfig ().SSL_VERIFY)
if (httpClientSSLContext->sslVerify ())
{
mShutdown = mSocket.verify (mDeqSites[0]);

View File

@@ -1069,9 +1069,15 @@ struct RPCCallImp
};
//------------------------------------------------------------------------------
namespace RPCCall {
int RPCCall::fromCommandLine (const std::vector<std::string>& vCmd)
int fromCommandLine (
Config const& config,
const std::vector<std::string>& vCmd)
{
if (vCmd.empty ())
return 1; // 1 = print usage.
Json::Value jvOutput;
int nRet = 0;
Json::Value jvRequest (Json::objectValue);
@@ -1081,8 +1087,6 @@ int RPCCall::fromCommandLine (const std::vector<std::string>& vCmd)
RPCParser rpParser;
Json::Value jvRpcParams (Json::arrayValue);
if (vCmd.empty ()) return 1; // 1 = print usage.
for (int i = 1; i != vCmd.size (); i++)
jvRpcParams.append (vCmd[i]);
@@ -1106,7 +1110,7 @@ int RPCCall::fromCommandLine (const std::vector<std::string>& vCmd)
try
{
std::stringstream ss;
setup = setup_ServerHandler(getConfig(), ss);
setup = setup_ServerHandler(config, ss);
}
catch(...)
{
@@ -1114,10 +1118,10 @@ int RPCCall::fromCommandLine (const std::vector<std::string>& vCmd)
// 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;
if (config.rpc_ip)
setup.client.ip = config.rpc_ip->to_string();
if (config.rpc_port)
setup.client.port = *config.rpc_port;
Json::Value jvParams (Json::arrayValue);
@@ -1142,6 +1146,7 @@ int RPCCall::fromCommandLine (const std::vector<std::string>& vCmd)
? jvRequest["method"].asString () : vCmd[0],
jvParams, // Parsed, execute.
setup.client.secure != 0, // Use SSL
config.QUIET,
std::bind (RPCCallImp::callRPCHandler, &jvOutput,
std::placeholders::_1));
isService.run(); // This blocks until there is no more outstanding async calls.
@@ -1204,16 +1209,16 @@ int RPCCall::fromCommandLine (const std::vector<std::string>& vCmd)
//------------------------------------------------------------------------------
void RPCCall::fromNetwork (
void fromNetwork (
boost::asio::io_service& io_service,
std::string const& strIp, const int iPort,
std::string const& strUsername, std::string const& strPassword,
std::string const& strPath, std::string const& strMethod,
Json::Value const& jvParams, const bool bSSL,
Json::Value const& jvParams, const bool bSSL, const bool quiet,
std::function<void (Json::Value const& jvInput)> callbackFuncP)
{
// Connect to localhost
if (!getConfig ().QUIET)
if (!quiet)
{
std::cerr << (bSSL ? "Securely connecting to " : "Connecting to ") <<
strIp << ":" << iPort << std::endl;
@@ -1249,4 +1254,6 @@ void RPCCall::fromNetwork (
std::placeholders::_3));
}
}
} // ripple

View File

@@ -164,7 +164,8 @@ private:
mUsername, mPassword,
mPath, "event",
jvEvent,
mSSL);
mSSL,
true);
}
catch (const std::exception& e)
{
@@ -176,7 +177,6 @@ private:
}
private:
// VFALCO TODO replace this macro with a language constant
enum
{
eventQueueMax = 32
@@ -207,12 +207,12 @@ RPCSub::RPCSub (InfoSub::Source& source)
{
}
RPCSub::pointer RPCSub::New (InfoSub::Source& source,
boost::asio::io_service& io_service, JobQueue& jobQueue,
std::string const& strUrl, std::string const& strUsername,
std::string const& strPassword)
std::shared_ptr<RPCSub> make_RPCSub (
InfoSub::Source& source, boost::asio::io_service& io_service,
JobQueue& jobQueue, std::string const& strUrl,
std::string const& strUsername, std::string const& strPassword)
{
return std::make_shared <RPCSubImp> (std::ref (source),
return std::make_shared<RPCSubImp> (std::ref (source),
std::ref (io_service), std::ref (jobQueue),
strUrl, strUsername, strPassword);
}