BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
application_impl.hxx
Go to the documentation of this file.
1 #pragma once
2 
4 #include <fc/thread/parallel.hpp>
5 
10 #include <graphene/net/message.hpp>
11 
12 namespace graphene { namespace app { namespace detail {
13 
14 
15 class application_impl : public net::node_delegate, public std::enable_shared_from_this<application_impl>
16  {
17  public:
19  bool _is_block_producer = false;
20  bool _force_validate = false;
22 
23  void reset_p2p_node(const fc::path& data_dir);
24 
26 
28 
30 
31  explicit application_impl(application& self)
32  : _self(self),
33  _chain_db(std::make_shared<chain::database>())
34  {
35  }
36 
37  virtual ~application_impl();
38 
39  void set_block_production(bool producing_blocks);
40 
41  void set_api_limit();
42 
43  void initialize(const fc::path& data_dir, std::shared_ptr<boost::program_options::variables_map> options);
44  void startup();
45 
46  fc::optional< api_access_info > get_api_access_info(const string& username)const;
47 
48  void set_api_access_info(const string& username, api_access_info&& permissions);
49 
53  bool has_item(const net::item_id& id) override;
54 
65  bool handle_block(const graphene::net::block_message& blk_msg, bool sync_mode,
66  std::vector<graphene::net::message_hash_type>& contained_transaction_msg_ids) override;
67 
68  void handle_transaction(const graphene::net::trx_message& transaction_message) override;
69 
70  void handle_message(const graphene::net::message& message_to_process) override;
71 
73 
83  std::vector<graphene::net::item_hash_t> get_block_ids(
84  const std::vector<graphene::net::item_hash_t>& blockchain_synopsis,
85  uint32_t& remaining_item_count,
86  uint32_t limit) override;
87 
92 
94 
153  std::vector<graphene::net::item_hash_t> get_blockchain_synopsis(
154  const graphene::net::item_hash_t& reference_point,
155  uint32_t number_of_blocks_after_reference_point) override;
156 
165  void sync_status(uint32_t item_type, uint32_t item_count) override;
166 
170  void connection_count_changed(uint32_t c) override;
171 
172  uint32_t get_block_number(const graphene::net::item_hash_t& block_id) override;
173 
179 
181 
182  uint32_t estimate_last_known_fork_from_git_revision_timestamp(uint32_t unix_timestamp) const override;
183 
184  void error_encountered(const std::string& message, const fc::oexception& error) override;
185 
186  uint8_t get_current_block_interval_in_seconds() const override;
187 
189  void add_available_plugin( std::shared_ptr<abstract_plugin> p );
190 
192  void enable_plugin(const string& name);
193 
195  bool is_plugin_enabled(const string& name) const;
196 
197  private:
198  void shutdown();
199 
200  void initialize_plugins() const;
201  void startup_plugins() const;
202  void shutdown_plugins() const;
203 
205  graphene::chain::genesis_state_type initialize_genesis_state() const;
207  void open_chain_database() const;
208 
210 
211  application& _self;
212 
213  fc::path _data_dir;
214  std::shared_ptr<boost::program_options::variables_map> _options;
215  api_access _apiaccess;
216 
217  std::shared_ptr<graphene::chain::database> _chain_db;
218  std::shared_ptr<graphene::net::node> _p2p_network;
219  std::shared_ptr<fc::http::websocket_server> _websocket_server;
220  std::shared_ptr<fc::http::websocket_tls_server> _websocket_tls_server;
221 
222  std::map<string, std::shared_ptr<abstract_plugin>> _active_plugins;
223  std::map<string, std::shared_ptr<abstract_plugin>> _available_plugins;
224 
225  bool _is_finished_syncing = false;
226 
228  string _node_info;
229 
230  fc::serial_valve valve;
231  };
232 
233 }}} // namespace graphene namespace app namespace detail
graphene::net::block_message
Definition: core_messages.hpp:104
genesis_state.hpp
graphene::app::detail::application_impl::handle_transaction
void handle_transaction(const graphene::net::trx_message &transaction_message) override
Called when a new transaction comes in from the network.
Definition: application.cpp:733
graphene::app::detail::application_impl::error_encountered
void error_encountered(const std::string &message, const fc::oexception &error) override
Definition: application.cpp:1067
graphene::chain::database
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
graphene::app::detail::application_impl::set_block_production
void set_block_production(bool producing_blocks)
Definition: application.cpp:1152
message.hpp
parallel.hpp
graphene::app::detail::application_impl::new_connection
void new_connection(const fc::http::websocket_connection_ptr &c)
Definition: application.cpp:188
graphene::app::detail::application_impl::get_current_block_interval_in_seconds
uint8_t get_current_block_interval_in_seconds() const override
Definition: application.cpp:1072
graphene::net::message
Definition: message.hpp:58
api_access.hpp
fc::sha256
Definition: sha256.hpp:10
graphene::app::detail::application_impl::get_head_block_id
graphene::net::item_hash_t get_head_block_id() const override
Definition: application.cpp:1057
fc::http::websocket_connection_ptr
std::shared_ptr< websocket_connection > websocket_connection_ptr
Definition: websocket.hpp:47
graphene::app::detail::application_impl::add_available_plugin
void add_available_plugin(std::shared_ptr< abstract_plugin > p)
Add an available plugin.
Definition: application.cpp:1147
graphene::app::detail::application_impl::handle_message
void handle_message(const graphene::net::message &message_to_process) override
Called when a new message comes in from the network other than a block or a transaction....
Definition: application.cpp:749
graphene::app::detail::application_impl::~application_impl
virtual ~application_impl()
Definition: application.cpp:117
graphene::app::detail::application_impl::get_chain_id
graphene::chain::chain_id_type get_chain_id() const override
Definition: application.cpp:838
graphene::app::application
Definition: application.hpp:91
graphene::app::detail::application_impl::application_impl
application_impl(application &self)
Definition: application_impl.hxx:31
graphene::app::detail::application_impl::has_item
bool has_item(const net::item_id &id) override
Definition: application.cpp:640
graphene::net::item_id
Definition: core_messages.hpp:49
graphene::app::detail::application_impl::set_api_access_info
void set_api_access_info(const string &username, api_access_info &&permissions)
Definition: application.cpp:627
graphene::app::detail::application_impl::set_api_limit
void set_api_limit()
Definition: application.cpp:328
graphene::app::detail::application_impl::enable_plugin
void enable_plugin(const string &name)
Enables a plugin.
Definition: application.cpp:1111
types.hpp
fc::serial_valve
Definition: parallel.hpp:50
graphene::app::detail::application_impl::reset_websocket_server
void reset_websocket_server()
Definition: application.cpp:222
fc::path
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28
graphene::app::detail::application_impl::_lock_file
fc::optional< fc::temp_file > _lock_file
Definition: application_impl.hxx:18
graphene::app::api_access
Definition: api_access.hpp:48
graphene::app::detail::application_impl::reset_p2p_node
void reset_p2p_node(const fc::path &data_dir)
Definition: application.cpp:122
fc::time_point_sec
Definition: time.hpp:74
fc::ripemd160
Definition: ripemd160.hpp:11
graphene::app::detail::application_impl::startup
void startup()
Definition: application.cpp:597
graphene::app::detail::application_impl::sync_status
void sync_status(uint32_t item_type, uint32_t item_count) override
Definition: application.cpp:1028
graphene::app::detail::application_impl::estimate_last_known_fork_from_git_revision_timestamp
uint32_t estimate_last_known_fork_from_git_revision_timestamp(uint32_t unix_timestamp) const override
Definition: application.cpp:1062
graphene::app::detail::application_impl::_force_validate
bool _force_validate
Definition: application_impl.hxx:20
graphene::app::detail::application_impl::get_item
graphene::net::message get_item(const graphene::net::item_id &id) override
Definition: application.cpp:822
graphene::app::detail::application_impl::_is_block_producer
bool _is_block_producer
Definition: application_impl.hxx:19
graphene::app::detail::application_impl::get_block_ids
std::vector< graphene::net::item_hash_t > get_block_ids(const std::vector< graphene::net::item_hash_t > &blockchain_synopsis, uint32_t &remaining_item_count, uint32_t limit) override
Definition: application.cpp:771
websocket.hpp
graphene::app::detail::application_impl::get_api_access_info
fc::optional< api_access_info > get_api_access_info(const string &username) const
Definition: application.cpp:614
graphene::app::detail::application_impl::is_plugin_enabled
bool is_plugin_enabled(const string &name) const
Returns whether a plugin is enabled.
Definition: application.cpp:632
application.hpp
graphene::app::detail::application_impl::initialize
void initialize(const fc::path &data_dir, std::shared_ptr< boost::program_options::variables_map > options)
Definition: application.cpp:264
graphene::app::detail::application_impl
Definition: application_impl.hxx:15
graphene::chain::genesis_state_type
Definition: genesis_state.hpp:40
graphene::app::detail::application_impl::_app_options
application_options _app_options
Definition: application_impl.hxx:21
std
Definition: zeroed_array.hpp:76
graphene::app::detail::application_impl::get_block_number
uint32_t get_block_number(const graphene::net::item_hash_t &block_id) override
Definition: application.cpp:1041
graphene::app::detail::application_impl::get_block_time
fc::time_point_sec get_block_time(const graphene::net::item_hash_t &block_id) override
Definition: application.cpp:1050
graphene::net::trx_message
Definition: core_messages.hpp:93
graphene::app::detail::application_impl::connection_count_changed
void connection_count_changed(uint32_t c) override
Definition: application.cpp:1036
graphene::app::detail::application_impl::reset_websocket_tls_server
void reset_websocket_tls_server()
Definition: application.cpp:239
graphene::app::detail::application_impl::handle_block
bool handle_block(const graphene::net::block_message &blk_msg, bool sync_mode, std::vector< graphene::net::message_hash_type > &contained_transaction_msg_ids) override
allows the application to validate an item prior to broadcasting to peers.
Definition: application.cpp:660
fc::optional< fc::temp_file >
graphene::app::api_access_info
Definition: api_access.hpp:36
graphene::app::detail::application_impl::get_blockchain_synopsis
std::vector< graphene::net::item_hash_t > get_blockchain_synopsis(const graphene::net::item_hash_t &reference_point, uint32_t number_of_blocks_after_reference_point) override
Definition: application.cpp:901
graphene::app::detail::application_impl::is_included_block
bool is_included_block(const graphene::chain::block_id_type &block_id)
Definition: application.cpp:755
graphene
Definition: api.cpp:48
graphene::app::application_options
Definition: application.hpp:38
graphene::net::node_delegate
used by node reports status to client or fetch data from client
Definition: node.hpp:56