Http client for RPC executor

This commit is contained in:
Zachary Michaels 2014-06-23 16:03:01 -04:00
parent b36ca99bff
commit 7366afde2b
4 changed files with 58 additions and 16 deletions

View File

@ -43,6 +43,7 @@
#include <boost/interprocess/detail/atomic.hpp> #include <boost/interprocess/detail/atomic.hpp>
#include "net/net_utils_base.h" #include "net/net_utils_base.h"
#include "misc_language.h" #include "misc_language.h"
#include "misc_log_ex.h"
//#include "profile_tools.h" //#include "profile_tools.h"
#include "../string_tools.h" #include "../string_tools.h"

View File

@ -136,22 +136,6 @@ int main(int argc, char* argv[])
} }
} }
// If there are positional options, we're running a daemon command
if (command_line::arg_present(vm, arg_command))
{
auto command = command_line::get_arg(vm, arg_command);
t_command_server rpc_commands(new t_rpc_command_executor());
if (rpc_commands.process_command_vec(command))
{
return 0;
}
else
{
std::cerr << "Unknown command" << std::endl;
return 1;
}
}
// Parse config file if it exists // Parse config file if it exists
{ {
bf::path data_dir_path(bf::absolute(command_line::get_arg(vm, command_line::arg_data_dir))); bf::path data_dir_path(bf::absolute(command_line::get_arg(vm, command_line::arg_data_dir)));
@ -170,6 +154,29 @@ int main(int argc, char* argv[])
po::notify(vm); po::notify(vm);
} }
// If there are positional options, we're running a daemon command
if (command_line::arg_present(vm, arg_command))
{
auto command = command_line::get_arg(vm, arg_command);
auto executor = t_rpc_command_executor::parse_host_and_create("127.0.0.1", "18081");
if (!executor)
{
std::cerr << "Invalid RPC host" << std::endl;
return 1;
}
t_command_server rpc_commands(executor);
if (rpc_commands.process_command_vec(command))
{
return 0;
}
else
{
std::cerr << "Unknown command" << std::endl;
return 1;
}
}
// Set log file // Set log file
{ {
bf::path data_dir(bf::absolute(command_line::get_arg(vm, command_line::arg_data_dir))); bf::path data_dir(bf::absolute(command_line::get_arg(vm, command_line::arg_data_dir)));

View File

@ -2,6 +2,28 @@
using namespace daemonize; using namespace daemonize;
t_rpc_command_executor * t_rpc_command_executor::parse_host_and_create(
std::string rpc_host_ip_str, std::string rpc_host_port_str)
{
bool ok;
uint32_t rpc_host_ip;
uint16_t rpc_host_port;
ok = epee::string_tools::get_ip_int32_from_string(rpc_host_ip, rpc_host_ip_str);
ok = epee::string_tools::get_xtype_from_string(rpc_host_port, rpc_host_port_str);
if (ok) {
return new t_rpc_command_executor(rpc_host_port, rpc_host_ip);
} else {
return nullptr;
}
}
t_rpc_command_executor::t_rpc_command_executor(uint32_t rpc_host_ip, uint16_t rpc_host_port) :
m_rpc_host_ip(rpc_host_ip)
, m_rpc_host_port(rpc_host_port)
{}
bool t_rpc_command_executor::print_peer_list() { bool t_rpc_command_executor::print_peer_list() {
std::cout << "print peer list" << std::endl; std::cout << "print peer list" << std::endl;
return true; return true;

View File

@ -1,14 +1,26 @@
#pragma once #pragma once
#include "net/http_client.h"
#include "misc_log_ex.h" #include "misc_log_ex.h"
#include "cryptonote_core/cryptonote_core.h" #include "cryptonote_core/cryptonote_core.h"
#include "cryptonote_protocol/cryptonote_protocol_handler.h" #include "cryptonote_protocol/cryptonote_protocol_handler.h"
#include "daemon/command_executor.h" #include "daemon/command_executor.h"
#include "p2p/net_node.h" #include "p2p/net_node.h"
#include <boost/optional.hpp>
namespace daemonize { namespace daemonize {
class t_rpc_command_executor final : public t_command_executor { class t_rpc_command_executor final : public t_command_executor {
private:
epee::net_utils::http::http_simple_client m_http_client = {};
uint32_t m_rpc_host_ip;
uint16_t m_rpc_host_port;
public:
static t_rpc_command_executor * parse_host_and_create(
std::string rpc_host_ip_str, std::string rpc_host_port_str);
t_rpc_command_executor(uint32_t rpc_host_ip, uint16_t rpc_host_port);
bool print_peer_list() override; bool print_peer_list() override;
bool save_blockchain() override; bool save_blockchain() override;