BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
core_messages.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <graphene/net/config.hpp>
27 
28 #include <fc/crypto/ripemd160.hpp>
29 #include <fc/crypto/elliptic.hpp>
30 #include <fc/crypto/sha256.hpp>
31 #include <fc/network/ip.hpp>
32 #include <fc/time.hpp>
33 #include <fc/variant_object.hpp>
35 #include <fc/io/enum_type.hpp>
36 
38 
39 #include <vector>
40 
41 namespace graphene { namespace net {
46 
49  struct item_id
50  {
51  uint32_t item_type;
52  item_hash_t item_hash;
53 
54  item_id() {}
55  item_id(uint32_t type, const item_hash_t& hash) :
56  item_type(type),
57  item_hash(hash)
58  {}
59  bool operator==(const item_id& other) const
60  {
61  return item_type == other.item_type &&
62  item_hash == other.item_hash;
63  }
64  };
65 
67  {
89  };
90 
92 
93  struct trx_message
94  {
96 
100  trx(std::move(transaction))
101  {}
102  };
103 
105  {
107 
110  :block(blk),block_id(blk.id()){}
111 
114 
115  };
116 
118  {
120 
121  uint32_t item_type;
122  std::vector<item_hash_t> item_hashes_available;
123 
125  item_ids_inventory_message(uint32_t item_type, const std::vector<item_hash_t>& item_hashes_available) :
126  item_type(item_type),
127  item_hashes_available(item_hashes_available)
128  {}
129  };
130 
132  {
134 
136  uint32_t item_type;
137  std::vector<item_hash_t> item_hashes_available;
138 
140  blockchain_item_ids_inventory_message(uint32_t total_remaining_item_count,
141  uint32_t item_type,
142  const std::vector<item_hash_t>& item_hashes_available) :
143  total_remaining_item_count(total_remaining_item_count),
144  item_type(item_type),
145  item_hashes_available(item_hashes_available)
146  {}
147  };
148 
150  {
152 
153  uint32_t item_type;
154  std::vector<item_hash_t> blockchain_synopsis;
155 
157  fetch_blockchain_item_ids_message(uint32_t item_type, const std::vector<item_hash_t>& blockchain_synopsis) :
158  item_type(item_type),
159  blockchain_synopsis(blockchain_synopsis)
160  {}
161  };
162 
164  {
166 
167  uint32_t item_type;
168  std::vector<item_hash_t> items_to_fetch;
169 
171  fetch_items_message(uint32_t item_type, const std::vector<item_hash_t>& items_to_fetch) :
172  item_type(item_type),
173  items_to_fetch(items_to_fetch)
174  {}
175  };
176 
178  {
180 
182 
184  item_not_available_message(const item_id& requested_item) :
185  requested_item(requested_item)
186  {}
187  };
188 
190  {
192 
193  std::string user_agent;
196  uint16_t inbound_port;
197  uint16_t outbound_port;
198  node_id_t node_public_key;
202 
204  hello_message(const std::string& user_agent,
205  uint32_t core_protocol_version,
206  const fc::ip::address& inbound_address,
207  uint16_t inbound_port,
208  uint16_t outbound_port,
209  const node_id_t& node_public_key,
210  const fc::ecc::compact_signature& signed_shared_secret,
211  const fc::sha256& chain_id_arg,
212  const fc::variant_object& user_data ) :
213  user_agent(user_agent),
214  core_protocol_version(core_protocol_version),
215  inbound_address(inbound_address),
216  inbound_port(inbound_port),
217  outbound_port(outbound_port),
218  node_public_key(node_public_key),
219  signed_shared_secret(signed_shared_secret),
220  chain_id(chain_id_arg),
221  user_data(user_data)
222  {}
223  };
224 
226  {
228 
230  };
231 
237  blocked,
239  client_too_old };
240 
242  {
244 
245  std::string user_agent;
248  std::string reason_string;
250 
252  connection_rejected_message(const std::string& user_agent, uint32_t core_protocol_version,
253  const fc::ip::endpoint& remote_endpoint, rejection_reason_code reason_code,
254  const std::string& reason_string) :
255  user_agent(user_agent),
256  core_protocol_version(core_protocol_version),
257  remote_endpoint(remote_endpoint),
258  reason_string(reason_string),
259  reason_code(reason_code)
260  {}
261  };
262 
264  {
266 
268  };
269 
272 
274  {
278  node_id_t node_id;
281 
283  address_info(const fc::ip::endpoint& remote_endpoint,
284  const fc::time_point_sec last_seen_time,
285  const fc::microseconds latency,
286  const node_id_t& node_id,
287  peer_connection_direction direction,
288  firewalled_state firewalled) :
289  remote_endpoint(remote_endpoint),
290  last_seen_time(last_seen_time),
291  latency(latency),
292  node_id(node_id),
293  direction(direction),
294  firewalled(firewalled)
295  {}
296  };
297 
299  {
301 
302  std::vector<address_info> addresses;
303  };
304 
306  {
308 
309  std::string reason_for_closing;
312 
313  closing_connection_message() : closing_due_to_error(false) {}
314  closing_connection_message(const std::string& reason_for_closing,
315  bool closing_due_to_error = false,
316  const fc::oexception& error = fc::oexception()) :
317  reason_for_closing(reason_for_closing),
318  closing_due_to_error(closing_due_to_error),
319  error(error)
320  {}
321  };
322 
324  {
327 
329  current_time_request_message(const fc::time_point request_sent_time) :
330  request_sent_time(request_sent_time)
331  {}
332  };
333 
335  {
340 
343  const fc::time_point request_received_time,
344  const fc::time_point reply_transmitted_time = fc::time_point()) :
345  request_sent_time(request_sent_time),
346  request_received_time(request_received_time),
347  reply_transmitted_time(reply_transmitted_time)
348  {}
349  };
350 
352  {
354  node_id_t node_id;
356  };
357 
359  {
363  };
364 
366  {
368  node_id_t node_id;
371  };
372 
374  {
376  };
377 
379  {
380  uint32_t connection_duration; // in seconds
382  node_id_t node_id;
388  };
389 
391  {
399  std::vector<current_connection_data> current_connections;
400  };
401 
402 } } // graphene::net
403 
431  (blocked)
433  (client_too_old))
435  (inbound)
436  (outbound))
438  (firewalled)
439  (not_firewalled))
443 
444 FC_REFLECT_TYPENAME( graphene::net::trx_message )
445 FC_REFLECT_TYPENAME( graphene::net::block_message )
447 FC_REFLECT_TYPENAME( graphene::net::item_ids_inventory_message )
448 FC_REFLECT_TYPENAME( graphene::net::blockchain_item_ids_inventory_message )
449 FC_REFLECT_TYPENAME( graphene::net::fetch_blockchain_item_ids_message )
450 FC_REFLECT_TYPENAME( graphene::net::fetch_items_message )
451 FC_REFLECT_TYPENAME( graphene::net::item_not_available_message )
452 FC_REFLECT_TYPENAME( graphene::net::hello_message )
453 FC_REFLECT_TYPENAME( graphene::net::connection_accepted_message )
454 FC_REFLECT_TYPENAME( graphene::net::connection_rejected_message )
455 FC_REFLECT_TYPENAME( graphene::net::address_request_message )
456 FC_REFLECT_TYPENAME( graphene::net::address_info )
457 FC_REFLECT_TYPENAME( graphene::net::address_message )
458 FC_REFLECT_TYPENAME( graphene::net::closing_connection_message )
459 FC_REFLECT_TYPENAME( graphene::net::current_time_request_message )
460 FC_REFLECT_TYPENAME( graphene::net::current_time_reply_message )
461 FC_REFLECT_TYPENAME( graphene::net::check_firewall_message )
462 FC_REFLECT_TYPENAME( graphene::net::check_firewall_reply_message )
463 FC_REFLECT_TYPENAME( graphene::net::get_current_connections_request_message )
464 FC_REFLECT_TYPENAME( graphene::net::current_connection_data )
465 FC_REFLECT_TYPENAME( graphene::net::get_current_connections_reply_message )
466 
470 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::item_ids_inventory_message )
471 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::blockchain_item_ids_inventory_message )
472 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::fetch_blockchain_item_ids_message )
473 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::fetch_items_message )
474 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::item_not_available_message )
476 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::connection_accepted_message )
477 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::connection_rejected_message )
478 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::address_request_message )
480 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::address_message )
481 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::closing_connection_message )
482 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::current_time_request_message )
483 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::current_time_reply_message )
484 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::check_firewall_message )
485 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::check_firewall_reply_message )
486 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::get_current_connections_request_message )
487 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::current_connection_data )
488 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::net::get_current_connections_reply_message )
489 
490 #include <unordered_map>
491 #include <fc/crypto/city.hpp>
492 #include <fc/crypto/sha224.hpp>
493 namespace std
494 {
495  template<>
496  struct hash<graphene::net::item_id>
497  {
498  size_t operator()(const graphene::net::item_id& item_to_hash) const
499  {
500  return fc::city_hash_size_t((char*)&item_to_hash, sizeof(item_to_hash));
501  }
502  };
503 }
block_message(const signed_block &blk)
fc::enum_type< uint8_t, firewalled_state > firewalled
static const core_message_type_enum type
const uint32_t core_protocol_version
blockchain_item_ids_inventory_message(uint32_t total_remaining_item_count, uint32_t item_type, const std::vector< item_hash_t > &item_hashes_available)
size_t city_hash_size_t(const char *buf, size_t len)
Definition: city.hpp:59
current_time_request_message(const fc::time_point request_sent_time)
current_time_reply_message(const fc::time_point request_sent_time, const fc::time_point request_received_time, const fc::time_point reply_transmitted_time=fc::time_point())
An order-perserving dictionary of variant&#39;s.
static const core_message_type_enum type
item_id(uint32_t type, const item_hash_t &hash)
Definition: api.cpp:56
static const core_message_type_enum type
closing_connection_message(const std::string &reason_for_closing, bool closing_due_to_error=false, const fc::oexception &error=fc::oexception())
fc::enum_type< uint8_t, peer_connection_direction > connection_direction
static const core_message_type_enum type
std::vector< item_hash_t > items_to_fetch
std::vector< item_hash_t > item_hashes_available
fc::ripemd160 item_hash_t
fc::ripemd160 block_id_type
Definition: types.hpp:242
std::vector< address_info > addresses
static const core_message_type_enum type
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
graphene::protocol::precomputable_transaction trx
FC_REFLECT_TYPENAME(fc::log_message)
FC_REFLECT_ENUM(graphene::net::core_message_type_enum,(trx_message_type)(block_message_type)(core_message_type_first)(item_ids_inventory_message_type)(blockchain_item_ids_inventory_message_type)(fetch_blockchain_item_ids_message_type)(fetch_items_message_type)(item_not_available_message_type)(hello_message_type)(connection_accepted_message_type)(connection_rejected_message_type)(address_request_message_type)(address_message_type)(closing_connection_message_type)(current_time_request_message_type)(current_time_reply_message_type)(check_firewall_message_type)(check_firewall_reply_message_type)(get_current_connections_request_message_type)(get_current_connections_reply_message_type)(core_message_type_last))(different_chain)(already_connected)(connected_to_self)(not_accepting_connections)(blocked)(invalid_hello_message)(client_too_old))(inbound)(outbound))(firewalled)(not_firewalled))(unable_to_connect)(connection_successful)) namespace std
fc::enum_type< uint8_t, firewall_check_result > result
fc::ip::endpoint remote_endpoint
static const core_message_type_enum type
fetch_blockchain_item_ids_message(uint32_t item_type, const std::vector< item_hash_t > &blockchain_synopsis)
fc::ecc::compact_signature signed_shared_secret
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
fc::ecc::public_key_data node_id_t
address_info(const fc::ip::endpoint &remote_endpoint, const fc::time_point_sec last_seen_time, const fc::microseconds latency, const node_id_t &node_id, peer_connection_direction direction, firewalled_state firewalled)
fc::variant_object user_data
item_ids_inventory_message(uint32_t item_type, const std::vector< item_hash_t > &item_hashes_available)
item_not_available_message(const item_id &requested_item)
hello_message(const std::string &user_agent, uint32_t core_protocol_version, const fc::ip::address &inbound_address, uint16_t inbound_port, uint16_t outbound_port, const node_id_t &node_public_key, const fc::ecc::compact_signature &signed_shared_secret, const fc::sha256 &chain_id_arg, const fc::variant_object &user_data)
fetch_items_message(uint32_t item_type, const std::vector< item_hash_t > &items_to_fetch)
adds a signature to a transaction
static const core_message_type_enum type
static const core_message_type_enum type
static const core_message_type_enum type
static const core_message_type_enum type
Defines exception&#39;s used by fc.
static const core_message_type_enum type
bool operator==(const item_id &other) const
#define GRAPHENE_NET_PROTOCOL_VERSION
Definition: config.hpp:26
static const core_message_type_enum type
fc::enum_type< uint8_t, peer_connection_direction > direction
static const core_message_type_enum type
std::vector< current_connection_data > current_connections
connection_rejected_message(const std::string &user_agent, uint32_t core_protocol_version, const fc::ip::endpoint &remote_endpoint, rejection_reason_code reason_code, const std::string &reason_string)
static const core_message_type_enum type
static const core_message_type_enum type
fc::enum_type< uint8_t, firewalled_state > firewalled
fc::ripemd160 transaction_id_type
Definition: types.hpp:244
fc::time_point_sec last_seen_time
trx_message(graphene::protocol::signed_transaction transaction)
fc::enum_type< uint8_t, rejection_reason_code > reason_code
static const core_message_type_enum type