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.
This commit is contained in:
Wladimir J. van der Laan
2015-12-07 15:31:32 +01:00
parent 5dc63ed1ca
commit 9bbe71b641
5 changed files with 283 additions and 73 deletions

View File

@@ -67,14 +67,6 @@ namespace {
};
}
//immutable thread safe array of allowed commands for logging inbound traffic
const static std::string logAllowIncomingMsgCmds[] = {
"version", "addr", "inv", "getdata", "merkleblock",
"getblocks", "getheaders", "tx", "headers", "block",
"getaddr", "mempool", "ping", "pong", "alert", "notfound",
"filterload", "filteradd", "filterclear", "reject",
"sendheaders", "verack"};
const static std::string NET_MESSAGE_COMMAND_OTHER = "*other*";
//
@@ -469,7 +461,7 @@ void CNode::PushVersion()
LogPrint("net", "send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), addrYou.ToString(), id);
else
LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id);
PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe,
PushMessage(NetMsgType::VERSION, PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe,
nLocalHostNonce, strSubVersion, nBestHeight, !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY));
}
@@ -2399,8 +2391,8 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
nPingUsecTime = 0;
fPingQueued = false;
nMinPingUsecTime = std::numeric_limits<int64_t>::max();
for (unsigned int i = 0; i < sizeof(logAllowIncomingMsgCmds)/sizeof(logAllowIncomingMsgCmds[0]); i++)
mapRecvBytesPerMsgCmd[logAllowIncomingMsgCmds[i]] = 0;
BOOST_FOREACH(const std::string &msg, getAllNetMessageTypes())
mapRecvBytesPerMsgCmd[msg] = 0;
mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0;
{