Electroneum
cryptonote_protocol_defs.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2019, The Electroneum Project
2 // Copyrights(c) 2014-2017, The Monero Project
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are
7 // permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this list of
10 // conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 // of conditions and the following disclaimer in the documentation and/or other
14 // materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its contributors may be
17 // used to endorse or promote products derived from this software without specific
18 // prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31 
32 #pragma once
33 
34 #include <list>
35 #include "serialization/keyvalue_serialization.h"
38 namespace cryptonote
39 {
40 
41 
42 #define BC_COMMANDS_POOL_BASE 2000
43 
44  /************************************************************************/
45  /* P2P connection info, serializable to json */
46  /************************************************************************/
48  {
49  bool incoming;
50  bool localhost;
51  bool local_ip;
52 
53  std::string address;
54  std::string host;
55  std::string ip;
56  std::string port;
57 
58  std::string peer_id;
59 
60  uint64_t recv_count;
61  uint64_t recv_idle_time;
62 
63  uint64_t send_count;
64  uint64_t send_idle_time;
65 
66  std::string state;
67 
68  uint64_t live_time;
69 
70  uint64_t avg_download;
71  uint64_t current_download;
72 
73  uint64_t avg_upload;
74  uint64_t current_upload;
75 
76  uint32_t support_flags;
77 
79 
80  uint64_t height;
81 
82  BEGIN_KV_SERIALIZE_MAP()
83  KV_SERIALIZE(incoming)
84  KV_SERIALIZE(localhost)
85  KV_SERIALIZE(local_ip)
86  KV_SERIALIZE(address)
87  KV_SERIALIZE(host)
88  KV_SERIALIZE(ip)
89  KV_SERIALIZE(port)
90  KV_SERIALIZE(peer_id)
91  KV_SERIALIZE(recv_count)
92  KV_SERIALIZE(recv_idle_time)
93  KV_SERIALIZE(send_count)
94  KV_SERIALIZE(send_idle_time)
95  KV_SERIALIZE(state)
96  KV_SERIALIZE(live_time)
97  KV_SERIALIZE(avg_download)
98  KV_SERIALIZE(current_download)
99  KV_SERIALIZE(avg_upload)
100  KV_SERIALIZE(current_upload)
101  KV_SERIALIZE(support_flags)
102  KV_SERIALIZE_VAL_POD_AS_BLOB(connection_id)
103  KV_SERIALIZE(height)
104  END_KV_SERIALIZE_MAP()
105  };
106 
107  /************************************************************************/
108  /* */
109  /************************************************************************/
111  {
113  std::list<blobdata> txs;
114  BEGIN_KV_SERIALIZE_MAP()
115  KV_SERIALIZE(block)
116  KV_SERIALIZE(txs)
117  END_KV_SERIALIZE_MAP()
118  };
119 
120 
121  /************************************************************************/
122  /* */
123  /************************************************************************/
125  {
126  const static int ID = BC_COMMANDS_POOL_BASE + 1;
127 
128  struct request
129  {
132  uint32_t hop;
133 
134  BEGIN_KV_SERIALIZE_MAP()
135  KV_SERIALIZE(b)
136  KV_SERIALIZE(current_blockchain_height)
137  KV_SERIALIZE(hop)
138  END_KV_SERIALIZE_MAP()
139  };
140  };
141 
142  /************************************************************************/
143  /* */
144  /************************************************************************/
146  {
147  const static int ID = BC_COMMANDS_POOL_BASE + 2;
148 
149  struct request
150  {
151  std::list<blobdata> txs;
152 
153  BEGIN_KV_SERIALIZE_MAP()
154  KV_SERIALIZE(txs)
155  END_KV_SERIALIZE_MAP()
156  };
157  };
158  /************************************************************************/
159  /* */
160  /************************************************************************/
162  {
163  const static int ID = BC_COMMANDS_POOL_BASE + 3;
164 
165  struct request
166  {
167  std::list<crypto::hash> txs;
168  std::list<crypto::hash> blocks;
169 
170  BEGIN_KV_SERIALIZE_MAP()
171  KV_SERIALIZE_CONTAINER_POD_AS_BLOB(txs)
172  KV_SERIALIZE_CONTAINER_POD_AS_BLOB(blocks)
173  END_KV_SERIALIZE_MAP()
174  };
175  };
176 
178  {
179  const static int ID = BC_COMMANDS_POOL_BASE + 4;
180 
181  struct request
182  {
183  std::list<blobdata> txs;
184  std::list<block_complete_entry> blocks;
185  std::list<crypto::hash> missed_ids;
187 
188  BEGIN_KV_SERIALIZE_MAP()
189  KV_SERIALIZE(txs)
190  KV_SERIALIZE(blocks)
191  KV_SERIALIZE_CONTAINER_POD_AS_BLOB(missed_ids)
192  KV_SERIALIZE(current_blockchain_height)
193  END_KV_SERIALIZE_MAP()
194  };
195  };
196 
197 
199  {
200  uint64_t current_height;
203  uint8_t top_version;
204 
205  BEGIN_KV_SERIALIZE_MAP()
206  KV_SERIALIZE(current_height)
207  KV_SERIALIZE(cumulative_difficulty)
208  KV_SERIALIZE_VAL_POD_AS_BLOB(top_id)
209  KV_SERIALIZE_OPT(top_version, (uint8_t)0)
210  END_KV_SERIALIZE_MAP()
211  };
212 
214  {
215  const static int ID = BC_COMMANDS_POOL_BASE + 6;
216 
217  struct request
218  {
219  std::list<crypto::hash> block_ids; /*IDs of the first 10 blocks are sequential, next goes with pow(2,n) offset, like 2, 4, 8, 16, 32, 64 and so on, and the last one is always genesis block */
220 
221  BEGIN_KV_SERIALIZE_MAP()
222  KV_SERIALIZE_CONTAINER_POD_AS_BLOB(block_ids)
223  END_KV_SERIALIZE_MAP()
224  };
225  };
226 
228  {
229  const static int ID = BC_COMMANDS_POOL_BASE + 7;
230 
231  struct request
232  {
233  uint64_t start_height;
234  uint64_t total_height;
236  std::list<crypto::hash> m_block_ids;
237 
238  BEGIN_KV_SERIALIZE_MAP()
239  KV_SERIALIZE(start_height)
240  KV_SERIALIZE(total_height)
241  KV_SERIALIZE(cumulative_difficulty)
242  KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_block_ids)
243  END_KV_SERIALIZE_MAP()
244  };
245  };
246 
247  /************************************************************************/
248  /* */
249  /************************************************************************/
251  {
252  const static int ID = BC_COMMANDS_POOL_BASE + 8;
253 
254  struct request
255  {
258  uint32_t hop;
259 
260  BEGIN_KV_SERIALIZE_MAP()
261  KV_SERIALIZE(b)
262  KV_SERIALIZE(current_blockchain_height)
263  KV_SERIALIZE(hop)
264  END_KV_SERIALIZE_MAP()
265  };
266  };
267 
268  /************************************************************************/
269  /* */
270  /************************************************************************/
272  {
273  const static int ID = BC_COMMANDS_POOL_BASE + 9;
274 
275  struct request
276  {
279  std::vector<size_t> missing_tx_indices;
280  uint32_t hop;
281 
282  BEGIN_KV_SERIALIZE_MAP()
283  KV_SERIALIZE_VAL_POD_AS_BLOB(block_hash)
284  KV_SERIALIZE(current_blockchain_height)
285  KV_SERIALIZE_CONTAINER_POD_AS_BLOB(missing_tx_indices)
286  KV_SERIALIZE(hop)
287  END_KV_SERIALIZE_MAP()
288  };
289  };
290 
291  /************************************************************************/
292  /* */
293  /************************************************************************/
295  {
296  const static int ID = BC_COMMANDS_POOL_BASE + 10;
297 
298  struct request
299  {
300  BEGIN_KV_SERIALIZE_MAP()
301  END_KV_SERIALIZE_MAP()
302  };
303 
304  struct response
305  {
306  std::string serialized_v_list;
307 
308  BEGIN_KV_SERIALIZE_MAP()
309  KV_SERIALIZE(serialized_v_list)
310  END_KV_SERIALIZE_MAP()
311  };
312 
313  BEGIN_KV_SERIALIZE_MAP()
314  END_KV_SERIALIZE_MAP()
315  };
316 
317  /************************************************************************/
318  /* */
319  /************************************************************************/
320 
322  {
323  const static int ID = BC_COMMANDS_POOL_BASE + 11;
324 
325  struct request
326  {
327  std::string serialized_v_list;
328 
329  BEGIN_KV_SERIALIZE_MAP()
330  KV_SERIALIZE(serialized_v_list)
331  END_KV_SERIALIZE_MAP()
332  };
333  };
334 }
Definition: cryptonote_protocol_defs.h:165
uint64_t current_blockchain_height
Definition: cryptonote_protocol_defs.h:257
boost::uuids::uuid connection_id
Definition: cryptonote_protocol_defs.h:78
uint32_t hop
Definition: cryptonote_protocol_defs.h:280
Definition: cryptonote_protocol_defs.h:304
std::string serialized_v_list
Definition: cryptonote_protocol_defs.h:327
std::list< crypto::hash > missed_ids
Definition: cryptonote_protocol_defs.h:185
std::string peer_id
Definition: cryptonote_protocol_defs.h:58
uint64_t avg_download
Definition: cryptonote_protocol_defs.h:70
#define BC_COMMANDS_POOL_BASE
Definition: cryptonote_protocol_defs.h:42
uint64_t send_idle_time
Definition: cryptonote_protocol_defs.h:64
uint64_t avg_upload
Definition: cryptonote_protocol_defs.h:73
boost::uuids::uuid uuid
Definition: net_node_common.h:41
uint64_t current_upload
Definition: cryptonote_protocol_defs.h:74
Definition: cryptonote_protocol_defs.h:110
Definition: cryptonote_basic.h:382
std::list< crypto::hash > m_block_ids
Definition: cryptonote_protocol_defs.h:236
Definition: cryptonote_protocol_defs.h:298
std::list< crypto::hash > block_ids
Definition: cryptonote_protocol_defs.h:219
uint64_t recv_count
Definition: cryptonote_protocol_defs.h:60
Definition: cryptonote_protocol_defs.h:47
Definition: cryptonote_protocol_defs.h:227
uint64_t cumulative_difficulty
Definition: cryptonote_protocol_defs.h:201
Definition: cryptonote_protocol_defs.h:145
std::list< blobdata > txs
Definition: cryptonote_protocol_defs.h:113
block_complete_entry b
Definition: cryptonote_protocol_defs.h:130
std::string state
Definition: cryptonote_protocol_defs.h:66
uint64_t current_download
Definition: cryptonote_protocol_defs.h:71
Definition: cryptonote_protocol_defs.h:275
Definition: cryptonote_protocol_defs.h:254
std::list< crypto::hash > txs
Definition: cryptonote_protocol_defs.h:167
Holds cryptonote related classes and helpers.
Definition: db_bdb.cpp:225
uint64_t recv_idle_time
Definition: cryptonote_protocol_defs.h:61
uint64_t cumulative_difficulty
Definition: cryptonote_protocol_defs.h:235
uint64_t live_time
Definition: cryptonote_protocol_defs.h:68
uint32_t support_flags
Definition: cryptonote_protocol_defs.h:76
std::string ip
Definition: cryptonote_protocol_defs.h:55
bool localhost
Definition: cryptonote_protocol_defs.h:50
Definition: cryptonote_protocol_defs.h:177
std::string port
Definition: cryptonote_protocol_defs.h:56
Definition: cryptonote_protocol_defs.h:250
Definition: cryptonote_protocol_defs.h:181
int b
Definition: base.py:1
std::string serialized_v_list
Definition: cryptonote_protocol_defs.h:306
Definition: cryptonote_protocol_defs.h:124
std::string host
Definition: cryptonote_protocol_defs.h:54
blobdata block
Definition: cryptonote_protocol_defs.h:112
uint32_t hop
Definition: cryptonote_protocol_defs.h:132
Definition: cryptonote_protocol_defs.h:128
uint64_t current_blockchain_height
Definition: cryptonote_protocol_defs.h:278
uint64_t height
Definition: cryptonote_protocol_defs.h:80
std::list< block_complete_entry > blocks
Definition: cryptonote_protocol_defs.h:184
Definition: cryptonote_protocol_defs.h:213
bool local_ip
Definition: cryptonote_protocol_defs.h:51
Definition: cryptonote_protocol_defs.h:198
std::string blobdata
Definition: blobdatatype.h:36
#define blocks
Definition: sha512-hash.c:11
Definition: blake256.h:37
bool incoming
Definition: cryptonote_protocol_defs.h:49
uint64_t send_count
Definition: cryptonote_protocol_defs.h:63
Definition: cryptonote_protocol_defs.h:325
uint64_t total_height
Definition: cryptonote_protocol_defs.h:234
Definition: cryptonote_protocol_defs.h:231
uint64_t current_blockchain_height
Definition: cryptonote_protocol_defs.h:131
Definition: cryptonote_protocol_defs.h:294
crypto::hash block_hash
Definition: cryptonote_protocol_defs.h:277
uint64_t current_blockchain_height
Definition: cryptonote_protocol_defs.h:186
std::list< blobdata > txs
Definition: cryptonote_protocol_defs.h:183
POD_CLASS hash
Definition: hash.h:46
Definition: cryptonote_protocol_defs.h:161
Definition: cryptonote_protocol_defs.h:271
uint32_t hop
Definition: cryptonote_protocol_defs.h:258
Definition: cryptonote_protocol_defs.h:149
crypto::hash top_id
Definition: cryptonote_protocol_defs.h:202
uint64_t current_height
Definition: cryptonote_protocol_defs.h:200
block_complete_entry b
Definition: cryptonote_protocol_defs.h:256
Definition: cryptonote_protocol_defs.h:321
Definition: cryptonote_protocol_defs.h:217
uint64_t start_height
Definition: cryptonote_protocol_defs.h:233
std::list< crypto::hash > blocks
Definition: cryptonote_protocol_defs.h:168
std::string address
Definition: cryptonote_protocol_defs.h:53
std::vector< size_t > missing_tx_indices
Definition: cryptonote_protocol_defs.h:279
std::list< blobdata > txs
Definition: cryptonote_protocol_defs.h:151
uint8_t top_version
Definition: cryptonote_protocol_defs.h:203