mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-12 11:19:08 -05:00
protocol: make message types constexpr
As a side effect the names of the constants do not have to be repeated in `src/protocol.cpp`.
This commit is contained in:
parent
2fa9de06c2
commit
b3efb48673
2 changed files with 35 additions and 76 deletions
|
@ -7,46 +7,6 @@
|
||||||
|
|
||||||
#include <common/system.h>
|
#include <common/system.h>
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
namespace NetMsgType {
|
|
||||||
const char* VERSION = "version";
|
|
||||||
const char* VERACK = "verack";
|
|
||||||
const char* ADDR = "addr";
|
|
||||||
const char* ADDRV2 = "addrv2";
|
|
||||||
const char* SENDADDRV2 = "sendaddrv2";
|
|
||||||
const char* INV = "inv";
|
|
||||||
const char* GETDATA = "getdata";
|
|
||||||
const char* MERKLEBLOCK = "merkleblock";
|
|
||||||
const char* GETBLOCKS = "getblocks";
|
|
||||||
const char* GETHEADERS = "getheaders";
|
|
||||||
const char* TX = "tx";
|
|
||||||
const char* HEADERS = "headers";
|
|
||||||
const char* BLOCK = "block";
|
|
||||||
const char* GETADDR = "getaddr";
|
|
||||||
const char* MEMPOOL = "mempool";
|
|
||||||
const char* PING = "ping";
|
|
||||||
const char* PONG = "pong";
|
|
||||||
const char* NOTFOUND = "notfound";
|
|
||||||
const char* FILTERLOAD = "filterload";
|
|
||||||
const char* FILTERADD = "filteradd";
|
|
||||||
const char* FILTERCLEAR = "filterclear";
|
|
||||||
const char* SENDHEADERS = "sendheaders";
|
|
||||||
const char* FEEFILTER = "feefilter";
|
|
||||||
const char* SENDCMPCT = "sendcmpct";
|
|
||||||
const char* CMPCTBLOCK = "cmpctblock";
|
|
||||||
const char* GETBLOCKTXN = "getblocktxn";
|
|
||||||
const char* BLOCKTXN = "blocktxn";
|
|
||||||
const char* GETCFILTERS = "getcfilters";
|
|
||||||
const char* CFILTER = "cfilter";
|
|
||||||
const char* GETCFHEADERS = "getcfheaders";
|
|
||||||
const char* CFHEADERS = "cfheaders";
|
|
||||||
const char* GETCFCHECKPT = "getcfcheckpt";
|
|
||||||
const char* CFCHECKPT = "cfcheckpt";
|
|
||||||
const char* WTXIDRELAY = "wtxidrelay";
|
|
||||||
const char* SENDTXRCNCL = "sendtxrcncl";
|
|
||||||
} // namespace NetMsgType
|
|
||||||
|
|
||||||
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
|
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
|
||||||
: pchMessageStart{pchMessageStartIn}
|
: pchMessageStart{pchMessageStartIn}
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,103 +58,102 @@ public:
|
||||||
* to update ALL_NET_MESSAGE_TYPES below.
|
* to update ALL_NET_MESSAGE_TYPES below.
|
||||||
*/
|
*/
|
||||||
namespace NetMsgType {
|
namespace NetMsgType {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The version message provides information about the transmitting node to the
|
* The version message provides information about the transmitting node to the
|
||||||
* receiving node at the beginning of a connection.
|
* receiving node at the beginning of a connection.
|
||||||
*/
|
*/
|
||||||
extern const char* VERSION;
|
inline constexpr const char* VERSION{"version"};
|
||||||
/**
|
/**
|
||||||
* The verack message acknowledges a previously-received version message,
|
* The verack message acknowledges a previously-received version message,
|
||||||
* informing the connecting node that it can begin to send other messages.
|
* informing the connecting node that it can begin to send other messages.
|
||||||
*/
|
*/
|
||||||
extern const char* VERACK;
|
inline constexpr const char* VERACK{"verack"};
|
||||||
/**
|
/**
|
||||||
* The addr (IP address) message relays connection information for peers on the
|
* The addr (IP address) message relays connection information for peers on the
|
||||||
* network.
|
* network.
|
||||||
*/
|
*/
|
||||||
extern const char* ADDR;
|
inline constexpr const char* ADDR{"addr"};
|
||||||
/**
|
/**
|
||||||
* The addrv2 message relays connection information for peers on the network just
|
* The addrv2 message relays connection information for peers on the network just
|
||||||
* like the addr message, but is extended to allow gossiping of longer node
|
* like the addr message, but is extended to allow gossiping of longer node
|
||||||
* addresses (see BIP155).
|
* addresses (see BIP155).
|
||||||
*/
|
*/
|
||||||
extern const char *ADDRV2;
|
inline constexpr const char* ADDRV2{"addrv2"};
|
||||||
/**
|
/**
|
||||||
* The sendaddrv2 message signals support for receiving ADDRV2 messages (BIP155).
|
* The sendaddrv2 message signals support for receiving ADDRV2 messages (BIP155).
|
||||||
* It also implies that its sender can encode as ADDRV2 and would send ADDRV2
|
* It also implies that its sender can encode as ADDRV2 and would send ADDRV2
|
||||||
* instead of ADDR to a peer that has signaled ADDRV2 support by sending SENDADDRV2.
|
* instead of ADDR to a peer that has signaled ADDRV2 support by sending SENDADDRV2.
|
||||||
*/
|
*/
|
||||||
extern const char *SENDADDRV2;
|
inline constexpr const char* SENDADDRV2{"sendaddrv2"};
|
||||||
/**
|
/**
|
||||||
* The inv message (inventory message) transmits one or more inventories of
|
* The inv message (inventory message) transmits one or more inventories of
|
||||||
* objects known to the transmitting peer.
|
* objects known to the transmitting peer.
|
||||||
*/
|
*/
|
||||||
extern const char* INV;
|
inline constexpr const char* INV{"inv"};
|
||||||
/**
|
/**
|
||||||
* The getdata message requests one or more data objects from another node.
|
* The getdata message requests one or more data objects from another node.
|
||||||
*/
|
*/
|
||||||
extern const char* GETDATA;
|
inline constexpr const char* GETDATA{"getdata"};
|
||||||
/**
|
/**
|
||||||
* The merkleblock message is a reply to a getdata message which requested a
|
* The merkleblock message is a reply to a getdata message which requested a
|
||||||
* block using the inventory type MSG_MERKLEBLOCK.
|
* block using the inventory type MSG_MERKLEBLOCK.
|
||||||
* @since protocol version 70001 as described by BIP37.
|
* @since protocol version 70001 as described by BIP37.
|
||||||
*/
|
*/
|
||||||
extern const char* MERKLEBLOCK;
|
inline constexpr const char* MERKLEBLOCK{"merkleblock"};
|
||||||
/**
|
/**
|
||||||
* The getblocks message requests an inv message that provides block header
|
* The getblocks message requests an inv message that provides block header
|
||||||
* hashes starting from a particular point in the block chain.
|
* hashes starting from a particular point in the block chain.
|
||||||
*/
|
*/
|
||||||
extern const char* GETBLOCKS;
|
inline constexpr const char* GETBLOCKS{"getblocks"};
|
||||||
/**
|
/**
|
||||||
* The getheaders message requests a headers message that provides block
|
* The getheaders message requests a headers message that provides block
|
||||||
* headers starting from a particular point in the block chain.
|
* headers starting from a particular point in the block chain.
|
||||||
* @since protocol version 31800.
|
* @since protocol version 31800.
|
||||||
*/
|
*/
|
||||||
extern const char* GETHEADERS;
|
inline constexpr const char* GETHEADERS{"getheaders"};
|
||||||
/**
|
/**
|
||||||
* The tx message transmits a single transaction.
|
* The tx message transmits a single transaction.
|
||||||
*/
|
*/
|
||||||
extern const char* TX;
|
inline constexpr const char* TX{"tx"};
|
||||||
/**
|
/**
|
||||||
* The headers message sends one or more block headers to a node which
|
* The headers message sends one or more block headers to a node which
|
||||||
* previously requested certain headers with a getheaders message.
|
* previously requested certain headers with a getheaders message.
|
||||||
* @since protocol version 31800.
|
* @since protocol version 31800.
|
||||||
*/
|
*/
|
||||||
extern const char* HEADERS;
|
inline constexpr const char* HEADERS{"headers"};
|
||||||
/**
|
/**
|
||||||
* The block message transmits a single serialized block.
|
* The block message transmits a single serialized block.
|
||||||
*/
|
*/
|
||||||
extern const char* BLOCK;
|
inline constexpr const char* BLOCK{"block"};
|
||||||
/**
|
/**
|
||||||
* The getaddr message requests an addr message from the receiving node,
|
* The getaddr message requests an addr message from the receiving node,
|
||||||
* preferably one with lots of IP addresses of other receiving nodes.
|
* preferably one with lots of IP addresses of other receiving nodes.
|
||||||
*/
|
*/
|
||||||
extern const char* GETADDR;
|
inline constexpr const char* GETADDR{"getaddr"};
|
||||||
/**
|
/**
|
||||||
* The mempool message requests the TXIDs of transactions that the receiving
|
* The mempool message requests the TXIDs of transactions that the receiving
|
||||||
* node has verified as valid but which have not yet appeared in a block.
|
* node has verified as valid but which have not yet appeared in a block.
|
||||||
* @since protocol version 60002 as described by BIP35.
|
* @since protocol version 60002 as described by BIP35.
|
||||||
* Only available with service bit NODE_BLOOM, see also BIP111.
|
* Only available with service bit NODE_BLOOM, see also BIP111.
|
||||||
*/
|
*/
|
||||||
extern const char* MEMPOOL;
|
inline constexpr const char* MEMPOOL{"mempool"};
|
||||||
/**
|
/**
|
||||||
* The ping message is sent periodically to help confirm that the receiving
|
* The ping message is sent periodically to help confirm that the receiving
|
||||||
* peer is still connected.
|
* peer is still connected.
|
||||||
*/
|
*/
|
||||||
extern const char* PING;
|
inline constexpr const char* PING{"ping"};
|
||||||
/**
|
/**
|
||||||
* The pong message replies to a ping message, proving to the pinging node that
|
* The pong message replies to a ping message, proving to the pinging node that
|
||||||
* the ponging node is still alive.
|
* the ponging node is still alive.
|
||||||
* @since protocol version 60001 as described by BIP31.
|
* @since protocol version 60001 as described by BIP31.
|
||||||
*/
|
*/
|
||||||
extern const char* PONG;
|
inline constexpr const char* PONG{"pong"};
|
||||||
/**
|
/**
|
||||||
* The notfound message is a reply to a getdata message which requested an
|
* The notfound message is a reply to a getdata message which requested an
|
||||||
* object the receiving node does not have available for relay.
|
* object the receiving node does not have available for relay.
|
||||||
* @since protocol version 70001.
|
* @since protocol version 70001.
|
||||||
*/
|
*/
|
||||||
extern const char* NOTFOUND;
|
inline constexpr const char* NOTFOUND{"notfound"};
|
||||||
/**
|
/**
|
||||||
* The filterload message tells the receiving peer to filter all relayed
|
* The filterload message tells the receiving peer to filter all relayed
|
||||||
* transactions and requested merkle blocks through the provided filter.
|
* transactions and requested merkle blocks through the provided filter.
|
||||||
|
@ -162,7 +161,7 @@ extern const char* NOTFOUND;
|
||||||
* Only available with service bit NODE_BLOOM since protocol version
|
* Only available with service bit NODE_BLOOM since protocol version
|
||||||
* 70011 as described by BIP111.
|
* 70011 as described by BIP111.
|
||||||
*/
|
*/
|
||||||
extern const char* FILTERLOAD;
|
inline constexpr const char* FILTERLOAD{"filterload"};
|
||||||
/**
|
/**
|
||||||
* The filteradd message tells the receiving peer to add a single element to a
|
* The filteradd message tells the receiving peer to add a single element to a
|
||||||
* previously-set bloom filter, such as a new public key.
|
* previously-set bloom filter, such as a new public key.
|
||||||
|
@ -170,7 +169,7 @@ extern const char* FILTERLOAD;
|
||||||
* Only available with service bit NODE_BLOOM since protocol version
|
* Only available with service bit NODE_BLOOM since protocol version
|
||||||
* 70011 as described by BIP111.
|
* 70011 as described by BIP111.
|
||||||
*/
|
*/
|
||||||
extern const char* FILTERADD;
|
inline constexpr const char* FILTERADD{"filteradd"};
|
||||||
/**
|
/**
|
||||||
* The filterclear message tells the receiving peer to remove a previously-set
|
* The filterclear message tells the receiving peer to remove a previously-set
|
||||||
* bloom filter.
|
* bloom filter.
|
||||||
|
@ -178,19 +177,19 @@ extern const char* FILTERADD;
|
||||||
* Only available with service bit NODE_BLOOM since protocol version
|
* Only available with service bit NODE_BLOOM since protocol version
|
||||||
* 70011 as described by BIP111.
|
* 70011 as described by BIP111.
|
||||||
*/
|
*/
|
||||||
extern const char* FILTERCLEAR;
|
inline constexpr const char* FILTERCLEAR{"filterclear"};
|
||||||
/**
|
/**
|
||||||
* Indicates that a node prefers to receive new block announcements via a
|
* Indicates that a node prefers to receive new block announcements via a
|
||||||
* "headers" message rather than an "inv".
|
* "headers" message rather than an "inv".
|
||||||
* @since protocol version 70012 as described by BIP130.
|
* @since protocol version 70012 as described by BIP130.
|
||||||
*/
|
*/
|
||||||
extern const char* SENDHEADERS;
|
inline constexpr const char* SENDHEADERS{"sendheaders"};
|
||||||
/**
|
/**
|
||||||
* The feefilter message tells the receiving peer not to inv us any txs
|
* The feefilter message tells the receiving peer not to inv us any txs
|
||||||
* which do not meet the specified min fee rate.
|
* which do not meet the specified min fee rate.
|
||||||
* @since protocol version 70013 as described by BIP133
|
* @since protocol version 70013 as described by BIP133
|
||||||
*/
|
*/
|
||||||
extern const char* FEEFILTER;
|
inline constexpr const char* FEEFILTER{"feefilter"};
|
||||||
/**
|
/**
|
||||||
* Contains a 1-byte bool and 8-byte LE version number.
|
* Contains a 1-byte bool and 8-byte LE version number.
|
||||||
* Indicates that a node is willing to provide blocks via "cmpctblock" messages.
|
* Indicates that a node is willing to provide blocks via "cmpctblock" messages.
|
||||||
|
@ -198,36 +197,36 @@ extern const char* FEEFILTER;
|
||||||
* "cmpctblock" message rather than an "inv", depending on message contents.
|
* "cmpctblock" message rather than an "inv", depending on message contents.
|
||||||
* @since protocol version 70014 as described by BIP 152
|
* @since protocol version 70014 as described by BIP 152
|
||||||
*/
|
*/
|
||||||
extern const char* SENDCMPCT;
|
inline constexpr const char* SENDCMPCT{"sendcmpct"};
|
||||||
/**
|
/**
|
||||||
* Contains a CBlockHeaderAndShortTxIDs object - providing a header and
|
* Contains a CBlockHeaderAndShortTxIDs object - providing a header and
|
||||||
* list of "short txids".
|
* list of "short txids".
|
||||||
* @since protocol version 70014 as described by BIP 152
|
* @since protocol version 70014 as described by BIP 152
|
||||||
*/
|
*/
|
||||||
extern const char* CMPCTBLOCK;
|
inline constexpr const char* CMPCTBLOCK{"cmpctblock"};
|
||||||
/**
|
/**
|
||||||
* Contains a BlockTransactionsRequest
|
* Contains a BlockTransactionsRequest
|
||||||
* Peer should respond with "blocktxn" message.
|
* Peer should respond with "blocktxn" message.
|
||||||
* @since protocol version 70014 as described by BIP 152
|
* @since protocol version 70014 as described by BIP 152
|
||||||
*/
|
*/
|
||||||
extern const char* GETBLOCKTXN;
|
inline constexpr const char* GETBLOCKTXN{"getblocktxn"};
|
||||||
/**
|
/**
|
||||||
* Contains a BlockTransactions.
|
* Contains a BlockTransactions.
|
||||||
* Sent in response to a "getblocktxn" message.
|
* Sent in response to a "getblocktxn" message.
|
||||||
* @since protocol version 70014 as described by BIP 152
|
* @since protocol version 70014 as described by BIP 152
|
||||||
*/
|
*/
|
||||||
extern const char* BLOCKTXN;
|
inline constexpr const char* BLOCKTXN{"blocktxn"};
|
||||||
/**
|
/**
|
||||||
* getcfilters requests compact filters for a range of blocks.
|
* getcfilters requests compact filters for a range of blocks.
|
||||||
* Only available with service bit NODE_COMPACT_FILTERS as described by
|
* Only available with service bit NODE_COMPACT_FILTERS as described by
|
||||||
* BIP 157 & 158.
|
* BIP 157 & 158.
|
||||||
*/
|
*/
|
||||||
extern const char* GETCFILTERS;
|
inline constexpr const char* GETCFILTERS{"getcfilters"};
|
||||||
/**
|
/**
|
||||||
* cfilter is a response to a getcfilters request containing a single compact
|
* cfilter is a response to a getcfilters request containing a single compact
|
||||||
* filter.
|
* filter.
|
||||||
*/
|
*/
|
||||||
extern const char* CFILTER;
|
inline constexpr const char* CFILTER{"cfilter"};
|
||||||
/**
|
/**
|
||||||
* getcfheaders requests a compact filter header and the filter hashes for a
|
* getcfheaders requests a compact filter header and the filter hashes for a
|
||||||
* range of blocks, which can then be used to reconstruct the filter headers
|
* range of blocks, which can then be used to reconstruct the filter headers
|
||||||
|
@ -235,36 +234,36 @@ extern const char* CFILTER;
|
||||||
* Only available with service bit NODE_COMPACT_FILTERS as described by
|
* Only available with service bit NODE_COMPACT_FILTERS as described by
|
||||||
* BIP 157 & 158.
|
* BIP 157 & 158.
|
||||||
*/
|
*/
|
||||||
extern const char* GETCFHEADERS;
|
inline constexpr const char* GETCFHEADERS{"getcfheaders"};
|
||||||
/**
|
/**
|
||||||
* cfheaders is a response to a getcfheaders request containing a filter header
|
* cfheaders is a response to a getcfheaders request containing a filter header
|
||||||
* and a vector of filter hashes for each subsequent block in the requested range.
|
* and a vector of filter hashes for each subsequent block in the requested range.
|
||||||
*/
|
*/
|
||||||
extern const char* CFHEADERS;
|
inline constexpr const char* CFHEADERS{"cfheaders"};
|
||||||
/**
|
/**
|
||||||
* getcfcheckpt requests evenly spaced compact filter headers, enabling
|
* getcfcheckpt requests evenly spaced compact filter headers, enabling
|
||||||
* parallelized download and validation of the headers between them.
|
* parallelized download and validation of the headers between them.
|
||||||
* Only available with service bit NODE_COMPACT_FILTERS as described by
|
* Only available with service bit NODE_COMPACT_FILTERS as described by
|
||||||
* BIP 157 & 158.
|
* BIP 157 & 158.
|
||||||
*/
|
*/
|
||||||
extern const char* GETCFCHECKPT;
|
inline constexpr const char* GETCFCHECKPT{"getcfcheckpt"};
|
||||||
/**
|
/**
|
||||||
* cfcheckpt is a response to a getcfcheckpt request containing a vector of
|
* cfcheckpt is a response to a getcfcheckpt request containing a vector of
|
||||||
* evenly spaced filter headers for blocks on the requested chain.
|
* evenly spaced filter headers for blocks on the requested chain.
|
||||||
*/
|
*/
|
||||||
extern const char* CFCHECKPT;
|
inline constexpr const char* CFCHECKPT{"cfcheckpt"};
|
||||||
/**
|
/**
|
||||||
* Indicates that a node prefers to relay transactions via wtxid, rather than
|
* Indicates that a node prefers to relay transactions via wtxid, rather than
|
||||||
* txid.
|
* txid.
|
||||||
* @since protocol version 70016 as described by BIP 339.
|
* @since protocol version 70016 as described by BIP 339.
|
||||||
*/
|
*/
|
||||||
extern const char* WTXIDRELAY;
|
inline constexpr const char* WTXIDRELAY{"wtxidrelay"};
|
||||||
/**
|
/**
|
||||||
* Contains a 4-byte version number and an 8-byte salt.
|
* Contains a 4-byte version number and an 8-byte salt.
|
||||||
* The salt is used to compute short txids needed for efficient
|
* The salt is used to compute short txids needed for efficient
|
||||||
* txreconciliation, as described by BIP 330.
|
* txreconciliation, as described by BIP 330.
|
||||||
*/
|
*/
|
||||||
extern const char* SENDTXRCNCL;
|
inline constexpr const char* SENDTXRCNCL{"sendtxrcncl"};
|
||||||
}; // namespace NetMsgType
|
}; // namespace NetMsgType
|
||||||
|
|
||||||
/** All known message types (see above). Keep this in the same order as the list of messages above. */
|
/** All known message types (see above). Keep this in the same order as the list of messages above. */
|
||||||
|
|
Loading…
Add table
Reference in a new issue