BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface 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
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
void enable_plugin(const string &name)
Enables a plugin.
void add_available_plugin(std::shared_ptr< abstract_plugin > p)
Add an available plugin.
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.
fc::optional< api_access_info > get_api_access_info(const string &username) const
bool has_item(const net::item_id &id) override
void set_block_production(bool producing_blocks)
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
void initialize(const fc::path &data_dir, std::shared_ptr< boost::program_options::variables_map > options)
void error_encountered(const std::string &message, const fc::oexception &error) override
Definition: api.cpp:48
bool is_included_block(const graphene::chain::block_id_type &block_id)
uint32_t get_block_number(const graphene::net::item_hash_t &block_id) override
used by node reports status to client or fetch data from client
Definition: node.hpp:56
void connection_count_changed(uint32_t c) override
fc::optional< fc::temp_file > _lock_file
std::shared_ptr< websocket_connection > websocket_connection_ptr
Definition: websocket.hpp:47
graphene::net::item_hash_t get_head_block_id() const override
void handle_transaction(const graphene::net::trx_message &transaction_message) override
Called when a new transaction comes in from the network.
uint8_t get_current_block_interval_in_seconds() const override
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
void set_api_access_info(const string &username, api_access_info &&permissions)
fc::time_point_sec get_block_time(const graphene::net::item_hash_t &block_id) override
uint32_t estimate_last_known_fork_from_git_revision_timestamp(uint32_t unix_timestamp) const override
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. Currently there are no other possible messages, so this should never be called.
void sync_status(uint32_t item_type, uint32_t item_count) override
void new_connection(const fc::http::websocket_connection_ptr &c)
graphene::net::message get_item(const graphene::net::item_id &id) override
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28
void reset_p2p_node(const fc::path &data_dir)
graphene::chain::chain_id_type get_chain_id() const override
bool is_plugin_enabled(const string &name) const
Returns whether a plugin is enabled.