34 #include <boost/algorithm/string/split.hpp> 36 #include "daemon/daemon.h" 56 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY 57 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "daemon" 67 std::vector<std::unique_ptr<t_rpc>>
rpcs;
70 boost::program_options::variables_map
const & vm
82 rpcs.emplace_back(
new t_rpc{vm, core, p2p, restricted, main_rpc_port,
"core"});
88 rpcs.emplace_back(
new t_rpc{vm, core, p2p,
true, restricted_rpc_port,
"restricted"});
101 boost::program_options::variables_map
const & vm,
105 public_rpc_port(public_rpc_port)
119 mp_internals =
std::move(other.mp_internals);
120 other.mp_internals.reset(
nullptr);
121 public_rpc_port = other.public_rpc_port;
130 mp_internals =
std::move(other.mp_internals);
131 other.mp_internals.reset(
nullptr);
132 public_rpc_port = other.public_rpc_port;
139 if (
nullptr == mp_internals)
141 throw std::runtime_error{
"Can't run stopped daemon"};
144 std::atomic<bool>
stop(
false), shutdown(
false);
145 boost::thread stop_thread = boost::thread([&
stop, &shutdown,
this] {
159 if (!mp_internals->core.run())
162 for(
auto& rpc: mp_internals->rpcs)
165 std::unique_ptr<daemonize::t_command_server> rpc_commands;
166 if (interactive && mp_internals->rpcs.size())
170 rpc_commands->
start_handling(std::bind(&daemonize::t_daemon::stop_p2p,
this));
176 if (!zmq_rpc_disabled)
178 if (!zmq_server.addTCPSocket(zmq_rpc_bind_address, zmq_rpc_bind_port))
181 +
":" + zmq_rpc_bind_port +
") to ZMQ RPC Server");
186 for(
auto& rpc : mp_internals->rpcs)
192 MINFO(
"Starting ZMQ server...");
196 +
":" + zmq_rpc_bind_port +
".");
199 MINFO(
"ZMQ server disabled");
201 if (public_rpc_port > 0)
203 MGINFO(
"Public RPC port " << public_rpc_port <<
" will be advertised to other peers over P2P");
204 mp_internals->p2p.get().set_rpc_port(public_rpc_port);
207 mp_internals->p2p.run();
212 if (!zmq_rpc_disabled)
215 for(
auto& rpc : mp_internals->rpcs)
220 catch (std::exception
const & ex)
222 MFATAL(
"Uncaught exception! " << ex.what());
227 MFATAL(
"Uncaught exception!");
234 if (
nullptr == mp_internals)
236 throw std::runtime_error{
"Can't stop stopped daemon"};
238 mp_internals->p2p.stop();
239 for(
auto& rpc : mp_internals->rpcs)
242 mp_internals.reset(
nullptr);
245 void t_daemon::stop_p2p()
247 if (
nullptr == mp_internals)
249 throw std::runtime_error{
"Can't send stop signal to a stopped daemon"};
251 mp_internals->p2p.get().send_stop_signal();
void init_options(boost::program_options::options_description &hidden_options, boost::program_options::options_description &normal_options)
std::vector< std::unique_ptr< t_rpc > > rpcs
auto_scope_leave_caller create_scope_leave_handler(t_scope_leave_handler f)
t_internals(boost::program_options::variables_map const &vm)
const command_line::arg_descriptor< std::string > arg_zmq_rpc_bind_ip
t_daemon(boost::program_options::variables_map const &vm, uint16_t public_rpc_port=0)
t_daemon(boost::program_options::variables_map const &_vm)
t_daemon & operator=(t_daemon &&other)
const command_line::arg_descriptor< std::string, false, true, 2 > arg_zmq_rpc_bind_port
static const command_line::arg_descriptor< std::string > arg_rpc_restricted_bind_port
void set_protocol(t_protocol_raw &protocol)
boost::shared_ptr< call_befor_die_base > auto_scope_leave_caller
bool start_handling(std::function< void(void)> exit_handler=NULL)
const command_line::arg_descriptor< bool > arg_zmq_rpc_disabled
const command_line::arg_descriptor< bool > arg_offline
const T & move(const T &t)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
static const command_line::arg_descriptor< std::string, false, true, 2 > arg_rpc_bind_port
static const command_line::arg_descriptor< bool > arg_restricted_rpc
void set_p2p_endpoint(t_node_server &server)
bool is_arg_defaulted(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
bool run(bool interactive=false)