forked from lthn/blockchain
adds API server enablement option and conditional initialization in daemon
This commit is contained in:
parent
c6e98b6aa9
commit
60df03ff1f
1 changed files with 21 additions and 11 deletions
|
|
@ -59,6 +59,7 @@ BOOST_CLASS_VERSION(nodetool::node_server<currency::t_currency_protocol_handler<
|
||||||
|
|
||||||
const command_line::arg_descriptor<uint32_t> arg_rpc_server_threads("rpc-server-threads", "Specify number of RPC server threads. Default: 10", RPC_SERVER_DEFAULT_THREADS_NUM);
|
const command_line::arg_descriptor<uint32_t> arg_rpc_server_threads("rpc-server-threads", "Specify number of RPC server threads. Default: 10", RPC_SERVER_DEFAULT_THREADS_NUM);
|
||||||
const command_line::arg_descriptor<bool> arg_do_warp_mode("do-warp-mode", "This option pre-loads and unserialize all data into RAM and provide significant speed increase in RPC-handling, requires 32GB psychical RAM at least(64GB recommended). Might be helpful for production servers(like remote nodes or public nodes for mobile apps).");
|
const command_line::arg_descriptor<bool> arg_do_warp_mode("do-warp-mode", "This option pre-loads and unserialize all data into RAM and provide significant speed increase in RPC-handling, requires 32GB psychical RAM at least(64GB recommended). Might be helpful for production servers(like remote nodes or public nodes for mobile apps).");
|
||||||
|
const command_line::arg_descriptor<bool> arg_api_enabled("api-enabled", "Enable the API server", true);
|
||||||
|
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
|
|
@ -187,6 +188,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
command_line::add_arg(desc_cmd_sett, arg_rpc_server_threads);
|
command_line::add_arg(desc_cmd_sett, arg_rpc_server_threads);
|
||||||
command_line::add_arg(desc_cmd_sett, arg_do_warp_mode);
|
command_line::add_arg(desc_cmd_sett, arg_do_warp_mode);
|
||||||
|
command_line::add_arg(desc_cmd_sett, arg_api_enabled);
|
||||||
|
|
||||||
arg_market_disable.default_value = true;
|
arg_market_disable.default_value = true;
|
||||||
arg_market_disable.use_default = true;
|
arg_market_disable.use_default = true;
|
||||||
|
|
@ -468,10 +470,14 @@ int main(int argc, char* argv[])
|
||||||
LOG_PRINT_L0("Stratum server started ok");
|
LOG_PRINT_L0("Stratum server started ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize API server
|
std::unique_ptr<ApiServer> api_server;
|
||||||
oatpp::base::Environment::init();
|
bool api_enabled = command_line::get_arg(vm, arg_api_enabled);
|
||||||
ApiServer api_server(vm, &ccore, &p2psrv, &rpc_server);
|
if (api_enabled) {
|
||||||
api_server.start();
|
// Initialize API server
|
||||||
|
oatpp::base::Environment::init();
|
||||||
|
api_server = std::make_unique<ApiServer>(vm, &ccore, &p2psrv, &rpc_server);
|
||||||
|
api_server->start();
|
||||||
|
}
|
||||||
|
|
||||||
// Setup signal handler to gracefully stop the main p2p loop
|
// Setup signal handler to gracefully stop the main p2p loop
|
||||||
tools::signal_handler::install([&p2psrv] {
|
tools::signal_handler::install([&p2psrv] {
|
||||||
|
|
@ -487,10 +493,12 @@ int main(int argc, char* argv[])
|
||||||
LOG_PRINT_L0("Stopping command handler...");
|
LOG_PRINT_L0("Stopping command handler...");
|
||||||
dch.stop_handling();
|
dch.stop_handling();
|
||||||
|
|
||||||
LOG_PRINT_L0("Stopping API server...");
|
if (api_server) {
|
||||||
api_server.stop();
|
LOG_PRINT_L0("Stopping API server...");
|
||||||
api_server.wait();
|
api_server->stop();
|
||||||
LOG_PRINT_L0("API server stopped");
|
api_server->wait();
|
||||||
|
LOG_PRINT_L0("API server stopped");
|
||||||
|
}
|
||||||
|
|
||||||
//stop other components
|
//stop other components
|
||||||
if (stratum_enabled)
|
if (stratum_enabled)
|
||||||
|
|
@ -523,9 +531,11 @@ int main(int argc, char* argv[])
|
||||||
LOG_PRINT_L0("Deinitializing p2p...");
|
LOG_PRINT_L0("Deinitializing p2p...");
|
||||||
p2psrv.deinit();
|
p2psrv.deinit();
|
||||||
|
|
||||||
LOG_PRINT_L0("Destroying oatpp environment...");
|
if (api_enabled) {
|
||||||
oatpp::base::Environment::destroy();
|
LOG_PRINT_L0("Destroying oatpp environment...");
|
||||||
LOG_PRINT_L0("oatpp environment destroyed.");
|
oatpp::base::Environment::destroy();
|
||||||
|
LOG_PRINT_L0("oatpp environment destroyed.");
|
||||||
|
}
|
||||||
|
|
||||||
ccore.set_critical_error_handler(nullptr);
|
ccore.set_critical_error_handler(nullptr);
|
||||||
ccore.set_currency_protocol(NULL);
|
ccore.set_currency_protocol(NULL);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue