Skip to content

Commit

Permalink
Add app option to disallow universal subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
abitmore committed Mar 17, 2018
1 parent f287324 commit 883cb05
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace graphene { namespace app {
{
if( api_name == "database_api" )
{
_database_api = std::make_shared< database_api >( std::ref( *_app.chain_database() ) );
_database_api = std::make_shared< database_api >( std::ref( *_app.chain_database() ), &( _app.get_options() ) );
}
else if( api_name == "block_api" )
{
Expand Down
11 changes: 10 additions & 1 deletion libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ namespace detail {
fc::optional<fc::temp_file> _lock_file;
bool _is_block_producer = false;
bool _force_validate = false;
application_options _app_options;

void reset_p2p_node(const fc::path& data_dir)
{ try {
Expand Down Expand Up @@ -404,6 +405,9 @@ namespace detail {
_force_validate = true;
}

if( _options->count("enable-subscribe-to-all") )
_app_options.enable_subscribe_to_all = _options->at("enable-subscribe-to-all").as<bool>();

if( _options->count("api-access") ) {

if(fc::exists(_options->at("api-access").as<boost::filesystem::path>()))
Expand All @@ -419,7 +423,6 @@ namespace detail {
std::exit(EXIT_FAILURE);
}
}

else
{
// TODO: Remove this generous default access policy
Expand Down Expand Up @@ -933,6 +936,7 @@ void application::set_program_options(boost::program_options::options_descriptio
("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")
("plugins", bpo::value<string>(), "Space-separated list of plugins to activate")
("enable-subscribe-to-all", bpo::value<bool>()->implicit_value(false), "Whether allow API clients to subscribe to universal object creation and removal events")
;
command_line_options.add(configuration_file_options);
command_line_options.add_options()
Expand Down Expand Up @@ -1098,5 +1102,10 @@ void application::startup_plugins()
return;
}

const application_options& application::get_options()
{
return my->_app_options;
}

// namespace detail
} }
16 changes: 12 additions & 4 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class database_api_impl;
class database_api_impl : public std::enable_shared_from_this<database_api_impl>
{
public:
database_api_impl( graphene::chain::database& db );
database_api_impl( graphene::chain::database& db, const application_options* app_options );
~database_api_impl();


Expand Down Expand Up @@ -229,6 +229,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
boost::signals2::scoped_connection _pending_trx_connection;
map< pair<asset_id_type,asset_id_type>, std::function<void(const variant&)> > _market_subscriptions;
graphene::chain::database& _db;
const application_options* _app_options = nullptr;
};

//////////////////////////////////////////////////////////////////////
Expand All @@ -237,12 +238,13 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
// //
//////////////////////////////////////////////////////////////////////

database_api::database_api( graphene::chain::database& db )
: my( new database_api_impl( db ) ) {}
database_api::database_api( graphene::chain::database& db, const application_options* app_options )
: my( new database_api_impl( db, app_options ) ) {}

database_api::~database_api() {}

database_api_impl::database_api_impl( graphene::chain::database& db ):_db(db)
database_api_impl::database_api_impl( graphene::chain::database& db, const application_options* app_options )
:_db(db), _app_options(app_options)
{
wlog("creating database api ${x}", ("x",int64_t(this)) );
_new_connection = _db.new_objects.connect([this](const vector<object_id_type>& ids, const flat_set<account_id_type>& impacted_accounts) {
Expand Down Expand Up @@ -315,6 +317,12 @@ void database_api::set_subscribe_callback( std::function<void(const variant&)> c

void database_api_impl::set_subscribe_callback( std::function<void(const variant&)> cb, bool notify_remove_create )
{
if( notify_remove_create )
{
FC_ASSERT( _app_options && _app_options->enable_subscribe_to_all,
"Subscribing to universal object creation and removal is disallowed in this server." );
}

_subscribe_callback = cb;
_notify_remove_create = notify_remove_create;
_subscribed_accounts.clear();
Expand Down
8 changes: 8 additions & 0 deletions libraries/app/include/graphene/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ namespace graphene { namespace app {

class abstract_plugin;

class application_options
{
public:
bool enable_subscribe_to_all = false;
};

class application
{
public:
Expand Down Expand Up @@ -89,6 +95,8 @@ namespace graphene { namespace app {
/// Emitted when syncing finishes (is_finished_syncing will return true)
boost::signals2::signal<void()> syncing_finished;

const application_options& get_options();

private:
void enable_plugin( const string& name );
void add_available_plugin( std::shared_ptr<abstract_plugin> p );
Expand Down
2 changes: 1 addition & 1 deletion libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct market_trade
class database_api
{
public:
database_api(graphene::chain::database& db);
database_api(graphene::chain::database& db, const application_options* app_options = nullptr );
~database_api();

/////////////
Expand Down

0 comments on commit 883cb05

Please sign in to comment.