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] {
148 if (shutdown)
149 this->stop_p2p();
150 });
153 stop_thread.join();
154 });
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
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();
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();
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}
boost::shared_ptr< call_befor_die_base > auto_scope_leave_caller
auto_scope_leave_caller create_scope_leave_handler(t_scope_leave_handler f)