Electroneum
Loading...
Searching...
No Matches
daemonize::t_daemon Class Referencefinal

#include <daemon.h>

Public Member Functions

 t_daemon (boost::program_options::variables_map const &vm, uint16_t public_rpc_port=0)
 t_daemon (t_daemon &&other)
t_daemonoperator= (t_daemon &&other)
 ~t_daemon ()
bool run (bool interactive=false)
void stop ()

Static Public Member Functions

static void init_options (boost::program_options::options_description &option_spec)

Detailed Description

Definition at line 40 of file daemon.h.

Constructor & Destructor Documentation

◆ t_daemon() [1/2]

t_daemon::t_daemon ( boost::program_options::variables_map const & vm,
uint16_t public_rpc_port = 0 )

Definition at line 100 of file daemon.cpp.

104 : mp_internals{new t_internals{vm}},
105 public_rpc_port(public_rpc_port)
106{
110}
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
const command_line::arg_descriptor< bool > arg_zmq_rpc_disabled
const command_line::arg_descriptor< std::string, false, true, 2 > arg_zmq_rpc_bind_port
const command_line::arg_descriptor< std::string > arg_zmq_rpc_bind_ip
Here is the call graph for this function:
Here is the caller graph for this function:

◆ t_daemon() [2/2]

t_daemon::t_daemon ( t_daemon && other)

Definition at line 115 of file daemon.cpp.

116{
117 if (this != &other)
118 {
119 mp_internals = std::move(other.mp_internals);
120 other.mp_internals.reset(nullptr);
121 public_rpc_port = other.public_rpc_port;
122 }
123}
Here is the call graph for this function:

◆ ~t_daemon()

t_daemon::~t_daemon ( )
default

Member Function Documentation

◆ init_options()

void t_daemon::init_options ( boost::program_options::options_description & option_spec)
static

Definition at line 93 of file daemon.cpp.

94{
95 t_core::init_options(option_spec);
96 t_p2p::init_options(option_spec);
97 t_rpc::init_options(option_spec);
98}
static void init_options(boost::program_options::options_description &option_spec)
Definition core.h:46
static void init_options(boost::program_options::options_description &option_spec)
Definition p2p.h:50
static void init_options(boost::program_options::options_description &option_spec)
Definition rpc.h:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

t_daemon & t_daemon::operator= ( t_daemon && other)

Definition at line 126 of file daemon.cpp.

127{
128 if (this != &other)
129 {
130 mp_internals = std::move(other.mp_internals);
131 other.mp_internals.reset(nullptr);
132 public_rpc_port = other.public_rpc_port;
133 }
134 return *this;
135}
Here is the call graph for this function:

◆ run()

bool t_daemon::run ( bool interactive = false)

Definition at line 137 of file daemon.cpp.

138{
139 if (nullptr == mp_internals)
140 {
141 throw std::runtime_error{"Can't run stopped daemon"};
142 }
143
144 std::atomic<bool> stop(false), shutdown(false);
145 boost::thread stop_thread = boost::thread([&stop, &shutdown, this] {
146 while (!stop)
148 if (shutdown)
149 this->stop_p2p();
150 });
152 stop = true;
153 stop_thread.join();
154 });
155 tools::signal_handler::install([&stop, &shutdown](int){ stop = shutdown = true; });
156
157 try
158 {
159 if (!mp_internals->core.run())
160 return false;
161
162 for(auto& rpc: mp_internals->rpcs)
163 rpc->run();
164
165 std::unique_ptr<daemonize::t_command_server> rpc_commands;
166 if (interactive && mp_internals->rpcs.size())
167 {
168 // The first three variables are not used when the fourth is false
169 rpc_commands.reset(new daemonize::t_command_server(0, 0, boost::none, epee::net_utils::ssl_support_t::e_ssl_support_disabled, false, mp_internals->rpcs.front()->get_server()));
170 rpc_commands->start_handling(std::bind(&daemonize::t_daemon::stop_p2p, this));
171 }
172
173 cryptonote::rpc::DaemonHandler rpc_daemon_handler(mp_internals->core.get(), mp_internals->p2p.get());
174 cryptonote::rpc::ZmqServer zmq_server(rpc_daemon_handler);
175
176 if (!zmq_rpc_disabled)
177 {
178 if (!zmq_server.addTCPSocket(zmq_rpc_bind_address, zmq_rpc_bind_port))
179 {
180 LOG_ERROR(std::string("Failed to add TCP Socket (") + zmq_rpc_bind_address
181 + ":" + zmq_rpc_bind_port + ") to ZMQ RPC Server");
182
183 if (rpc_commands)
184 rpc_commands->stop_handling();
185
186 for(auto& rpc : mp_internals->rpcs)
187 rpc->stop();
188
189 return false;
190 }
191
192 MINFO("Starting ZMQ server...");
193 zmq_server.run();
194
195 MINFO(std::string("ZMQ server started at ") + zmq_rpc_bind_address
196 + ":" + zmq_rpc_bind_port + ".");
197 }
198 else
199 MINFO("ZMQ server disabled");
200
201 if (public_rpc_port > 0)
202 {
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);
205 }
206
207 mp_internals->p2p.run(); // blocks until p2p goes down
208
209 if (rpc_commands)
210 rpc_commands->stop_handling();
211
212 if (!zmq_rpc_disabled)
213 zmq_server.stop();
214
215 for(auto& rpc : mp_internals->rpcs)
216 rpc->stop();
217 MGINFO("Node stopped.");
218 return true;
219 }
220 catch (std::exception const & ex)
221 {
222 MFATAL("Uncaught exception! " << ex.what());
223 return false;
224 }
225 catch (...)
226 {
227 MFATAL("Uncaught exception!");
228 return false;
229 }
230}
static bool install(T t)
installs a signal handler
Definition util.h:164
#define MFATAL(x)
Definition misc_log_ex.h:72
#define LOG_ERROR(x)
Definition misc_log_ex.h:98
#define MGINFO(x)
Definition misc_log_ex.h:80
#define MINFO(x)
Definition misc_log_ex.h:75
boost::shared_ptr< call_befor_die_base > auto_scope_leave_caller
bool sleep_no_w(long ms)
auto_scope_leave_caller create_scope_leave_handler(t_scope_leave_handler f)
Here is the call graph for this function:

◆ stop()

void t_daemon::stop ( )

Definition at line 232 of file daemon.cpp.

233{
234 if (nullptr == mp_internals)
235 {
236 throw std::runtime_error{"Can't stop stopped daemon"};
237 }
238 mp_internals->p2p.stop();
239 for(auto& rpc : mp_internals->rpcs)
240 rpc->stop();
241
242 mp_internals.reset(nullptr); // Ensure resources are cleaned up before we return
243}
Here is the caller graph for this function:

The documentation for this class was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/daemon/daemon.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/daemon/daemon.cpp