Fabcoin Core  0.16.2
P2P Digital Currency
protocol.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 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 FABCOIN_PROTOCOL_H
11 #define FABCOIN_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 
28 {
29 public:
30  enum {
35 
38  HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE
39  };
40  typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
41 
42  CMessageHeader(const MessageStartChars& pchMessageStartIn);
43  CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn);
44 
45  std::string GetCommand() const;
46  bool IsValid(const MessageStartChars& messageStart) const;
47 
49 
50  template <typename Stream, typename Operation>
51  inline void SerializationOp(Stream& s, Operation ser_action)
52  {
57  }
58 
61  uint32_t nMessageSize;
63 };
64 
69 namespace NetMsgType {
70 
76 extern const char *VERSION;
82 extern const char *VERACK;
88 extern const char *ADDR;
94 extern const char *INV;
99 extern const char *GETDATA;
106 extern const char *MERKLEBLOCK;
112 extern const char *GETBLOCKS;
119 extern const char *GETHEADERS;
124 extern const char *TX;
131 extern const char *HEADERS;
136 extern const char *BLOCK;
142 extern const char *GETADDR;
149 extern const char *MEMPOOL;
155 extern const char *PING;
162 extern const char *PONG;
169 extern const char *NOTFOUND;
178 extern const char *FILTERLOAD;
187 extern const char *FILTERADD;
196 extern const char *FILTERCLEAR;
203 extern const char *REJECT;
210 extern const char *SENDHEADERS;
216 extern const char *FEEFILTER;
224 extern const char *SENDCMPCT;
230 extern const char *CMPCTBLOCK;
236 extern const char *GETBLOCKTXN;
242 extern const char *BLOCKTXN;
243 };
244 
245 /* Get a vector of all valid message types (see above) */
246 const std::vector<std::string> &getAllNetMessageTypes();
247 
249 enum ServiceFlags : uint64_t {
250  // Nothing
252  // NODE_NETWORK means that the node is capable of serving the block chain. It is currently
253  // set by all Fabcoin Core nodes, and is unset by SPV clients or other peers that just want
254  // network services but don't provide them.
255  NODE_NETWORK = (1 << 0),
256  // NODE_GETUTXO means the node is capable of responding to the getutxo protocol request.
257  // Fabcoin Core does not support this but a patch set called Fabcoin XT does.
258  // See BIP 64 for details on how this is implemented.
259  NODE_GETUTXO = (1 << 1),
260  // NODE_BLOOM means the node is capable and willing to handle bloom-filtered connections.
261  // Fabcoin Core nodes used to support this by default, without advertising this bit,
262  // but no longer do as of protocol version 70011 (= NO_BLOOM_VERSION)
263  NODE_BLOOM = (1 << 2),
264  // NODE_WITNESS indicates that a node can be asked for blocks and transactions including
265  // witness data.
266  NODE_WITNESS = (1 << 3),
267  // NODE_XTHIN means the node supports Xtreme Thinblocks
268  // If this is turned off then the node will not service nor make xthin requests
269  NODE_XTHIN = (1 << 4),
270 
271  // Bits 24-31 are reserved for temporary experiments. Just pick a bit that
272  // isn't getting used, or one not being used much, and notify the
273  // fabcoin-development mailing list. Remember that service bits are just
274  // unauthenticated advertisements, so your code must be robust against
275  // collisions and other cases where nodes may be advertising a service they
276  // do not actually support. Other service bits should be allocated via the
277  // BIP process.
278 };
279 
281 class CAddress : public CService
282 {
283 public:
284  CAddress();
285  explicit CAddress(CService ipIn, ServiceFlags nServicesIn);
286 
287  void Init();
288 
290 
291  template <typename Stream, typename Operation>
292  inline void SerializationOp(Stream& s, Operation ser_action)
293  {
294  if (ser_action.ForRead())
295  Init();
296  int nVersion = s.GetVersion();
297  if (s.GetType() & SER_DISK)
298  READWRITE(nVersion);
299  if ((s.GetType() & SER_DISK) ||
300  (nVersion >= CADDR_TIME_VERSION && !(s.GetType() & SER_GETHASH)))
301  READWRITE(nTime);
302  uint64_t nServicesInt = nServices;
303  READWRITE(nServicesInt);
304  nServices = (ServiceFlags)nServicesInt;
305  READWRITE(*(CService*)this);
306  }
307 
308  // TODO: make private (improves encapsulation)
309 public:
311 
312  // disk and network only
313  unsigned int nTime;
314 };
315 
317 const uint32_t MSG_WITNESS_FLAG = 1 << 30;
318 const uint32_t MSG_TYPE_MASK = 0xffffffff >> 2;
319 
325 {
327  MSG_TX = 1,
329  // The following can only occur in getdata. Invs always use TX or BLOCK.
335 };
336 
338 class CInv
339 {
340 public:
341  CInv();
342  CInv(int typeIn, const uint256& hashIn);
343 
345 
346  template <typename Stream, typename Operation>
347  inline void SerializationOp(Stream& s, Operation ser_action)
348  {
349  READWRITE(type);
350  READWRITE(hash);
351  }
352 
353  friend bool operator<(const CInv& a, const CInv& b);
354 
355  std::string GetCommand() const;
356  std::string ToString() const;
357 
358  // TODO: make private (improves encapsulation)
359 public:
360  int type;
362 };
363 
364 #endif // FABCOIN_PROTOCOL_H
const char * PING
The ping message is sent periodically to help confirm that the receiving peer is still connected...
Definition: protocol.cpp:29
const char * FILTERLOAD
The filterload message tells the receiving peer to filter all relayed transactions and requested merk...
Definition: protocol.cpp:32
const char * MERKLEBLOCK
The merkleblock message is a reply to a getdata message which requested a block using the inventory t...
Definition: protocol.cpp:21
uint8_t pchChecksum[CHECKSUM_SIZE]
Definition: protocol.h:62
const char * BLOCKTXN
Contains a BlockTransactions.
Definition: protocol.cpp:41
ServiceFlags
nServices flags
Definition: protocol.h:249
#define READWRITE(obj)
Definition: serialize.h:179
Defined in BIP144.
Definition: protocol.h:333
const std::vector< std::string > & getAllNetMessageTypes()
Definition: protocol.cpp:187
const char * GETADDR
The getaddr message requests an addr message from the receiving node, preferably one with lots of IP ...
Definition: protocol.cpp:27
Defined in BIP152.
Definition: protocol.h:331
inv message data
Definition: protocol.h:338
const char * SENDCMPCT
Contains a 1-byte bool and 8-byte LE version number.
Definition: protocol.cpp:38
char pchCommand[COMMAND_SIZE]
Definition: protocol.h:60
void SerializationOp(Stream &s, Operation ser_action)
Definition: protocol.h:292
Defined in BIP144.
Definition: protocol.h:332
ADD_SERIALIZE_METHODS
Definition: protocol.h:289
CMessageHeader(const MessageStartChars &pchMessageStartIn)
Definition: protocol.cpp:77
void SerializationOp(Stream &s, Operation ser_action)
Definition: protocol.h:51
GetDataMsg
getdata / inv message types.
Definition: protocol.h:324
const uint32_t MSG_WITNESS_FLAG
getdata message type flags
Definition: protocol.h:317
uint32_t nMessageSize
Definition: protocol.h:61
const uint32_t MSG_TYPE_MASK
Definition: protocol.h:318
const char * PONG
The pong message replies to a ping message, proving to the pinging node that the ponging node is stil...
Definition: protocol.cpp:30
bool IsValid(const MessageStartChars &messageStart) const
Definition: protocol.cpp:99
#define FLATDATA(obj)
Definition: serialize.h:388
const char * HEADERS
The headers message sends one or more block headers to a node which previously requested certain head...
Definition: protocol.cpp:25
const char * INV
The inv message (inventory message) transmits one or more inventories of objects known to the transmi...
Definition: protocol.cpp:19
#define a(i)
const char * GETHEADERS
The getheaders message requests a headers message that provides block headers starting from a particu...
Definition: protocol.cpp:23
Fabcoin protocol message types.
Definition: protocol.cpp:15
int type
Definition: protocol.h:360
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:140
Removed for reorganization.
const char * SENDHEADERS
Indicates that a node prefers to receive new block announcements via a "headers" message rather than ...
Definition: protocol.cpp:36
const char * MEMPOOL
The mempool message requests the TXIDs of transactions that the receiving node has verified as valid ...
Definition: protocol.cpp:28
A CService with information about it as peer.
Definition: protocol.h:281
uint256 hash
Definition: protocol.h:361
const char * ADDR
The addr (IP address) message relays connection information for peers on the network.
Definition: protocol.cpp:18
const char * FILTERCLEAR
The filterclear message tells the receiving peer to remove a previously-set bloom filter...
Definition: protocol.cpp:34
std::string GetCommand() const
Definition: protocol.cpp:94
const char * NOTFOUND
The notfound message is a reply to a getdata message which requested an object the receiving node doe...
Definition: protocol.cpp:31
const char * FEEFILTER
The feefilter message tells the receiving peer not to inv us any txs which do not meet the specified ...
Definition: protocol.cpp:37
#define b(i, j)
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:40
const char * REJECT
The reject message informs the receiving node that one of its previous messages has been rejected...
Definition: protocol.cpp:35
const char * GETBLOCKS
The getblocks message requests an inv message that provides block header hashes starting from a parti...
Definition: protocol.cpp:22
ADD_SERIALIZE_METHODS
Definition: protocol.h:344
const char * VERACK
The verack message acknowledges a previously-received version message, informing the connecting node ...
Definition: protocol.cpp:17
256-bit opaque blob.
Definition: uint256.h:132
unsigned int nTime
Definition: protocol.h:313
ServiceFlags nServices
Definition: protocol.h:310
const char * CMPCTBLOCK
Contains a CBlockHeaderAndShortTxIDs object - providing a header and list of "short txids"...
Definition: protocol.cpp:39
PlatformStyle::TableColorType type
Definition: rpcconsole.cpp:61
const char * GETDATA
The getdata message requests one or more data objects from another node.
Definition: protocol.cpp:20
void SerializationOp(Stream &s, Operation ser_action)
Definition: protocol.h:347
const char * TX
The tx message transmits a single transaction.
Definition: protocol.cpp:24
#define VERSION
char pchMessageStart[MESSAGE_START_SIZE]
Definition: protocol.h:59
Defined in BIP37.
Definition: protocol.h:330
const char * FILTERADD
The filteradd message tells the receiving peer to add a single element to a previously-set bloom filt...
Definition: protocol.cpp:33
bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
Definition: asn.h:562
const char * GETBLOCKTXN
Contains a BlockTransactionsRequest Peer should respond with "blocktxn" message.
Definition: protocol.cpp:40
Message header.
Definition: protocol.h:27