| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "rpc/core_rpc_server.h" |
| 34 |
|
| 35 |
#undef MONERO_DEFAULT_LOG_CATEGORY |
| 36 |
#define MONERO_DEFAULT_LOG_CATEGORY "daemon" |
| 37 |
|
| 38 |
namespace daemonize |
| 39 |
{ |
| 40 |
|
| 41 |
class t_rpc final |
| 42 |
{ |
| 43 |
public: |
| 44 |
static void init_options(boost::program_options::options_description & option_spec) |
| 45 |
{ |
| 46 |
cryptonote::core_rpc_server::init_options(option_spec); |
| 47 |
} |
| 48 |
private: |
| 49 |
cryptonote::core_rpc_server m_server; |
| 50 |
const std::string m_description; |
| 51 |
public: |
| 52 |
t_rpc( |
| 53 |
boost::program_options::variables_map const & vm |
| 54 |
, t_core & core |
| 55 |
, t_p2p & p2p |
| 56 |
, const bool restricted |
| 57 |
, const std::string & port |
| 58 |
, const std::string & description |
| 59 |
, bool allow_rpc_payment |
| 60 |
) |
| 61 |
: m_server{core.get(), p2p.get()}, m_description{description} |
| 62 |
{ |
| 63 |
MGINFO("Initializing " << m_description << " RPC server..."); |
| 64 |
|
| 65 |
if (!m_server.init(vm, restricted, port, allow_rpc_payment, command_line::get_arg(vm, daemon_args::arg_proxy))) |
| 66 |
{ |
| 67 |
throw std::runtime_error("Failed to initialize " + m_description + " RPC server."); |
| 68 |
} |
| 69 |
MGINFO(m_description << " RPC server initialized OK on port: " << m_server.get_binded_port()); |
| 70 |
} |
| 71 |
|
| 72 |
void run() |
| 73 |
{ |
| 74 |
MGINFO("Starting " << m_description << " RPC server..."); |
| 75 |
if (!m_server.run(2, false)) |
| 76 |
{ |
| 77 |
throw std::runtime_error("Failed to start " + m_description + " RPC server."); |
| 78 |
} |
| 79 |
MGINFO(m_description << " RPC server started ok"); |
| 80 |
} |
| 81 |
|
| 82 |
void stop() |
| 83 |
{ |
| 84 |
MGINFO("Stopping " << m_description << " RPC server..."); |
| 85 |
m_server.send_stop_signal(); |
| 86 |
m_server.timed_wait_server_stop(5000); |
| 87 |
} |
| 88 |
|
| 89 |
cryptonote::core_rpc_server* get_server() |
| 90 |
{ |
| 91 |
return &m_server; |
| 92 |
} |
| 93 |
|
| 94 |
~t_rpc() |
| 95 |
{ |
| 96 |
MGINFO("Deinitializing " << m_description << " RPC server..."); |
| 97 |
try { |
| 98 |
m_server.deinit(); |
| 99 |
} catch (...) { |
| 100 |
MERROR("Failed to deinitialize " << m_description << " RPC server..."); |
| 101 |
} |
| 102 |
} |
| 103 |
}; |
| 104 |
|
| 105 |
} |