Electroneum
cryptonote_protocol_defs.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2020, The Electroneum Project
2 // Copyrights(c) 2014-2019, 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 
39 namespace cryptonote
40 {
41 
42 
43 #define BC_COMMANDS_POOL_BASE 2000
44 
45  /************************************************************************/
46  /* P2P connection info, serializable to json */
47  /************************************************************************/
49  {
50  bool incoming;
51  bool localhost;
52  bool local_ip;
53  bool ssl;
54 
55  std::string address;
56  std::string host;
57  std::string ip;
58  std::string port;
59  uint16_t rpc_port;
60 
61  std::string peer_id;
62 
63  uint64_t recv_count;
64  uint64_t recv_idle_time;
65 
66  uint64_t send_count;
67  uint64_t send_idle_time;
68 
69  std::string state;
70 
71  uint64_t live_time;
72 
73  uint64_t avg_download;
74  uint64_t current_download;
75 
76  uint64_t avg_upload;
77  uint64_t current_upload;
78 
79  uint32_t support_flags;
80 
81  std::string connection_id;
82 
83  uint64_t height;
84 
85  uint32_t pruning_seed;
86 
87  BEGIN_KV_SERIALIZE_MAP()
88  KV_SERIALIZE(incoming)
89  KV_SERIALIZE(localhost)
90  KV_SERIALIZE(local_ip)
91  KV_SERIALIZE(address)
92  KV_SERIALIZE(host)
93  KV_SERIALIZE(ip)
94  KV_SERIALIZE(port)
95  KV_SERIALIZE(rpc_port)
96  KV_SERIALIZE(peer_id)
97  KV_SERIALIZE(recv_count)
98  KV_SERIALIZE(recv_idle_time)
99  KV_SERIALIZE(send_count)
100  KV_SERIALIZE(send_idle_time)
101  KV_SERIALIZE(state)
102  KV_SERIALIZE(live_time)
103  KV_SERIALIZE(avg_download)
104  KV_SERIALIZE(current_download)
105  KV_SERIALIZE(avg_upload)
106  KV_SERIALIZE(current_upload)
107  KV_SERIALIZE(support_flags)
108  KV_SERIALIZE(connection_id)
109  KV_SERIALIZE(height)
110  KV_SERIALIZE(pruning_seed)
111  END_KV_SERIALIZE_MAP()
112  };
113 
114  /************************************************************************/
115  /* */
116  /************************************************************************/
118  {
120  std::vector<blobdata> txs;
121  BEGIN_KV_SERIALIZE_MAP()
122  KV_SERIALIZE(block)
123  KV_SERIALIZE(txs)
124  END_KV_SERIALIZE_MAP()
125  };
126 
127 
128  /************************************************************************/
129  /* */
130  /************************************************************************/
132  {
133  const static int ID = BC_COMMANDS_POOL_BASE + 1;
134 
135  struct request_t
136  {
139 
140  BEGIN_KV_SERIALIZE_MAP()
141  KV_SERIALIZE(b)
142  KV_SERIALIZE(current_blockchain_height)
143  END_KV_SERIALIZE_MAP()
144  };
145  typedef epee::misc_utils::struct_init<request_t> request;
146  };
147 
148  /************************************************************************/
149  /* */
150  /************************************************************************/
152  {
153  const static int ID = BC_COMMANDS_POOL_BASE + 2;
154 
155  struct request_t
156  {
157  std::vector<blobdata> txs;
158  std::string _; // padding
159 
160  BEGIN_KV_SERIALIZE_MAP()
161  KV_SERIALIZE(txs)
162  KV_SERIALIZE(_)
163  END_KV_SERIALIZE_MAP()
164  };
165  typedef epee::misc_utils::struct_init<request_t> request;
166  };
167  /************************************************************************/
168  /* */
169  /************************************************************************/
171  {
172  const static int ID = BC_COMMANDS_POOL_BASE + 3;
173 
174  struct request_t
175  {
176  std::vector<crypto::hash> txs;
177  std::vector<crypto::hash> blocks;
178 
179  BEGIN_KV_SERIALIZE_MAP()
180  KV_SERIALIZE_CONTAINER_POD_AS_BLOB(txs)
181  KV_SERIALIZE_CONTAINER_POD_AS_BLOB(blocks)
182  END_KV_SERIALIZE_MAP()
183  };
184  typedef epee::misc_utils::struct_init<request_t> request;
185  };
186 
188  {
189  const static int ID = BC_COMMANDS_POOL_BASE + 4;
190 
191  struct request_t
192  {
193  std::vector<blobdata> txs;
194  std::vector<block_complete_entry> blocks;
195  std::vector<crypto::hash> missed_ids;
197 
198  BEGIN_KV_SERIALIZE_MAP()
199  KV_SERIALIZE(txs)
200  KV_SERIALIZE(blocks)
201  KV_SERIALIZE_CONTAINER_POD_AS_BLOB(missed_ids)
202  KV_SERIALIZE(current_blockchain_height)
203  END_KV_SERIALIZE_MAP()
204  };
205  typedef epee::misc_utils::struct_init<request_t> request;
206  };
207 
208 
210  {
211  uint64_t current_height;
215  uint8_t top_version;
216  uint32_t pruning_seed;
217 
218  BEGIN_KV_SERIALIZE_MAP()
219  KV_SERIALIZE(current_height)
220  KV_SERIALIZE(cumulative_difficulty)
221  KV_SERIALIZE(cumulative_difficulty_top64)
222  KV_SERIALIZE_VAL_POD_AS_BLOB(top_id)
223  KV_SERIALIZE_OPT(top_version, (uint8_t)0)
224  KV_SERIALIZE_OPT(pruning_seed, (uint32_t)0)
225  END_KV_SERIALIZE_MAP()
226  };
227 
229  {
230  const static int ID = BC_COMMANDS_POOL_BASE + 6;
231 
232  struct request_t
233  {
234  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 */
235 
236  BEGIN_KV_SERIALIZE_MAP()
237  KV_SERIALIZE_CONTAINER_POD_AS_BLOB(block_ids)
238  END_KV_SERIALIZE_MAP()
239  };
240  typedef epee::misc_utils::struct_init<request_t> request;
241  };
242 
244  {
245  const static int ID = BC_COMMANDS_POOL_BASE + 7;
246 
247  struct request_t
248  {
249  uint64_t start_height;
250  uint64_t total_height;
253  std::vector<crypto::hash> m_block_ids;
254 
255  BEGIN_KV_SERIALIZE_MAP()
256  KV_SERIALIZE(start_height)
257  KV_SERIALIZE(total_height)
258  KV_SERIALIZE(cumulative_difficulty)
259  KV_SERIALIZE(cumulative_difficulty_top64)
260  KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_block_ids)
261  END_KV_SERIALIZE_MAP()
262  };
263  typedef epee::misc_utils::struct_init<request_t> request;
264  };
265 
266  /************************************************************************/
267  /* */
268  /************************************************************************/
270  {
271  const static int ID = BC_COMMANDS_POOL_BASE + 8;
272 
273  struct request_t
274  {
277 
278  BEGIN_KV_SERIALIZE_MAP()
279  KV_SERIALIZE(b)
280  KV_SERIALIZE(current_blockchain_height)
281  END_KV_SERIALIZE_MAP()
282  };
283  typedef epee::misc_utils::struct_init<request_t> request;
284  };
285 
286  /************************************************************************/
287  /* */
288  /************************************************************************/
290  {
291  const static int ID = BC_COMMANDS_POOL_BASE + 9;
292 
293  struct request_t
294  {
297  std::vector<uint64_t> missing_tx_indices;
298 
299  BEGIN_KV_SERIALIZE_MAP()
300  KV_SERIALIZE_VAL_POD_AS_BLOB(block_hash)
301  KV_SERIALIZE(current_blockchain_height)
302  KV_SERIALIZE_CONTAINER_POD_AS_BLOB(missing_tx_indices)
303  END_KV_SERIALIZE_MAP()
304  };
305  typedef epee::misc_utils::struct_init<request_t> request;
306  };
307 
308  /************************************************************************/
309  /* */
310  /************************************************************************/
312  {
313  const static int ID = BC_COMMANDS_POOL_BASE + 10;
314 
315  struct request_t
316  {
317  BEGIN_KV_SERIALIZE_MAP()
318  END_KV_SERIALIZE_MAP()
319  };
320  typedef epee::misc_utils::struct_init<request_t> request;
321 
322  struct response_t
323  {
324  std::string serialized_v_list;
325 
326  BEGIN_KV_SERIALIZE_MAP()
327  KV_SERIALIZE(serialized_v_list)
328  END_KV_SERIALIZE_MAP()
329  };
330  typedef epee::misc_utils::struct_init<response_t> response;
331 
332  BEGIN_KV_SERIALIZE_MAP()
333  END_KV_SERIALIZE_MAP()
334  };
335 
336  /************************************************************************/
337  /* */
338  /************************************************************************/
339 
341  {
342  const static int ID = BC_COMMANDS_POOL_BASE + 11;
343 
344  struct request_t
345  {
346  std::string serialized_v_list;
347 
348  BEGIN_KV_SERIALIZE_MAP()
349  KV_SERIALIZE(serialized_v_list)
350  END_KV_SERIALIZE_MAP()
351  };
352  typedef epee::misc_utils::struct_init<request_t> request;
353  };
354 }
#define BC_COMMANDS_POOL_BASE
Definition: cryptonote_protocol_defs.h:43
int b
Definition: base.py:1
Definition: blocks.cpp:13
POD_CLASS hash
Definition: hash.h:50
Holds cryptonote related classes and helpers.
Definition: db_bdb.cpp:226
std::string blobdata
Definition: blobdatatype.h:39
Definition: cryptonote_format_utils.h:44
Definition: cryptonote_protocol_defs.h:210
uint64_t cumulative_difficulty_top64
Definition: cryptonote_protocol_defs.h:213
uint32_t pruning_seed
Definition: cryptonote_protocol_defs.h:216
uint64_t cumulative_difficulty
Definition: cryptonote_protocol_defs.h:212
uint8_t top_version
Definition: cryptonote_protocol_defs.h:215
uint64_t current_height
Definition: cryptonote_protocol_defs.h:211
crypto::hash top_id
Definition: cryptonote_protocol_defs.h:214
Definition: cryptonote_protocol_defs.h:345
std::string serialized_v_list
Definition: cryptonote_protocol_defs.h:346
Definition: cryptonote_protocol_defs.h:341
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:352
Definition: cryptonote_protocol_defs.h:136
uint64_t current_blockchain_height
Definition: cryptonote_protocol_defs.h:138
block_complete_entry b
Definition: cryptonote_protocol_defs.h:137
Definition: cryptonote_protocol_defs.h:132
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:145
Definition: cryptonote_protocol_defs.h:274
uint64_t current_blockchain_height
Definition: cryptonote_protocol_defs.h:276
block_complete_entry b
Definition: cryptonote_protocol_defs.h:275
Definition: cryptonote_protocol_defs.h:270
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:283
Definition: cryptonote_protocol_defs.h:156
std::string _
Definition: cryptonote_protocol_defs.h:158
std::vector< blobdata > txs
Definition: cryptonote_protocol_defs.h:157
Definition: cryptonote_protocol_defs.h:152
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:165
Definition: cryptonote_protocol_defs.h:233
std::list< crypto::hash > block_ids
Definition: cryptonote_protocol_defs.h:234
Definition: cryptonote_protocol_defs.h:229
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:240
Definition: cryptonote_protocol_defs.h:294
uint64_t current_blockchain_height
Definition: cryptonote_protocol_defs.h:296
std::vector< uint64_t > missing_tx_indices
Definition: cryptonote_protocol_defs.h:297
crypto::hash block_hash
Definition: cryptonote_protocol_defs.h:295
Definition: cryptonote_protocol_defs.h:290
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:305
Definition: cryptonote_protocol_defs.h:175
std::vector< crypto::hash > txs
Definition: cryptonote_protocol_defs.h:176
std::vector< crypto::hash > blocks
Definition: cryptonote_protocol_defs.h:177
Definition: cryptonote_protocol_defs.h:171
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:184
Definition: cryptonote_protocol_defs.h:316
Definition: cryptonote_protocol_defs.h:323
std::string serialized_v_list
Definition: cryptonote_protocol_defs.h:324
Definition: cryptonote_protocol_defs.h:312
epee::misc_utils::struct_init< response_t > response
Definition: cryptonote_protocol_defs.h:330
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:320
Definition: cryptonote_protocol_defs.h:248
uint64_t total_height
Definition: cryptonote_protocol_defs.h:250
uint64_t cumulative_difficulty_top64
Definition: cryptonote_protocol_defs.h:252
uint64_t cumulative_difficulty
Definition: cryptonote_protocol_defs.h:251
std::vector< crypto::hash > m_block_ids
Definition: cryptonote_protocol_defs.h:253
uint64_t start_height
Definition: cryptonote_protocol_defs.h:249
Definition: cryptonote_protocol_defs.h:244
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:263
Definition: cryptonote_protocol_defs.h:192
std::vector< blobdata > txs
Definition: cryptonote_protocol_defs.h:193
std::vector< block_complete_entry > blocks
Definition: cryptonote_protocol_defs.h:194
std::vector< crypto::hash > missed_ids
Definition: cryptonote_protocol_defs.h:195
uint64_t current_blockchain_height
Definition: cryptonote_protocol_defs.h:196
Definition: cryptonote_protocol_defs.h:188
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:205
Definition: cryptonote_protocol_defs.h:118
std::vector< blobdata > txs
Definition: cryptonote_protocol_defs.h:120
blobdata block
Definition: cryptonote_protocol_defs.h:119
Definition: cryptonote_basic.h:410
Definition: cryptonote_protocol_defs.h:49
std::string connection_id
Definition: cryptonote_protocol_defs.h:81
uint32_t pruning_seed
Definition: cryptonote_protocol_defs.h:85
std::string address
Definition: cryptonote_protocol_defs.h:55
uint64_t recv_count
Definition: cryptonote_protocol_defs.h:63
uint64_t live_time
Definition: cryptonote_protocol_defs.h:71
uint32_t support_flags
Definition: cryptonote_protocol_defs.h:79
bool localhost
Definition: cryptonote_protocol_defs.h:51
std::string port
Definition: cryptonote_protocol_defs.h:58
uint64_t height
Definition: cryptonote_protocol_defs.h:83
uint64_t send_idle_time
Definition: cryptonote_protocol_defs.h:67
std::string host
Definition: cryptonote_protocol_defs.h:56
std::string ip
Definition: cryptonote_protocol_defs.h:57
uint64_t current_download
Definition: cryptonote_protocol_defs.h:74
uint64_t avg_download
Definition: cryptonote_protocol_defs.h:73
uint64_t recv_idle_time
Definition: cryptonote_protocol_defs.h:64
uint16_t rpc_port
Definition: cryptonote_protocol_defs.h:59
uint64_t send_count
Definition: cryptonote_protocol_defs.h:66
std::string state
Definition: cryptonote_protocol_defs.h:69
bool local_ip
Definition: cryptonote_protocol_defs.h:52
bool ssl
Definition: cryptonote_protocol_defs.h:53
bool incoming
Definition: cryptonote_protocol_defs.h:50
std::string peer_id
Definition: cryptonote_protocol_defs.h:61
uint64_t current_upload
Definition: cryptonote_protocol_defs.h:77
uint64_t avg_upload
Definition: cryptonote_protocol_defs.h:76
Definition: blake256.h:37