mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 22:45:52 +00:00
More work toward http/https client merge.
This commit is contained in:
@@ -152,7 +152,6 @@ public:
|
||||
boost::asio::async_write(PlainSocket(), buffers, handler);
|
||||
}
|
||||
|
||||
|
||||
template <typename Buf, typename Condition, typename Handler>
|
||||
void async_read(const Buf& buffers, Condition cond, Handler handler)
|
||||
{
|
||||
|
||||
@@ -625,22 +625,16 @@ int commandLineRPC(const std::vector<std::string>& vCmd)
|
||||
|
||||
boost::asio::io_service isService;
|
||||
|
||||
// void 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, const bool bSSL,
|
||||
boost::function<void(const Json::Value& jvInput)> callbackFuncP)
|
||||
callRPCAsync(
|
||||
callRPC(
|
||||
isService,
|
||||
#if 0
|
||||
theConfig.RPC_IP,
|
||||
theConfig.RPC_PORT,
|
||||
theConfig.RPC_USER,
|
||||
theConfig.RPC_PASSWORD,
|
||||
theConfig.RPC_IP, theConfig.RPC_PORT,
|
||||
theConfig.RPC_USER, theConfig.RPC_PASSWORD,
|
||||
"",
|
||||
jvRequest.isMember("method") // Allow parser to rewrite method.
|
||||
? jvRequest["method"].asString()
|
||||
: vCmd[0],
|
||||
jvParams, // Parsed, execute.
|
||||
boost::bind(callRPCHandler, jvOutput, _1));
|
||||
#endif
|
||||
false,
|
||||
boost::bind(callRPCHandler, &jvOutput, _1));
|
||||
|
||||
isService.run(); // This blocks until there is no more outstanding async calls.
|
||||
@@ -749,7 +743,12 @@ void requestRPC(const std::string& strMethod, const Json::Value& jvParams, const
|
||||
mHeaders);
|
||||
}
|
||||
|
||||
void 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, const bool bSSL,
|
||||
void callRPC(
|
||||
boost::asio::io_service& io_service,
|
||||
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, const bool bSSL,
|
||||
boost::function<void(const Json::Value& jvInput)> callbackFuncP)
|
||||
{
|
||||
// Connect to localhost
|
||||
@@ -774,7 +773,7 @@ void callRPC(const std::string& strIp, const int iPort, const std::string& strUs
|
||||
|
||||
HttpsClient::httpsRequest(
|
||||
bSSL,
|
||||
theApp->getIOService(),
|
||||
io_service,
|
||||
strIp,
|
||||
iPort,
|
||||
boost::bind(
|
||||
@@ -788,5 +787,4 @@ void callRPC(const std::string& strIp, const int iPort, const std::string& strUs
|
||||
boost::bind(&responseRPC, callbackFuncP, _1, _2, _3));
|
||||
}
|
||||
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -48,9 +48,14 @@ public:
|
||||
};
|
||||
|
||||
extern int commandLineRPC(const std::vector<std::string>& vCmd);
|
||||
extern void void 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, const bool bSSL,
|
||||
boost::function<void(const Json::Value& jvInput)> callbackFuncP);
|
||||
|
||||
extern void callRPC(
|
||||
boost::asio::io_service& io_service,
|
||||
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, const bool bSSL,
|
||||
boost::function<void(const Json::Value& jvInput)> callbackFuncP);
|
||||
#endif
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -77,31 +77,31 @@ void HttpsClient::httpsGet(
|
||||
|
||||
void HttpsClient::httpsNext()
|
||||
{
|
||||
// std::cerr << "Fetch: " << mDeqSites[0] << std::endl;
|
||||
std::cerr << "Fetch: " << mDeqSites[0] << std::endl;
|
||||
boost::shared_ptr<boost::asio::ip::tcp::resolver::query> query(new boost::asio::ip::tcp::resolver::query(mDeqSites[0], boost::lexical_cast<std::string>(mPort),
|
||||
ip::resolver_query_base::numeric_service));
|
||||
mQuery = query;
|
||||
|
||||
mDeadline.expires_from_now(mTimeout, mShutdown);
|
||||
|
||||
// std::cerr << "expires_from_now: " << mShutdown.message() << std::endl;
|
||||
std::cerr << "expires_from_now: " << mShutdown.message() << std::endl;
|
||||
|
||||
if (!mShutdown)
|
||||
{
|
||||
mDeadline.async_wait(
|
||||
boost::bind(
|
||||
&HttpsClient::ShandleDeadline,
|
||||
&HttpsClient::handleDeadline,
|
||||
shared_from_this(),
|
||||
boost::asio::placeholders::error));
|
||||
}
|
||||
|
||||
if (!mShutdown)
|
||||
{
|
||||
// std::cerr << "Resolving: " << mDeqSites[0] << std::endl;
|
||||
std::cerr << "Resolving: " << mDeqSites[0] << std::endl;
|
||||
|
||||
mResolver.async_resolve(*mQuery,
|
||||
boost::bind(
|
||||
&HttpsClient::ShandleResolve,
|
||||
&HttpsClient::handleResolve,
|
||||
shared_from_this(),
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::iterator));
|
||||
@@ -116,7 +116,7 @@ void HttpsClient::handleDeadline(const boost::system::error_code& ecResult)
|
||||
if (ecResult == boost::asio::error::operation_aborted)
|
||||
{
|
||||
// Timer canceled because deadline no longer needed.
|
||||
// std::cerr << "Deadline cancelled." << std::endl;
|
||||
std::cerr << "Deadline cancelled." << std::endl;
|
||||
|
||||
nothing(); // Aborter is done.
|
||||
}
|
||||
@@ -167,13 +167,13 @@ void HttpsClient::handleResolve(
|
||||
|
||||
if (mShutdown)
|
||||
{
|
||||
// std::cerr << "Resolve error: " << mDeqSites[0] << ": " << mShutdown.message() << std::endl;
|
||||
std::cerr << "Resolve error: " << mDeqSites[0] << ": " << mShutdown.message() << std::endl;
|
||||
|
||||
invokeComplete(mShutdown);
|
||||
}
|
||||
else
|
||||
{
|
||||
// std::cerr << "Resolve complete." << std::endl;
|
||||
std::cerr << "Resolve complete." << std::endl;
|
||||
|
||||
boost::asio::async_connect(
|
||||
mSocket.lowest_layer(),
|
||||
@@ -197,7 +197,7 @@ void HttpsClient::handleConnect(const boost::system::error_code& ecResult)
|
||||
|
||||
if (!mShutdown)
|
||||
{
|
||||
// std::cerr << "Connected." << std::endl;
|
||||
std::cerr << "Connected." << std::endl;
|
||||
mShutdown = mSocket.verify(mDeqSites[0]);
|
||||
|
||||
if (mShutdown)
|
||||
@@ -206,7 +206,7 @@ void HttpsClient::handleConnect(const boost::system::error_code& ecResult)
|
||||
}
|
||||
}
|
||||
|
||||
if (!mShutdown)
|
||||
if (mShutdown)
|
||||
{
|
||||
invokeComplete(mShutdown);
|
||||
}
|
||||
@@ -215,7 +215,7 @@ void HttpsClient::handleConnect(const boost::system::error_code& ecResult)
|
||||
mSocket.async_handshake(
|
||||
AutoSocket::ssl_socket::client,
|
||||
boost::bind(
|
||||
&HttpsClient::ShandleRequest,
|
||||
&HttpsClient::handleRequest,
|
||||
shared_from_this(),
|
||||
boost::asio::placeholders::error));
|
||||
}
|
||||
@@ -238,19 +238,19 @@ void HttpsClient::handleRequest(const boost::system::error_code& ecResult)
|
||||
}
|
||||
else
|
||||
{
|
||||
// std::cerr << "SSL session started." << std::endl;
|
||||
std::cerr << "Session started." << std::endl;
|
||||
mBuild(mRequest, mDeqSites[0]);
|
||||
|
||||
boost::asio::async_write(
|
||||
mSocket,
|
||||
mSocket.async_write(
|
||||
mRequest,
|
||||
boost::bind(&HttpsClient::ShandleWrite,
|
||||
boost::bind(&HttpsClient::handleWrite,
|
||||
shared_from_this(),
|
||||
boost::asio::placeholders::error));
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
}
|
||||
}
|
||||
|
||||
void HttpsClient::handleWrite(const boost::system::error_code& ecResult)
|
||||
void HttpsClient::handleWrite(const boost::system::error_code& ecResult, std::size_t bytes_transferred)
|
||||
{
|
||||
if (!mShutdown)
|
||||
mShutdown = ecResult;
|
||||
@@ -263,13 +263,13 @@ void HttpsClient::handleWrite(const boost::system::error_code& ecResult)
|
||||
}
|
||||
else
|
||||
{
|
||||
// std::cerr << "Wrote." << std::endl;
|
||||
std::cerr << "Wrote." << std::endl;
|
||||
|
||||
boost::asio::async_read(
|
||||
mSocket,
|
||||
mResponse,
|
||||
boost::asio::transfer_all(),
|
||||
boost::bind(&HttpsClient::ShandleData,
|
||||
boost::bind(&HttpsClient::handleData,
|
||||
shared_from_this(),
|
||||
boost::asio::placeholders::error));
|
||||
}
|
||||
@@ -290,7 +290,7 @@ void HttpsClient::handleData(const boost::system::error_code& ecResult)
|
||||
{
|
||||
if (mShutdown)
|
||||
{
|
||||
// std::cerr << "Complete." << std::endl;
|
||||
std::cerr << "Complete." << std::endl;
|
||||
nothing();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -41,28 +41,16 @@ private:
|
||||
boost::posix_time::time_duration mTimeout;
|
||||
|
||||
void handleDeadline(const boost::system::error_code& ecResult);
|
||||
static void ShandleDeadline(pointer This, const boost::system::error_code& ecResult)
|
||||
{ This->handleDeadline(ecResult); }
|
||||
|
||||
void handleResolve(const boost::system::error_code& ecResult, boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
|
||||
static void ShandleResolve(pointer This, const boost::system::error_code& ecResult, boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
|
||||
{ This->handleResolve(ecResult, endpoint_iterator); }
|
||||
|
||||
void handleConnect(const boost::system::error_code& ecResult);
|
||||
static void ShandleConnect(pointer This, const boost::system::error_code& ecResult)
|
||||
{ This->handleConnect(ecResult); }
|
||||
|
||||
void handleRequest(const boost::system::error_code& ecResult);
|
||||
static void ShandleRequest(pointer This, const boost::system::error_code& ecResult)
|
||||
{ This->handleRequest(ecResult); }
|
||||
|
||||
void handleWrite(const boost::system::error_code& ecResult);
|
||||
static void ShandleWrite(pointer This, const boost::system::error_code& ecResult)
|
||||
{ This->handleWrite(ecResult); }
|
||||
void handleWrite(const boost::system::error_code& ecResult, std::size_t bytes_transferred);
|
||||
|
||||
void handleData(const boost::system::error_code& ecResult);
|
||||
static void ShandleData(pointer This, const boost::system::error_code& ecResult)
|
||||
{ This->handleData(ecResult); }
|
||||
|
||||
void handleShutdown(const boost::system::error_code& ecResult);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user