diff --git a/src/protocol.cpp b/src/protocol.cpp index dd8da8716a..eaebd05d80 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -10,78 +10,82 @@ static std::atomic g_initial_block_download_completed(false); +#define MAKE_MSG(var_name, p2p_name_str) \ + const char* var_name=p2p_name_str; \ + static_assert(std::size(p2p_name_str) <= CMessageHeader::COMMAND_SIZE + 1, "p2p_name_str cannot be greater than COMMAND_SIZE"); // Includes +1 for null termination character. + 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 *REJECT="reject"; -const char *SENDHEADERS="sendheaders"; -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"; +MAKE_MSG(VERSION, "version"); +MAKE_MSG(VERACK, "verack"); +MAKE_MSG(ADDR, "addr"); +MAKE_MSG(ADDRV2, "addrv2"); +MAKE_MSG(SENDADDRV2, "sendaddrv2"); +MAKE_MSG(INV, "inv"); +MAKE_MSG(GETDATA, "getdata"); +MAKE_MSG(MERKLEBLOCK, "merkleblock"); +MAKE_MSG(GETBLOCKS, "getblocks"); +MAKE_MSG(GETHEADERS, "getheaders"); +MAKE_MSG(TX, "tx"); +MAKE_MSG(HEADERS, "headers"); +MAKE_MSG(BLOCK, "block"); +MAKE_MSG(GETADDR, "getaddr"); +MAKE_MSG(MEMPOOL, "mempool"); +MAKE_MSG(PING, "ping"); +MAKE_MSG(PONG, "pong"); +MAKE_MSG(NOTFOUND, "notfound"); +MAKE_MSG(FILTERLOAD, "filterload"); +MAKE_MSG(FILTERADD, "filteradd"); +MAKE_MSG(FILTERCLEAR, "filterclear"); +MAKE_MSG(REJECT, "reject"); +MAKE_MSG(SENDHEADERS, "sendheaders"); +MAKE_MSG(SENDCMPCT, "sendcmpct"); +MAKE_MSG(CMPCTBLOCK, "cmpctblock"); +MAKE_MSG(GETBLOCKTXN, "getblocktxn"); +MAKE_MSG(BLOCKTXN, "blocktxn"); +MAKE_MSG(GETCFILTERS, "getcfilters"); +MAKE_MSG(CFILTER, "cfilter"); +MAKE_MSG(GETCFHEADERS, "getcfheaders"); +MAKE_MSG(CFHEADERS, "cfheaders"); +MAKE_MSG(GETCFCHECKPT, "getcfcheckpt"); +MAKE_MSG(CFCHECKPT, "cfcheckpt"); // Dash message types -const char *LEGACYTXLOCKREQUEST="ix"; -const char *SPORK="spork"; -const char *GETSPORKS="getsporks"; -const char *DSACCEPT="dsa"; -const char *DSVIN="dsi"; -const char *DSFINALTX="dsf"; -const char *DSSIGNFINALTX="dss"; -const char *DSCOMPLETE="dsc"; -const char *DSSTATUSUPDATE="dssu"; -const char *DSTX="dstx"; -const char *DSQUEUE="dsq"; -const char *SENDDSQUEUE="senddsq"; -const char *SYNCSTATUSCOUNT="ssc"; -const char *MNGOVERNANCESYNC="govsync"; -const char *MNGOVERNANCEOBJECT="govobj"; -const char *MNGOVERNANCEOBJECTVOTE="govobjvote"; -const char *GETMNLISTDIFF="getmnlistd"; -const char *MNLISTDIFF="mnlistdiff"; -const char *QSENDRECSIGS="qsendrecsigs"; -const char *QFCOMMITMENT="qfcommit"; -const char *QCONTRIB="qcontrib"; -const char *QCOMPLAINT="qcomplaint"; -const char *QJUSTIFICATION="qjustify"; -const char *QPCOMMITMENT="qpcommit"; -const char *QWATCH="qwatch"; -const char *QSIGSESANN="qsigsesann"; -const char *QSIGSHARESINV="qsigsinv"; -const char *QGETSIGSHARES="qgetsigs"; -const char *QBSIGSHARES="qbsigs"; -const char *QSIGREC="qsigrec"; -const char *QSIGSHARE="qsigshare"; -const char* QGETDATA = "qgetdata"; -const char* QDATA = "qdata"; -const char *CLSIG="clsig"; -const char *ISLOCK="islock"; -const char *ISDLOCK="isdlock"; -const char *MNAUTH="mnauth"; +MAKE_MSG(LEGACYTXLOCKREQUEST, "ix"); +MAKE_MSG(SPORK, "spork"); +MAKE_MSG(GETSPORKS, "getsporks"); +MAKE_MSG(DSACCEPT, "dsa"); +MAKE_MSG(DSVIN, "dsi"); +MAKE_MSG(DSFINALTX, "dsf"); +MAKE_MSG(DSSIGNFINALTX, "dss"); +MAKE_MSG(DSCOMPLETE, "dsc"); +MAKE_MSG(DSSTATUSUPDATE, "dssu"); +MAKE_MSG(DSTX, "dstx"); +MAKE_MSG(DSQUEUE, "dsq"); +MAKE_MSG(SENDDSQUEUE, "senddsq"); +MAKE_MSG(SYNCSTATUSCOUNT, "ssc"); +MAKE_MSG(MNGOVERNANCESYNC, "govsync"); +MAKE_MSG(MNGOVERNANCEOBJECT, "govobj"); +MAKE_MSG(MNGOVERNANCEOBJECTVOTE, "govobjvote"); +MAKE_MSG(GETMNLISTDIFF, "getmnlistd"); +MAKE_MSG(MNLISTDIFF, "mnlistdiff"); +MAKE_MSG(QSENDRECSIGS, "qsendrecsigs"); +MAKE_MSG(QFCOMMITMENT, "qfcommit"); +MAKE_MSG(QCONTRIB, "qcontrib"); +MAKE_MSG(QCOMPLAINT, "qcomplaint"); +MAKE_MSG(QJUSTIFICATION, "qjustify"); +MAKE_MSG(QPCOMMITMENT, "qpcommit"); +MAKE_MSG(QWATCH, "qwatch"); +MAKE_MSG(QSIGSESANN, "qsigsesann"); +MAKE_MSG(QSIGSHARESINV, "qsigsinv"); +MAKE_MSG(QGETSIGSHARES, "qgetsigs"); +MAKE_MSG(QBSIGSHARES, "qbsigs"); +MAKE_MSG(QSIGREC, "qsigrec"); +MAKE_MSG(QSIGSHARE, "qsigshare"); +MAKE_MSG(QGETDATA, "qgetdata"); +MAKE_MSG(QDATA, "qdata"); +MAKE_MSG(CLSIG, "clsig"); +MAKE_MSG(ISLOCK, "islock"); +MAKE_MSG(ISDLOCK, "isdlock"); +MAKE_MSG(MNAUTH, "mnauth"); }; // namespace NetMsgType /** All known message types. Keep this in the same order as the list of