Implemented "plugins" config variable
This commit is contained in:
parent
b1f2ba5ba6
commit
e1244eb7ab
4 changed files with 41 additions and 12 deletions
|
|
@ -891,7 +891,8 @@ namespace detail {
|
|||
std::shared_ptr<fc::http::websocket_server> _websocket_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;
|
||||
};
|
||||
|
|
@ -933,6 +934,7 @@ void application::set_program_options(boost::program_options::options_descriptio
|
|||
("enable-standby-votes-tracking", bpo::value<bool>()->implicit_value(true),
|
||||
"Whether to enable tracking of votes of standby witnesses and committee members. "
|
||||
"Set it to true to provide accurate data to API clients, set to false for slightly better performance.")
|
||||
("plugins", bpo::value<string>(), "Space-separated list of plugins to activate")
|
||||
;
|
||||
command_line_options.add(configuration_file_options);
|
||||
command_line_options.add_options()
|
||||
|
|
@ -978,6 +980,22 @@ void application::initialize(const fc::path& data_dir, const boost::program_opti
|
|||
|
||||
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.cbegin(); it != wanted.cend(); it++)
|
||||
{
|
||||
if (!it->empty()) enable_plugin(*it);
|
||||
}
|
||||
}
|
||||
|
||||
void application::startup()
|
||||
|
|
@ -995,7 +1013,7 @@ void application::startup()
|
|||
|
||||
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()
|
||||
|
|
@ -1028,14 +1046,21 @@ bool application::is_finished_syncing() const
|
|||
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()
|
||||
{
|
||||
for( auto& entry : my->_plugins )
|
||||
for( auto& entry : my->_active_plugins )
|
||||
entry.second->plugin_shutdown();
|
||||
return;
|
||||
}
|
||||
|
|
@ -1049,14 +1074,14 @@ void application::shutdown()
|
|||
|
||||
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 );
|
||||
return;
|
||||
}
|
||||
|
||||
void application::startup_plugins()
|
||||
{
|
||||
for( auto& entry : my->_plugins )
|
||||
for( auto& entry : my->_active_plugins )
|
||||
entry.second->plugin_startup();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ namespace graphene { namespace app {
|
|||
if( !plugin_cfg_options.options().empty() )
|
||||
_cfg_options.add(plugin_cfg_options);
|
||||
|
||||
add_plugin( plug->plugin_name(), plug );
|
||||
add_available_plugin( plug );
|
||||
return plug;
|
||||
}
|
||||
std::shared_ptr<abstract_plugin> get_plugin( const string& name )const;
|
||||
|
|
@ -89,7 +89,8 @@ namespace graphene { namespace app {
|
|||
boost::signals2::signal<void()> syncing_finished;
|
||||
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
|
@ -74,6 +74,7 @@ void delayed_node_plugin::connect()
|
|||
|
||||
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>();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include <graphene/app/config_util.hpp>
|
||||
|
||||
#include <graphene/witness/witness.hpp>
|
||||
#include <graphene/debug_witness/debug_witness.hpp>
|
||||
#include <graphene/account_history/account_history_plugin.hpp>
|
||||
#include <graphene/accounts_list/accounts_list_plugin.hpp>
|
||||
#include <graphene/market_history/market_history_plugin.hpp>
|
||||
|
|
@ -71,6 +72,7 @@ int main(int argc, char** argv) {
|
|||
bpo::variables_map options;
|
||||
|
||||
auto witness_plug = node->register_plugin<witness_plugin::witness_plugin>();
|
||||
auto debug_witness_plug = node->register_plugin<debug_witness_plugin::debug_witness_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 generate_genesis_plug = node->register_plugin<generate_genesis_plugin::generate_genesis_plugin>();
|
||||
|
|
@ -142,7 +144,7 @@ int main(int argc, char** argv) {
|
|||
exit_promise->set_value(signal);
|
||||
}, SIGTERM);
|
||||
|
||||
ilog("Started witness node on a chain with ${h} blocks.", ("h", node->chain_database()->head_block_num()));
|
||||
ilog("Started BitShares node on a chain with ${h} blocks.", ("h", node->chain_database()->head_block_num()));
|
||||
ilog("Chain ID is ${id}", ("id", node->chain_database()->get_chain_id()) );
|
||||
|
||||
int signal = exit_promise->wait();
|
||||
|
|
@ -163,4 +165,4 @@ int main(int argc, char** argv) {
|
|||
delete node;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue