Implemented "plugins" config variable
From: https://github.com/bitshares/bitshares-core/pull/288
This commit is contained in:
parent
f097f94bdc
commit
604439dcaf
5 changed files with 86 additions and 17 deletions
|
|
@ -924,7 +924,8 @@ namespace detail {
|
||||||
std::shared_ptr<fc::http::websocket_server> _websocket_server;
|
std::shared_ptr<fc::http::websocket_server> _websocket_server;
|
||||||
std::shared_ptr<fc::http::websocket_tls_server> _websocket_tls_server;
|
std::shared_ptr<fc::http::websocket_tls_server> _websocket_tls_server;
|
||||||
|
|
||||||
std::map<string, std::shared_ptr<abstract_plugin>> _plugins;
|
std::map<string, std::shared_ptr<abstract_plugin>> _active_plugins;
|
||||||
|
std::map<string, std::shared_ptr<abstract_plugin>> _available_plugins;
|
||||||
|
|
||||||
bool _is_finished_syncing = false;
|
bool _is_finished_syncing = false;
|
||||||
};
|
};
|
||||||
|
|
@ -963,6 +964,7 @@ void application::set_program_options(boost::program_options::options_descriptio
|
||||||
("genesis-json", bpo::value<boost::filesystem::path>(), "File to read Genesis State from")
|
("genesis-json", bpo::value<boost::filesystem::path>(), "File to read Genesis State from")
|
||||||
("dbg-init-key", bpo::value<string>(), "Block signing key to use for init witnesses, overrides genesis file")
|
("dbg-init-key", bpo::value<string>(), "Block signing key to use for init witnesses, overrides genesis file")
|
||||||
("api-access", bpo::value<boost::filesystem::path>(), "JSON file specifying API permissions")
|
("api-access", bpo::value<boost::filesystem::path>(), "JSON file specifying API permissions")
|
||||||
|
("plugins", bpo::value<string>(), "Space-separated list of plugins to activate")
|
||||||
;
|
;
|
||||||
command_line_options.add(configuration_file_options);
|
command_line_options.add(configuration_file_options);
|
||||||
command_line_options.add_options()
|
command_line_options.add_options()
|
||||||
|
|
@ -1008,6 +1010,22 @@ void application::initialize(const fc::path& data_dir, const boost::program_opti
|
||||||
|
|
||||||
std::exit(EXIT_SUCCESS);
|
std::exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<string> wanted;
|
||||||
|
if( options.count("plugins") )
|
||||||
|
{
|
||||||
|
boost::split(wanted, options.at("plugins").as<std::string>(), [](char c){return c == ' ';});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wanted.push_back("witness");
|
||||||
|
wanted.push_back("account_history");
|
||||||
|
wanted.push_back("market_history");
|
||||||
|
}
|
||||||
|
for (auto& it : wanted)
|
||||||
|
{
|
||||||
|
if (!it.empty()) enable_plugin(it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void application::startup()
|
void application::startup()
|
||||||
|
|
@ -1025,7 +1043,7 @@ void application::startup()
|
||||||
|
|
||||||
std::shared_ptr<abstract_plugin> application::get_plugin(const string& name) const
|
std::shared_ptr<abstract_plugin> application::get_plugin(const string& name) const
|
||||||
{
|
{
|
||||||
return my->_plugins[name];
|
return my->_active_plugins[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
net::node_ptr application::p2p_node()
|
net::node_ptr application::p2p_node()
|
||||||
|
|
@ -1058,14 +1076,20 @@ bool application::is_finished_syncing() const
|
||||||
return my->_is_finished_syncing;
|
return my->_is_finished_syncing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void graphene::app::application::add_plugin(const string& name, std::shared_ptr<graphene::app::abstract_plugin> p)
|
void graphene::app::application::enable_plugin(const string& name)
|
||||||
{
|
{
|
||||||
my->_plugins[name] = p;
|
FC_ASSERT(my->_available_plugins[name], "Unknown plugin '" + name + "'");
|
||||||
|
my->_active_plugins[name] = my->_available_plugins[name];
|
||||||
|
my->_active_plugins[name]->plugin_set_app(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void graphene::app::application::add_available_plugin(std::shared_ptr<graphene::app::abstract_plugin> p) {
|
||||||
|
my->_available_plugins[p->plugin_name()] = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void application::shutdown_plugins()
|
void application::shutdown_plugins()
|
||||||
{
|
{
|
||||||
for( auto& entry : my->_plugins )
|
for( auto& entry : my->_active_plugins )
|
||||||
entry.second->plugin_shutdown();
|
entry.second->plugin_shutdown();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1079,14 +1103,14 @@ void application::shutdown()
|
||||||
|
|
||||||
void application::initialize_plugins( const boost::program_options::variables_map& options )
|
void application::initialize_plugins( const boost::program_options::variables_map& options )
|
||||||
{
|
{
|
||||||
for( auto& entry : my->_plugins )
|
for( auto& entry : my->_active_plugins )
|
||||||
entry.second->plugin_initialize( options );
|
entry.second->plugin_initialize( options );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void application::startup_plugins()
|
void application::startup_plugins()
|
||||||
{
|
{
|
||||||
for( auto& entry : my->_plugins )
|
for( auto& entry : my->_active_plugins )
|
||||||
entry.second->plugin_startup();
|
entry.second->plugin_startup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,8 @@ namespace graphene { namespace app {
|
||||||
boost::signals2::signal<void()> syncing_finished;
|
boost::signals2::signal<void()> syncing_finished;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void add_plugin( const string& name, std::shared_ptr<abstract_plugin> p );
|
void enable_plugin( const string& name );
|
||||||
|
void add_available_plugin( std::shared_ptr<abstract_plugin> p );
|
||||||
std::shared_ptr<detail::application_impl> my;
|
std::shared_ptr<detail::application_impl> my;
|
||||||
|
|
||||||
boost::program_options::options_description _cli_options;
|
boost::program_options::options_description _cli_options;
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ delayed_node_plugin::~delayed_node_plugin()
|
||||||
void delayed_node_plugin::plugin_set_program_options(bpo::options_description& cli, bpo::options_description& cfg)
|
void delayed_node_plugin::plugin_set_program_options(bpo::options_description& cli, bpo::options_description& cfg)
|
||||||
{
|
{
|
||||||
cli.add_options()
|
cli.add_options()
|
||||||
("trusted-node", boost::program_options::value<std::string>()->required(), "RPC endpoint of a trusted validating node (required)")
|
("trusted-node", boost::program_options::value<std::string>(), "RPC endpoint of a trusted validating node (required)")
|
||||||
;
|
;
|
||||||
cfg.add(cli);
|
cfg.add(cli);
|
||||||
}
|
}
|
||||||
|
|
@ -74,6 +74,7 @@ void delayed_node_plugin::connect()
|
||||||
|
|
||||||
void delayed_node_plugin::plugin_initialize(const boost::program_options::variables_map& options)
|
void delayed_node_plugin::plugin_initialize(const boost::program_options::variables_map& options)
|
||||||
{
|
{
|
||||||
|
FC_ASSERT(options.count("trusted-node") > 0);
|
||||||
my->remote_endpoint = "ws://" + options.at("trusted-node").as<std::string>();
|
my->remote_endpoint = "ws://" + options.at("trusted-node").as<std::string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,10 +70,19 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
bpo::variables_map options;
|
bpo::variables_map options;
|
||||||
|
|
||||||
|
bpo::options_description cli, cfg;
|
||||||
|
node.set_program_options(cli, cfg);
|
||||||
|
cfg_options.add(cfg);
|
||||||
|
|
||||||
|
cfg_options.add_options()
|
||||||
|
("plugins", bpo::value<std::string>()->default_value("delayed_node account_history market_history"),
|
||||||
|
"Space-separated list of plugins to activate");
|
||||||
|
|
||||||
auto delayed_plug = node.register_plugin<delayed_node::delayed_node_plugin>();
|
auto delayed_plug = node.register_plugin<delayed_node::delayed_node_plugin>();
|
||||||
auto history_plug = node.register_plugin<account_history::account_history_plugin>();
|
auto history_plug = node.register_plugin<account_history::account_history_plugin>();
|
||||||
auto market_history_plug = node.register_plugin<market_history::market_history_plugin>();
|
auto market_history_plug = node.register_plugin<market_history::market_history_plugin>();
|
||||||
|
|
||||||
|
// add plugin options to config
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bpo::options_description cli, cfg;
|
bpo::options_description cli, cfg;
|
||||||
|
|
@ -160,6 +169,9 @@ int main(int argc, char** argv) {
|
||||||
elog("Error parsing configuration file: ${e}", ("e", e.what()));
|
elog("Error parsing configuration file: ${e}", ("e", e.what()));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if( !options.count("plugins") )
|
||||||
|
options.insert( std::make_pair( "plugins", bpo::variable_value(std::string("delayed_node account_history market_history"), true) ) );
|
||||||
|
|
||||||
node.initialize(data_dir, options);
|
node.initialize(data_dir, options);
|
||||||
node.initialize_plugins( options );
|
node.initialize_plugins( options );
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,12 +78,23 @@ int main(int argc, char** argv) {
|
||||||
bpo::options_description cfg_options("Graphene Witness Node");
|
bpo::options_description cfg_options("Graphene Witness Node");
|
||||||
app_options.add_options()
|
app_options.add_options()
|
||||||
("help,h", "Print this help message and exit.")
|
("help,h", "Print this help message and exit.")
|
||||||
("version", "Display the version info and exit")
|
("data-dir,d", bpo::value<boost::filesystem::path>()->default_value("witness_node_data_dir"),
|
||||||
("data-dir,d", bpo::value<boost::filesystem::path>()->default_value("witness_node_data_dir"), "Directory containing databases, configuration file, etc.")
|
"Directory containing databases, configuration file, etc.")
|
||||||
;
|
("version,v", "Display version information")
|
||||||
|
("plugins", bpo::value<std::string>()
|
||||||
|
->default_value("witness account_history market_history grouped_orders api_helper_indexes"),
|
||||||
|
"Space-separated list of plugins to activate");
|
||||||
|
|
||||||
bpo::variables_map options;
|
bpo::variables_map options;
|
||||||
|
|
||||||
|
bpo::options_description cli, cfg;
|
||||||
|
node->set_program_options(cli, cfg);
|
||||||
|
cfg_options.add(cfg);
|
||||||
|
|
||||||
|
cfg_options.add_options()
|
||||||
|
("plugins", bpo::value<std::string>()->default_value("witness account_history market_history grouped_orders"),
|
||||||
|
"Space-separated list of plugins to activate");
|
||||||
|
|
||||||
auto witness_plug = node->register_plugin<witness_plugin::witness_plugin>();
|
auto witness_plug = node->register_plugin<witness_plugin::witness_plugin>();
|
||||||
auto history_plug = node->register_plugin<account_history::account_history_plugin>();
|
auto history_plug = node->register_plugin<account_history::account_history_plugin>();
|
||||||
auto market_history_plug = node->register_plugin<market_history::market_history_plugin>();
|
auto market_history_plug = node->register_plugin<market_history::market_history_plugin>();
|
||||||
|
|
@ -95,6 +106,7 @@ int main(int argc, char** argv) {
|
||||||
auto peerplays_sidechain = node->register_plugin<peerplays_sidechain::peerplays_sidechain_plugin>();
|
auto peerplays_sidechain = node->register_plugin<peerplays_sidechain::peerplays_sidechain_plugin>();
|
||||||
// auto snapshot_plug = node->register_plugin<snapshot_plugin::snapshot_plugin>();
|
// auto snapshot_plug = node->register_plugin<snapshot_plugin::snapshot_plugin>();
|
||||||
|
|
||||||
|
// add plugin options to config
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bpo::options_description cli, cfg;
|
bpo::options_description cli, cfg;
|
||||||
|
|
@ -109,11 +121,6 @@ int main(int argc, char** argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( options.count("help") )
|
|
||||||
{
|
|
||||||
std::cout << app_options << "\n";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (options.count("version"))
|
if (options.count("version"))
|
||||||
{
|
{
|
||||||
std::string witness_version(graphene::utilities::git_revision_description);
|
std::string witness_version(graphene::utilities::git_revision_description);
|
||||||
|
|
@ -127,6 +134,11 @@ int main(int argc, char** argv) {
|
||||||
std::cout << "Boost: " << boost::replace_all_copy(std::string(BOOST_LIB_VERSION), "_", ".") << "\n";
|
std::cout << "Boost: " << boost::replace_all_copy(std::string(BOOST_LIB_VERSION), "_", ".") << "\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if( options.count("help") )
|
||||||
|
{
|
||||||
|
std::cout << app_options << "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
fc::path data_dir;
|
fc::path data_dir;
|
||||||
if( options.count("data-dir") )
|
if( options.count("data-dir") )
|
||||||
|
|
@ -160,6 +172,7 @@ int main(int argc, char** argv) {
|
||||||
if( !fc::exists(data_dir) )
|
if( !fc::exists(data_dir) )
|
||||||
fc::create_directories(data_dir);
|
fc::create_directories(data_dir);
|
||||||
|
|
||||||
|
boost::container::flat_set<std::string> seen;
|
||||||
std::ofstream out_cfg(config_ini_path.preferred_string());
|
std::ofstream out_cfg(config_ini_path.preferred_string());
|
||||||
for( const boost::shared_ptr<bpo::option_description> od : cfg_options.options() )
|
for( const boost::shared_ptr<bpo::option_description> od : cfg_options.options() )
|
||||||
{
|
{
|
||||||
|
|
@ -169,6 +182,9 @@ int main(int argc, char** argv) {
|
||||||
if( !od->semantic()->apply_default(store) )
|
if( !od->semantic()->apply_default(store) )
|
||||||
out_cfg << "# " << od->long_name() << " = \n";
|
out_cfg << "# " << od->long_name() << " = \n";
|
||||||
else {
|
else {
|
||||||
|
const std::string name = od->long_name();
|
||||||
|
if( seen.find(name) != seen.end() ) continue;
|
||||||
|
seen.insert(name);
|
||||||
auto example = od->format_parameter();
|
auto example = od->format_parameter();
|
||||||
if( example.empty() )
|
if( example.empty() )
|
||||||
// This is a boolean switch
|
// This is a boolean switch
|
||||||
|
|
@ -190,7 +206,22 @@ int main(int argc, char** argv) {
|
||||||
fc::configure_logging(*logging_config);
|
fc::configure_logging(*logging_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<std::string> plugins;
|
||||||
|
boost::split(plugins, options.at("plugins").as<std::string>(), [](char c){return c == ' ';});
|
||||||
|
|
||||||
|
if(plugins.count("account_history") && plugins.count("elasticsearch")) {
|
||||||
|
std::cerr << "Plugin conflict: Cannot load both account_history plugin and elasticsearch plugin\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::for_each(plugins.begin(), plugins.end(), [node](const std::string& plug) mutable {
|
||||||
|
if (!plug.empty()) {
|
||||||
|
node->enable_plugin(plug);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
bpo::notify(options);
|
bpo::notify(options);
|
||||||
|
|
||||||
node->initialize(data_dir, options);
|
node->initialize(data_dir, options);
|
||||||
node->initialize_plugins( options );
|
node->initialize_plugins( options );
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue