diff --git a/contrib/epee/include/net/net_helper.h b/contrib/epee/include/net/net_helper.h index 4f7ebfa04..f5d3ab166 100644 --- a/contrib/epee/include/net/net_helper.h +++ b/contrib/epee/include/net/net_helper.h @@ -43,6 +43,7 @@ #include #include "net/net_utils_base.h" #include "misc_language.h" +#include "misc_log_ex.h" //#include "profile_tools.h" #include "../string_tools.h" diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index fce5bc65c..2e6b49e37 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -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 { 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); } + // 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 { bf::path data_dir(bf::absolute(command_line::get_arg(vm, command_line::arg_data_dir))); diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 7e0a7eeab..dd874e581 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -2,6 +2,28 @@ 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() { std::cout << "print peer list" << std::endl; return true; diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h index aa8969bd3..5ab51362f 100644 --- a/src/daemon/rpc_command_executor.h +++ b/src/daemon/rpc_command_executor.h @@ -1,14 +1,26 @@ #pragma once +#include "net/http_client.h" #include "misc_log_ex.h" #include "cryptonote_core/cryptonote_core.h" #include "cryptonote_protocol/cryptonote_protocol_handler.h" #include "daemon/command_executor.h" #include "p2p/net_node.h" +#include namespace daemonize { 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 save_blockchain() override;