aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.h
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2023-11-16 12:34:27 +0100
committerVasil Dimov <vd@FreeBSD.org>2024-02-28 18:03:22 +0100
commit2fa9de06c2c8583ee8e2434dc97014b26e218ab5 (patch)
tree3e55459da61c2ac8e903e537a9e6cd669f4f4345 /src/protocol.h
parentba907f96ad37c09c49c0e1532fad118fcb8dd4a8 (diff)
downloadbitcoin-2fa9de06c2c8583ee8e2434dc97014b26e218ab5.tar.xz
net: make the list of known message types a compile time constant
Turn the `std::vector` to `std::array` because it is cheaper and allows us to have the number of the messages as a compile time constant: `ALL_NET_MESSAGE_TYPES.size()` which can be used in future code to build other `std::array`s with that size.
Diffstat (limited to 'src/protocol.h')
-rw-r--r--src/protocol.h42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/protocol.h b/src/protocol.h
index 243cd23e6e..350e1d9866 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -55,7 +55,7 @@ public:
/**
* Bitcoin protocol message types. When adding new message types, don't forget
- * to update allNetMessageTypes in protocol.cpp.
+ * to update ALL_NET_MESSAGE_TYPES below.
*/
namespace NetMsgType {
@@ -267,8 +267,44 @@ extern const char* WTXIDRELAY;
extern const char* SENDTXRCNCL;
}; // namespace NetMsgType
-/* Get a vector of all valid message types (see above) */
-const std::vector<std::string>& getAllNetMessageTypes();
+/** All known message types (see above). Keep this in the same order as the list of messages above. */
+inline const std::array ALL_NET_MESSAGE_TYPES{std::to_array<std::string>({
+ NetMsgType::VERSION,
+ NetMsgType::VERACK,
+ NetMsgType::ADDR,
+ NetMsgType::ADDRV2,
+ NetMsgType::SENDADDRV2,
+ NetMsgType::INV,
+ NetMsgType::GETDATA,
+ NetMsgType::MERKLEBLOCK,
+ NetMsgType::GETBLOCKS,
+ NetMsgType::GETHEADERS,
+ NetMsgType::TX,
+ NetMsgType::HEADERS,
+ NetMsgType::BLOCK,
+ NetMsgType::GETADDR,
+ NetMsgType::MEMPOOL,
+ NetMsgType::PING,
+ NetMsgType::PONG,
+ NetMsgType::NOTFOUND,
+ NetMsgType::FILTERLOAD,
+ NetMsgType::FILTERADD,
+ NetMsgType::FILTERCLEAR,
+ NetMsgType::SENDHEADERS,
+ NetMsgType::FEEFILTER,
+ NetMsgType::SENDCMPCT,
+ NetMsgType::CMPCTBLOCK,
+ NetMsgType::GETBLOCKTXN,
+ NetMsgType::BLOCKTXN,
+ NetMsgType::GETCFILTERS,
+ NetMsgType::CFILTER,
+ NetMsgType::GETCFHEADERS,
+ NetMsgType::CFHEADERS,
+ NetMsgType::GETCFCHECKPT,
+ NetMsgType::CFCHECKPT,
+ NetMsgType::WTXIDRELAY,
+ NetMsgType::SENDTXRCNCL,
+})};
/** nServices flags */
enum ServiceFlags : uint64_t {