Skip to content

Commit b3efb48

Browse files
committed
protocol: make message types constexpr
As a side effect the names of the constants do not have to be repeated in `src/protocol.cpp`.
1 parent 2fa9de0 commit b3efb48

File tree

2 files changed

+35
-76
lines changed

2 files changed

+35
-76
lines changed

src/protocol.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,6 @@
77

88
#include <common/system.h>
99

10-
#include <atomic>
11-
12-
namespace NetMsgType {
13-
const char* VERSION = "version";
14-
const char* VERACK = "verack";
15-
const char* ADDR = "addr";
16-
const char* ADDRV2 = "addrv2";
17-
const char* SENDADDRV2 = "sendaddrv2";
18-
const char* INV = "inv";
19-
const char* GETDATA = "getdata";
20-
const char* MERKLEBLOCK = "merkleblock";
21-
const char* GETBLOCKS = "getblocks";
22-
const char* GETHEADERS = "getheaders";
23-
const char* TX = "tx";
24-
const char* HEADERS = "headers";
25-
const char* BLOCK = "block";
26-
const char* GETADDR = "getaddr";
27-
const char* MEMPOOL = "mempool";
28-
const char* PING = "ping";
29-
const char* PONG = "pong";
30-
const char* NOTFOUND = "notfound";
31-
const char* FILTERLOAD = "filterload";
32-
const char* FILTERADD = "filteradd";
33-
const char* FILTERCLEAR = "filterclear";
34-
const char* SENDHEADERS = "sendheaders";
35-
const char* FEEFILTER = "feefilter";
36-
const char* SENDCMPCT = "sendcmpct";
37-
const char* CMPCTBLOCK = "cmpctblock";
38-
const char* GETBLOCKTXN = "getblocktxn";
39-
const char* BLOCKTXN = "blocktxn";
40-
const char* GETCFILTERS = "getcfilters";
41-
const char* CFILTER = "cfilter";
42-
const char* GETCFHEADERS = "getcfheaders";
43-
const char* CFHEADERS = "cfheaders";
44-
const char* GETCFCHECKPT = "getcfcheckpt";
45-
const char* CFCHECKPT = "cfcheckpt";
46-
const char* WTXIDRELAY = "wtxidrelay";
47-
const char* SENDTXRCNCL = "sendtxrcncl";
48-
} // namespace NetMsgType
49-
5010
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
5111
: pchMessageStart{pchMessageStartIn}
5212
{

src/protocol.h

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,213 +58,212 @@ class CMessageHeader
5858
* to update ALL_NET_MESSAGE_TYPES below.
5959
*/
6060
namespace NetMsgType {
61-
6261
/**
6362
* The version message provides information about the transmitting node to the
6463
* receiving node at the beginning of a connection.
6564
*/
66-
extern const char* VERSION;
65+
inline constexpr const char* VERSION{"version"};
6766
/**
6867
* The verack message acknowledges a previously-received version message,
6968
* informing the connecting node that it can begin to send other messages.
7069
*/
71-
extern const char* VERACK;
70+
inline constexpr const char* VERACK{"verack"};
7271
/**
7372
* The addr (IP address) message relays connection information for peers on the
7473
* network.
7574
*/
76-
extern const char* ADDR;
75+
inline constexpr const char* ADDR{"addr"};
7776
/**
7877
* The addrv2 message relays connection information for peers on the network just
7978
* like the addr message, but is extended to allow gossiping of longer node
8079
* addresses (see BIP155).
8180
*/
82-
extern const char *ADDRV2;
81+
inline constexpr const char* ADDRV2{"addrv2"};
8382
/**
8483
* The sendaddrv2 message signals support for receiving ADDRV2 messages (BIP155).
8584
* It also implies that its sender can encode as ADDRV2 and would send ADDRV2
8685
* instead of ADDR to a peer that has signaled ADDRV2 support by sending SENDADDRV2.
8786
*/
88-
extern const char *SENDADDRV2;
87+
inline constexpr const char* SENDADDRV2{"sendaddrv2"};
8988
/**
9089
* The inv message (inventory message) transmits one or more inventories of
9190
* objects known to the transmitting peer.
9291
*/
93-
extern const char* INV;
92+
inline constexpr const char* INV{"inv"};
9493
/**
9594
* The getdata message requests one or more data objects from another node.
9695
*/
97-
extern const char* GETDATA;
96+
inline constexpr const char* GETDATA{"getdata"};
9897
/**
9998
* The merkleblock message is a reply to a getdata message which requested a
10099
* block using the inventory type MSG_MERKLEBLOCK.
101100
* @since protocol version 70001 as described by BIP37.
102101
*/
103-
extern const char* MERKLEBLOCK;
102+
inline constexpr const char* MERKLEBLOCK{"merkleblock"};
104103
/**
105104
* The getblocks message requests an inv message that provides block header
106105
* hashes starting from a particular point in the block chain.
107106
*/
108-
extern const char* GETBLOCKS;
107+
inline constexpr const char* GETBLOCKS{"getblocks"};
109108
/**
110109
* The getheaders message requests a headers message that provides block
111110
* headers starting from a particular point in the block chain.
112111
* @since protocol version 31800.
113112
*/
114-
extern const char* GETHEADERS;
113+
inline constexpr const char* GETHEADERS{"getheaders"};
115114
/**
116115
* The tx message transmits a single transaction.
117116
*/
118-
extern const char* TX;
117+
inline constexpr const char* TX{"tx"};
119118
/**
120119
* The headers message sends one or more block headers to a node which
121120
* previously requested certain headers with a getheaders message.
122121
* @since protocol version 31800.
123122
*/
124-
extern const char* HEADERS;
123+
inline constexpr const char* HEADERS{"headers"};
125124
/**
126125
* The block message transmits a single serialized block.
127126
*/
128-
extern const char* BLOCK;
127+
inline constexpr const char* BLOCK{"block"};
129128
/**
130129
* The getaddr message requests an addr message from the receiving node,
131130
* preferably one with lots of IP addresses of other receiving nodes.
132131
*/
133-
extern const char* GETADDR;
132+
inline constexpr const char* GETADDR{"getaddr"};
134133
/**
135134
* The mempool message requests the TXIDs of transactions that the receiving
136135
* node has verified as valid but which have not yet appeared in a block.
137136
* @since protocol version 60002 as described by BIP35.
138137
* Only available with service bit NODE_BLOOM, see also BIP111.
139138
*/
140-
extern const char* MEMPOOL;
139+
inline constexpr const char* MEMPOOL{"mempool"};
141140
/**
142141
* The ping message is sent periodically to help confirm that the receiving
143142
* peer is still connected.
144143
*/
145-
extern const char* PING;
144+
inline constexpr const char* PING{"ping"};
146145
/**
147146
* The pong message replies to a ping message, proving to the pinging node that
148147
* the ponging node is still alive.
149148
* @since protocol version 60001 as described by BIP31.
150149
*/
151-
extern const char* PONG;
150+
inline constexpr const char* PONG{"pong"};
152151
/**
153152
* The notfound message is a reply to a getdata message which requested an
154153
* object the receiving node does not have available for relay.
155154
* @since protocol version 70001.
156155
*/
157-
extern const char* NOTFOUND;
156+
inline constexpr const char* NOTFOUND{"notfound"};
158157
/**
159158
* The filterload message tells the receiving peer to filter all relayed
160159
* transactions and requested merkle blocks through the provided filter.
161160
* @since protocol version 70001 as described by BIP37.
162161
* Only available with service bit NODE_BLOOM since protocol version
163162
* 70011 as described by BIP111.
164163
*/
165-
extern const char* FILTERLOAD;
164+
inline constexpr const char* FILTERLOAD{"filterload"};
166165
/**
167166
* The filteradd message tells the receiving peer to add a single element to a
168167
* previously-set bloom filter, such as a new public key.
169168
* @since protocol version 70001 as described by BIP37.
170169
* Only available with service bit NODE_BLOOM since protocol version
171170
* 70011 as described by BIP111.
172171
*/
173-
extern const char* FILTERADD;
172+
inline constexpr const char* FILTERADD{"filteradd"};
174173
/**
175174
* The filterclear message tells the receiving peer to remove a previously-set
176175
* bloom filter.
177176
* @since protocol version 70001 as described by BIP37.
178177
* Only available with service bit NODE_BLOOM since protocol version
179178
* 70011 as described by BIP111.
180179
*/
181-
extern const char* FILTERCLEAR;
180+
inline constexpr const char* FILTERCLEAR{"filterclear"};
182181
/**
183182
* Indicates that a node prefers to receive new block announcements via a
184183
* "headers" message rather than an "inv".
185184
* @since protocol version 70012 as described by BIP130.
186185
*/
187-
extern const char* SENDHEADERS;
186+
inline constexpr const char* SENDHEADERS{"sendheaders"};
188187
/**
189188
* The feefilter message tells the receiving peer not to inv us any txs
190189
* which do not meet the specified min fee rate.
191190
* @since protocol version 70013 as described by BIP133
192191
*/
193-
extern const char* FEEFILTER;
192+
inline constexpr const char* FEEFILTER{"feefilter"};
194193
/**
195194
* Contains a 1-byte bool and 8-byte LE version number.
196195
* Indicates that a node is willing to provide blocks via "cmpctblock" messages.
197196
* May indicate that a node prefers to receive new block announcements via a
198197
* "cmpctblock" message rather than an "inv", depending on message contents.
199198
* @since protocol version 70014 as described by BIP 152
200199
*/
201-
extern const char* SENDCMPCT;
200+
inline constexpr const char* SENDCMPCT{"sendcmpct"};
202201
/**
203202
* Contains a CBlockHeaderAndShortTxIDs object - providing a header and
204203
* list of "short txids".
205204
* @since protocol version 70014 as described by BIP 152
206205
*/
207-
extern const char* CMPCTBLOCK;
206+
inline constexpr const char* CMPCTBLOCK{"cmpctblock"};
208207
/**
209208
* Contains a BlockTransactionsRequest
210209
* Peer should respond with "blocktxn" message.
211210
* @since protocol version 70014 as described by BIP 152
212211
*/
213-
extern const char* GETBLOCKTXN;
212+
inline constexpr const char* GETBLOCKTXN{"getblocktxn"};
214213
/**
215214
* Contains a BlockTransactions.
216215
* Sent in response to a "getblocktxn" message.
217216
* @since protocol version 70014 as described by BIP 152
218217
*/
219-
extern const char* BLOCKTXN;
218+
inline constexpr const char* BLOCKTXN{"blocktxn"};
220219
/**
221220
* getcfilters requests compact filters for a range of blocks.
222221
* Only available with service bit NODE_COMPACT_FILTERS as described by
223222
* BIP 157 & 158.
224223
*/
225-
extern const char* GETCFILTERS;
224+
inline constexpr const char* GETCFILTERS{"getcfilters"};
226225
/**
227226
* cfilter is a response to a getcfilters request containing a single compact
228227
* filter.
229228
*/
230-
extern const char* CFILTER;
229+
inline constexpr const char* CFILTER{"cfilter"};
231230
/**
232231
* getcfheaders requests a compact filter header and the filter hashes for a
233232
* range of blocks, which can then be used to reconstruct the filter headers
234233
* for those blocks.
235234
* Only available with service bit NODE_COMPACT_FILTERS as described by
236235
* BIP 157 & 158.
237236
*/
238-
extern const char* GETCFHEADERS;
237+
inline constexpr const char* GETCFHEADERS{"getcfheaders"};
239238
/**
240239
* cfheaders is a response to a getcfheaders request containing a filter header
241240
* and a vector of filter hashes for each subsequent block in the requested range.
242241
*/
243-
extern const char* CFHEADERS;
242+
inline constexpr const char* CFHEADERS{"cfheaders"};
244243
/**
245244
* getcfcheckpt requests evenly spaced compact filter headers, enabling
246245
* parallelized download and validation of the headers between them.
247246
* Only available with service bit NODE_COMPACT_FILTERS as described by
248247
* BIP 157 & 158.
249248
*/
250-
extern const char* GETCFCHECKPT;
249+
inline constexpr const char* GETCFCHECKPT{"getcfcheckpt"};
251250
/**
252251
* cfcheckpt is a response to a getcfcheckpt request containing a vector of
253252
* evenly spaced filter headers for blocks on the requested chain.
254253
*/
255-
extern const char* CFCHECKPT;
254+
inline constexpr const char* CFCHECKPT{"cfcheckpt"};
256255
/**
257256
* Indicates that a node prefers to relay transactions via wtxid, rather than
258257
* txid.
259258
* @since protocol version 70016 as described by BIP 339.
260259
*/
261-
extern const char* WTXIDRELAY;
260+
inline constexpr const char* WTXIDRELAY{"wtxidrelay"};
262261
/**
263262
* Contains a 4-byte version number and an 8-byte salt.
264263
* The salt is used to compute short txids needed for efficient
265264
* txreconciliation, as described by BIP 330.
266265
*/
267-
extern const char* SENDTXRCNCL;
266+
inline constexpr const char* SENDTXRCNCL{"sendtxrcncl"};
268267
}; // namespace NetMsgType
269268

270269
/** All known message types (see above). Keep this in the same order as the list of messages above. */

0 commit comments

Comments
 (0)