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