aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-12-07 15:31:32 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2015-12-10 12:14:06 +0100
commit9bbe71b641e2fc985daf127988a14a67c99da50a (patch)
tree6d13cf5ecbceb44ec633ad07b435799c6c73e4f5 /src/protocol.cpp
parent5dc63ed1ca8aca62f28881ba9ef996d4036a23ea (diff)
downloadbitcoin-9bbe71b641e2fc985daf127988a14a67c99da50a.tar.xz
net: Add and document network messages in protocol.h
- Avoids string typos (by making the compiler check) - Makes it easier to grep for handling/generation of a certain message type - Refer directly to documentation by following the symbol in IDE - Move list of valid message types to protocol.cpp: protocol.cpp is a more appropriate place for this, and having the array there makes it easier to keep things consistent.
Diffstat (limited to 'src/protocol.cpp')
-rw-r--r--src/protocol.cpp67
1 files changed, 63 insertions, 4 deletions
diff --git a/src/protocol.cpp b/src/protocol.cpp
index dd855aa33a..5d3ae87de8 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -12,13 +12,67 @@
# include <arpa/inet.h>
#endif
+namespace NetMsgType {
+const char *VERSION="version";
+const char *VERACK="verack";
+const char *ADDR="addr";
+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 *ALERT="alert";
+const char *NOTFOUND="notfound";
+const char *FILTERLOAD="filterload";
+const char *FILTERADD="filteradd";
+const char *FILTERCLEAR="filterclear";
+const char *REJECT="reject";
+const char *SENDHEADERS="sendheaders";
+};
+
static const char* ppszTypeName[] =
{
- "ERROR",
- "tx",
- "block",
- "filtered block"
+ "ERROR", // Should never occur
+ NetMsgType::TX,
+ NetMsgType::BLOCK,
+ "filtered block" // Should never occur
+};
+
+/** All known message types. Keep this in the same order as the list of
+ * messages above and in protocol.h.
+ */
+const static std::string allNetMessageTypes[] = {
+ NetMsgType::VERSION,
+ NetMsgType::VERACK,
+ NetMsgType::ADDR,
+ 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::ALERT,
+ NetMsgType::NOTFOUND,
+ NetMsgType::FILTERLOAD,
+ NetMsgType::FILTERADD,
+ NetMsgType::FILTERCLEAR,
+ NetMsgType::REJECT,
+ NetMsgType::SENDHEADERS
};
+const static std::vector<std::string> allNetMessageTypesVec(allNetMessageTypes, allNetMessageTypes+ARRAYLEN(allNetMessageTypes));
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn)
{
@@ -140,3 +194,8 @@ std::string CInv::ToString() const
{
return strprintf("%s %s", GetCommand(), hash.ToString());
}
+
+const std::vector<std::string> &getAllNetMessageTypes()
+{
+ return allNetMessageTypesVec;
+}