39 #include "daemon/daemon.h" 55 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY 56 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "daemon" 58 namespace po = boost::program_options;
59 namespace bf = boost::filesystem;
82 throw std::runtime_error(
"restricted RPC mode is required");
88 throw std::runtime_error(
"invalid RPC port " + rpc_port_str);
94 throw std::runtime_error(
"failed to parse RPC bind address");
99 +
" network zone is not supported, please check RPC server bind address");
105 <<
" is enabled, but RPC server " <<
address->str()
106 <<
" may be unreachable from outside, please check RPC server bind address");
112 int main(
int argc,
char const * argv[])
123 po::options_description all_options(
"All");
124 po::options_description hidden_options(
"Hidden");
125 po::options_description visible_options(
"Options");
126 po::options_description core_settings(
"Settings");
127 po::positional_options_description positional_options;
153 visible_options.add(core_settings);
154 all_options.add(visible_options);
155 all_options.add(hidden_options);
162 po::variables_map vm;
165 boost::program_options::store(
166 boost::program_options::command_line_parser(argc, argv)
167 .options(all_options).positional(positional_options).run()
178 std::cout <<
"Usage: " +
std::string{argv[0]} +
" [options|settings] [daemon_command...]" << std::endl << std::endl;
179 std::cout << visible_options << std::endl;
198 boost::filesystem::path config_path(
config);
199 boost::system::error_code ec;
200 if (bf::exists(config_path, ec))
204 po::store(po::parse_config_file<char>(config_path.string<
std::string>().c_str(), core_settings), vm);
206 catch (
const std::exception &e)
209 std::cerr <<
"Error parsing config file: " << e.what() << std::endl;
215 std::cerr <<
"Can't find config file " <<
config << std::endl;
222 if (testnet + stagenet + regtest > 1)
224 std::cerr <<
"Can't specify more than one of --tesnet and --stagenet and --regtest" <<
ENDL;
233 std::cout <<
"Invalid database type (" << db_type <<
"), available types are: " <<
245 boost::filesystem::path
data_dir = boost::filesystem::absolute(
250 bf::path relative_path_base =
data_dir;
262 if (!log_file_path.has_parent_path())
263 log_file_path = bf::absolute(log_file_path, relative_path_base);
277 #endif // STACK_TRACE 296 std::cerr <<
"Invalid IP: " << rpc_ip_str << std::endl;
301 std::cerr <<
"Invalid port: " << rpc_port_str << std::endl;
305 const char *env_rpc_login =
nullptr;
307 const bool use_rpc_env = !has_rpc_arg && (env_rpc_login = getenv(
"RPC_LOGIN")) !=
nullptr && strlen(env_rpc_login) > 0;
308 boost::optional<tools::login> login{};
309 if (has_rpc_arg || use_rpc_env)
314 rdln::suspend_readline pause_readline;
316 return tools::password_container::prompt(verify,
"Daemon client password");
321 std::cerr <<
"Failed to obtain password" << std::endl;
331 if (rpc_commands.process_command_vec(command))
340 std::cerr <<
"Unknown command: " << command.front() << std::endl;
348 #endif // STACK_TRACE 356 MINFO(
"Moving from main() into the daemonize now.");
360 catch (std::exception
const & ex)
362 LOG_ERROR(
"Exception in main! " << ex.what());
const char *const ELECTRONEUM_RELEASE_NAME
#define MLOG_RED(level, x)
int main(int argc, char *argv[])
void init_options(boost::program_options::options_description &hidden_options, boost::program_options::options_description &normal_options)
const command_line::arg_descriptor< std::vector< std::string > > arg_command
const command_line::arg_descriptor< bool > arg_os_version
void mlog_set_log(const char *log)
void mlog_configure(const std::string &filename_base, bool console, const std::size_t max_log_file_size=MAX_LOG_FILE_SIZE, const std::size_t max_log_files=MAX_LOG_FILES)
const command_line::arg_descriptor< std::string > arg_zmq_rpc_bind_ip
const command_line::arg_descriptor< bool, false > arg_stagenet_on
const arg_descriptor< bool > arg_help
const command_line::arg_descriptor< std::string, false, true, 2 > arg_log_file
std::string blockchain_db_types(const std::string &sep)
boost::filesystem::path data_dir
const command_line::arg_descriptor< std::size_t > arg_max_log_file_size
const command_line::arg_descriptor< unsigned > arg_max_concurrency
const char *const ELECTRONEUM_VERSION_FULL
bool blockchain_valid_db_type(const std::string &db_type)
const command_line::arg_descriptor< std::string, false, true, 2 > arg_zmq_rpc_bind_port
const command_line::arg_descriptor< bool, false > arg_testnet_on
static const command_line::arg_descriptor< std::string > arg_rpc_restricted_bind_port
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
std::enable_if<!std::is_same< T, bool >::value, bool >::type has_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
expect< epee::net_utils::network_address > get_network_address(const boost::string_ref address, const std::uint16_t default_port)
const command_line::arg_descriptor< std::string > arg_log_level
static boost::optional< epee::net_utils::ssl_options_t > process_ssl(const boost::program_options::variables_map &vm, const bool any_cert_option=false)
const char * zone_to_string(zone value) noexcept
static void init_options(boost::program_options::options_description &configurable_options)
bool daemonize(int argc, char const *argv[], T_executor &&executor, boost::program_options::variables_map const &vm)
const command_line::arg_descriptor< std::string, false, true, 2 > arg_data_dir
const command_line::arg_descriptor< std::string > arg_db_type
const command_line::arg_descriptor< bool > arg_zmq_rpc_disabled
Useful when application has potentially harmful situtaions.
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
const command_line::arg_descriptor< std::string, false, true, 2 > arg_config_file
const command_line::arg_descriptor< bool > arg_public_node
const T & move(const T &t)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
uint16_t parse_public_rpc_port(const po::variables_map &vm)
const command_line::arg_descriptor< bool > arg_regtest_on
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
const arg_descriptor< bool > arg_version
const command_line::arg_descriptor< std::size_t > arg_max_log_files
bool is_arg_defaulted(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)