Dash Core  0.12.2.1
P2P Digital Currency
protocol.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef __cplusplus
7 #error This header can only be compiled as C++.
8 #endif
9 
10 #ifndef BITCOIN_PROTOCOL_H
11 #define BITCOIN_PROTOCOL_H
12 
13 #include "netaddress.h"
14 #include "serialize.h"
15 #include "uint256.h"
16 #include "version.h"
17 
18 #include <stdint.h>
19 #include <string>
20 
21 #define MESSAGE_START_SIZE 4
22 
30 {
31 public:
32  typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
33 
34  CMessageHeader(const MessageStartChars& pchMessageStartIn);
35  CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn);
36 
37  std::string GetCommand() const;
38  bool IsValid(const MessageStartChars& messageStart) const;
39 
41 
42  template <typename Stream, typename Operation>
43  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
44  {
49  }
50 
51  // TODO: make private (improves encapsulation)
52 public:
53  enum {
57 
61  };
64  uint32_t nMessageSize;
66 };
67 
72 namespace NetMsgType {
73 
79 extern const char *VERSION;
85 extern const char *VERACK;
91 extern const char *ADDR;
97 extern const char *INV;
102 extern const char *GETDATA;
109 extern const char *MERKLEBLOCK;
115 extern const char *GETBLOCKS;
122 extern const char *GETHEADERS;
127 extern const char *TX;
134 extern const char *HEADERS;
139 extern const char *BLOCK;
145 extern const char *GETADDR;
152 extern const char *MEMPOOL;
158 extern const char *PING;
165 extern const char *PONG;
172 extern const char *ALERT;
179 extern const char *NOTFOUND;
188 extern const char *FILTERLOAD;
197 extern const char *FILTERADD;
206 extern const char *FILTERCLEAR;
213 extern const char *REJECT;
220 extern const char *SENDHEADERS;
221 
222 // Dash message types
223 // NOTE: do NOT declare non-implmented here, we don't want them to be exposed to the outside
224 // TODO: add description
225 extern const char *TXLOCKREQUEST;
226 extern const char *TXLOCKVOTE;
227 extern const char *SPORK;
228 extern const char *GETSPORKS;
229 extern const char *MASTERNODEPAYMENTVOTE;
230 extern const char *MASTERNODEPAYMENTSYNC;
231 extern const char *MNANNOUNCE;
232 extern const char *MNPING;
233 extern const char *DSACCEPT;
234 extern const char *DSVIN;
235 extern const char *DSFINALTX;
236 extern const char *DSSIGNFINALTX;
237 extern const char *DSCOMPLETE;
238 extern const char *DSSTATUSUPDATE;
239 extern const char *DSTX;
240 extern const char *DSQUEUE;
241 extern const char *DSEG;
242 extern const char *SYNCSTATUSCOUNT;
243 extern const char *MNGOVERNANCESYNC;
244 extern const char *MNGOVERNANCEOBJECT;
245 extern const char *MNGOVERNANCEOBJECTVOTE;
246 extern const char *MNVERIFY;
247 };
248 
249 /* Get a vector of all valid message types (see above) */
250 const std::vector<std::string> &getAllNetMessageTypes();
251 
253 enum ServiceFlags : uint64_t {
254  // Nothing
256  // NODE_NETWORK means that the node is capable of serving the block chain. It is currently
257  // set by all Dash Core nodes, and is unset by SPV clients or other peers that just want
258  // network services but don't provide them.
259  NODE_NETWORK = (1 << 0),
260  // NODE_GETUTXO means the node is capable of responding to the getutxo protocol request.
261  // Dash Core does not support this but a patch set called Bitcoin XT does.
262  // See BIP 64 for details on how this is implemented.
263  NODE_GETUTXO = (1 << 1),
264  // NODE_BLOOM means the node is capable and willing to handle bloom-filtered connections.
265  // Dash Core nodes used to support this by default, without advertising this bit,
266  // but no longer do as of protocol version 70201 (= NO_BLOOM_VERSION)
267  NODE_BLOOM = (1 << 2),
268 
269  // Bits 24-31 are reserved for temporary experiments. Just pick a bit that
270  // isn't getting used, or one not being used much, and notify the
271  // bitcoin-development mailing list. Remember that service bits are just
272  // unauthenticated advertisements, so your code must be robust against
273  // collisions and other cases where nodes may be advertising a service they
274  // do not actually support. Other service bits should be allocated via the
275  // BIP process.
276 };
277 
279 class CAddress : public CService
280 {
281 public:
282  CAddress();
283  explicit CAddress(CService ipIn, ServiceFlags nServicesIn);
284 
285  void Init();
286 
288 
289  template <typename Stream, typename Operation>
290  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
291  {
292  if (ser_action.ForRead())
293  Init();
294  if (nType & SER_DISK)
295  READWRITE(nVersion);
296  if ((nType & SER_DISK) ||
297  (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
298  READWRITE(nTime);
299  uint64_t nServicesInt = nServices;
300  READWRITE(nServicesInt);
301  nServices = (ServiceFlags)nServicesInt;
302  READWRITE(*(CService*)this);
303  }
304 
305  // TODO: make private (improves encapsulation)
306 public:
308 
309  // disk and network only
310  unsigned int nTime;
311 };
312 
314 class CInv
315 {
316 public:
317  CInv();
318  CInv(int typeIn, const uint256& hashIn);
319  CInv(const std::string& strType, const uint256& hashIn);
320 
322 
323  template <typename Stream, typename Operation>
324  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
325  {
326  READWRITE(type);
327  READWRITE(hash);
328  }
329 
330  friend bool operator<(const CInv& a, const CInv& b);
331 
332  bool IsKnownType() const;
333  const char* GetCommand() const;
334  std::string ToString() const;
335 
336  // TODO: make private (improves encapsulation)
337 public:
338  int type;
340 };
341 
342 enum {
343  MSG_TX = 1,
345  // Nodes may always request a MSG_FILTERED_BLOCK in a getdata, however,
346  // MSG_FILTERED_BLOCK should not appear in any invs except as a part of getdata.
348  // Dash message types
349  // NOTE: declare non-implmented here, we must keep this enum consistent and backwards compatible
354  MSG_MASTERNODE_PAYMENT_BLOCK, // reusing, was MSG_MASTERNODE_SCANNING_ERROR previousely, was NOT used in 12.0
355  MSG_BUDGET_VOTE, // depreciated since 12.1
356  MSG_BUDGET_PROPOSAL, // depreciated since 12.1
357  MSG_BUDGET_FINALIZED, // depreciated since 12.1
358  MSG_BUDGET_FINALIZED_VOTE, // depreciated since 12.1
359  MSG_MASTERNODE_QUORUM, // not implemented
366 };
367 
368 #endif // BITCOIN_PROTOCOL_H
const char * MNPING
Definition: protocol.cpp:53
const char * ADDR
Definition: protocol.cpp:18
const char * VERACK
Definition: protocol.cpp:17
const char * DSACCEPT
Definition: protocol.cpp:54
ServiceFlags
Definition: protocol.h:253
const char * DSTX
Definition: protocol.cpp:60
#define READWRITE(obj)
Definition: serialize.h:175
const char * MASTERNODEPAYMENTVOTE
Definition: protocol.cpp:43
#define MESSAGE_START_SIZE
Definition: protocol.h:21
const char * DSQUEUE
Definition: protocol.cpp:61
char pchMessageStart[MESSAGE_START_SIZE]
Definition: protocol.h:62
const std::vector< std::string > & getAllNetMessageTypes()
Definition: protocol.cpp:275
uint256 hash
Definition: protocol.h:339
const char * NOTFOUND
Definition: protocol.cpp:32
const char * BLOCK
Definition: protocol.cpp:26
const char * INV
Definition: protocol.cpp:19
const char * DSFINALTX
Definition: protocol.cpp:56
const char * MEMPOOL
Definition: protocol.cpp:28
const char * TX
Definition: protocol.cpp:24
const char * SYNCSTATUSCOUNT
Definition: protocol.cpp:63
bool IsKnownType() const
Definition: protocol.cpp:254
const char * HEADERS
Definition: protocol.cpp:25
friend bool operator<(const CInv &a, const CInv &b)
Definition: protocol.cpp:249
bool IsValid(const MessageStartChars &messageStart) const
Definition: protocol.cpp:172
const char * FILTERLOAD
Definition: protocol.cpp:33
const char * MNVERIFY
Definition: protocol.cpp:67
const char * FILTERADD
Definition: protocol.cpp:34
#define FLATDATA(obj)
Definition: serialize.h:387
char pchCommand[COMMAND_SIZE]
Definition: protocol.h:63
uint32_t nMessageSize
Definition: protocol.h:64
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: protocol.h:324
const char * GETBLOCKS
Definition: protocol.cpp:22
const char * REJECT
Definition: protocol.cpp:36
const char * DSEG
Definition: protocol.cpp:62
const char * TXLOCKVOTE
Definition: protocol.cpp:40
const char * SENDHEADERS
Definition: protocol.cpp:37
const char * GetCommand() const
Definition: protocol.cpp:259
const char * MNGOVERNANCESYNC
Definition: protocol.cpp:64
CMessageHeader(const MessageStartChars &pchMessageStartIn)
Definition: protocol.cpp:150
const char * ALERT
Definition: protocol.cpp:31
std::string GetCommand() const
Definition: protocol.cpp:167
CInv()
Definition: protocol.cpp:221
const char * GETSPORKS
Definition: protocol.cpp:42
const char * GETDATA
Definition: protocol.cpp:20
const char * FILTERCLEAR
Definition: protocol.cpp:35
const char * PONG
Definition: protocol.cpp:30
ServiceFlags nServices
Definition: protocol.h:307
const char * MNGOVERNANCEOBJECT
Definition: protocol.cpp:65
const char * VERSION
Definition: protocol.cpp:16
const char * SPORK
Definition: protocol.cpp:41
const char * DSSIGNFINALTX
Definition: protocol.cpp:57
std::string ToString() const
Definition: protocol.cpp:266
const char * GETHEADERS
Definition: protocol.cpp:23
const char * TXLOCKREQUEST
Definition: protocol.cpp:39
const char * MNGOVERNANCEOBJECTVOTE
Definition: protocol.cpp:66
unsigned int nTime
Definition: protocol.h:310
const char * GETADDR
Definition: protocol.cpp:27
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:32
ADD_SERIALIZE_METHODS
Definition: protocol.h:287
const char * PING
Definition: protocol.cpp:29
static const int CADDR_TIME_VERSION
Definition: version.h:26
int type
Definition: protocol.h:338
Definition: protocol.h:314
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: protocol.h:43
const char * MERKLEBLOCK
Definition: protocol.cpp:21
const char * MASTERNODEPAYMENTSYNC
Definition: protocol.cpp:45
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: protocol.h:290
const char * DSVIN
Definition: protocol.cpp:55
const char * DSCOMPLETE
Definition: protocol.cpp:58
const char * DSSTATUSUPDATE
Definition: protocol.cpp:59
const char * MNANNOUNCE
Definition: protocol.cpp:52
void Init()
Definition: protocol.cpp:215
ADD_SERIALIZE_METHODS
Definition: protocol.h:321
uint8_t pchChecksum[CHECKSUM_SIZE]
Definition: protocol.h:65