14 #include <arpa/inet.h> 24 const char *
INV =
"inv";
29 const char *
TX =
"tx";
80 static const std::vector<std::string>
85 memcpy(std::begin(pchMessageStart), std::begin(pchMessageStartIn),
87 memset(pchCommand.data(), 0,
sizeof(pchCommand));
89 memset(pchChecksum, 0, CHECKSUM_SIZE);
93 const char *pszCommand,
94 unsigned int nMessageSizeIn) {
95 memcpy(std::begin(pchMessageStart), std::begin(pchMessageStartIn),
99 for (; i < pchCommand.size() && pszCommand[i] != 0; ++i) {
100 pchCommand[i] = pszCommand[i];
103 assert(pszCommand[i] == 0);
104 for (; i < pchCommand.size(); ++i) {
108 nMessageSize = nMessageSizeIn;
109 memset(pchChecksum, 0, CHECKSUM_SIZE);
114 return std::string(pchCommand.data(),
116 strnlen(pchCommand.data(), COMMAND_SIZE));
129 for (
const char *p1 = header.
pchCommand.data();
139 }
else if (*p1 < ' ' || *p1 > 0x7E) {
155 if (IsOversized(config)) {
156 LogPrintf(
"CMessageHeader::IsValid(): (%s, %u bytes) is oversized\n",
157 GetCommand(), nMessageSize);
180 "CMessageHeader::IsValidForSeeder(): (%s, %u bytes) is oversized\n",
181 GetCommand(), nMessageSize);
242 throw std::out_of_range(
243 strprintf(
"CInv::GetCommand(): type=%d unknown type", type));
249 return strprintf(
"%s %s", GetCommand(), hash.ToString());
250 }
catch (
const std::out_of_range &) {
251 return strprintf(
"0x%08x %s", type, hash.ToString());
265 const uint64_t service_flag = 1ULL << bit;
277 return "NETWORK_LIMITED";
279 return "COMPACT_FILTERS";
283 std::ostringstream stream;
284 stream.imbue(std::locale::classic());
285 stream <<
"UNKNOWN[";
286 stream <<
"2^" << bit;
293 std::vector<std::string> str_flags;
295 for (
size_t i = 0; i <
sizeof(
flags) * 8; ++i) {
296 if (flags & (1ULL << i)) {
const char * GETCFILTERS
getcfilters requests compact filters for a range of blocks.
const char * PING
The ping message is sent periodically to help confirm that the receiving peer is still connected...
const char * FILTERLOAD
The filterload message tells the receiving peer to filter all relayed transactions and requested merk...
const char * MERKLEBLOCK
The merkleblock message is a reply to a getdata message which requested a block using the inventory t...
const char * BLOCKTXN
Contains a BlockTransactions.
static bool CheckHeaderMagicAndCommand(const CMessageHeader &header, const CMessageHeader::MessageMagic &magic)
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH
Maximum length of incoming protocol messages (Currently 2MB).
static const std::string allNetMessageTypes[]
All known message types.
ServiceFlags
nServices flags.
std::string GetCommand() const
std::string ToString() const
const char * GETADDR
The getaddr message requests an addr message from the receiving node, preferably one with lots of IP ...
const char * AVAHELLO
Contains a delegation and a signature.
const char * SENDCMPCT
Contains a 1-byte bool and 8-byte LE version number.
static const std::vector< std::string > allNetMessageTypesVec(allNetMessageTypes, allNetMessageTypes+ARRAYLEN(allNetMessageTypes))
#define ARRAYLEN(array)
Utilities for converting data from/to strings.
const char * CFHEADERS
cfheaders is a response to a getcfheaders request containing a filter header and a vector of filter h...
static void LogPrintf(const char *fmt, const Args &... args)
void SetServiceFlagsIBDCache(bool state)
Set the current IBD status in order to figure out the desirable service flags.
const char * CFILTER
cfilter is a response to a getcfilters request containing a single compact filter.
const char * PONG
The pong message replies to a ping message, proving to the pinging node that the ponging node is stil...
const char * HEADERS
The headers message sends one or more block headers to a node which previously requested certain head...
virtual const CChainParams & GetChainParams() const =0
const char * GETCFCHECKPT
getcfcheckpt requests evenly spaced compact filter headers, enabling parallelized download and valida...
const char * INV
The inv message (inventory message) transmits one or more inventories of objects known to the transmi...
static std::atomic< bool > g_initial_block_download_completed(false)
const char * GETHEADERS
The getheaders message requests a headers message that provides block headers starting from a particu...
virtual uint64_t GetMaxBlockSize() const =0
std::vector< std::string > serviceFlagsToStr(const uint64_t flags)
Convert service flags (a bitmask of NODE_*) to human readable strings.
Bitcoin protocol message types.
A combination of a network address (CNetAddr) and a (TCP) port.
const char * SENDHEADERS
Indicates that a node prefers to receive new block announcements via a "headers" message rather than ...
const char * MEMPOOL
The mempool message requests the TXIDs of transactions that the receiving node has verified as valid ...
static std::string serviceFlagToStr(const size_t bit)
Convert a service flag (NODE_*) to a human readable string.
const std::vector< std::string > & getAllNetMessageTypes()
Get a vector of all valid message types (see above)
const char * ADDR
The addr (IP address) message relays connection information for peers on the network.
const char * FILTERCLEAR
The filterclear message tells the receiving peer to remove a previously-set bloom filter...
const char * NOTFOUND
The notfound message is a reply to a getdata message which requested an object the receiving node doe...
const char * BLOCK
The block message transmits a single serialized block.
const char * FEEFILTER
The feefilter message tells the receiving peer not to inv us any txs which do not meet the specified ...
const char * GETCFHEADERS
getcfheaders requests a compact filter header and the filter hashes for a range of blocks...
const char * GETBLOCKS
The getblocks message requests an inv message that provides block header hashes starting from a parti...
const char * VERACK
The verack message acknowledges a previously-received version message, informing the connecting node ...
const char * AVARESPONSE
Contains an avalanche::Response.
const char * CMPCTBLOCK
Contains a CBlockHeaderAndShortTxIDs object - providing a header and list of "short txids"...
const char * VERSION
The version message provides information about the transmitting node to the receiving node at the beg...
size_t strnlen(const char *start, size_t max_len)
ServiceFlags GetDesirableServiceFlags(ServiceFlags services)
Gets the set of service flags which are "desirable" for a given peer.
const char * GETDATA
The getdata message requests one or more data objects from another node.
const char * AVAPOLL
Contains an avalanche::Poll.
bool IsBlockLike(const std::string &strCommand)
Indicate if the message is used to transmit the content of a block.
const char * CFCHECKPT
cfcheckpt is a response to a getcfcheckpt request containing a vector of evenly spaced filter headers...
const char * TX
The tx message transmits a single transaction.
const CMessageHeader::MessageMagic & NetMagic() const
const char * FILTERADD
The filteradd message tells the receiving peer to add a single element to a previously-set bloom filt...
const char * GETBLOCKTXN
Contains a BlockTransactionsRequest Peer should respond with "blocktxn" message.