Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Namespaces | Enumerations | Functions | Variables
protocol.h File Reference
#include <kernel/messagestartchars.h>
#include <netaddress.h>
#include <primitives/transaction.h>
#include <serialize.h>
#include <streams.h>
#include <uint256.h>
#include <util/time.h>
#include <array>
#include <cstdint>
#include <limits>
#include <string>
Include dependency graph for protocol.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CMessageHeader
 Message header. More...
 
class  CAddress
 A CService with information about it as peer. More...
 
struct  CAddress::SerParams
 
class  CInv
 inv message data More...
 

Namespaces

namespace  NetMsgType
 Bitcoin protocol message types.
 

Enumerations

enum  ServiceFlags : uint64_t {
  NODE_NONE = 0 , NODE_NETWORK = (1 << 0) , NODE_BLOOM = (1 << 2) , NODE_WITNESS = (1 << 3) ,
  NODE_COMPACT_FILTERS = (1 << 6) , NODE_NETWORK_LIMITED = (1 << 10) , NODE_P2P_V2 = (1 << 11)
}
 nServices flags More...
 
enum  GetDataMsg : uint32_t {
  UNDEFINED = 0 , MSG_TX = 1 , MSG_BLOCK = 2 , MSG_WTX = 5 ,
  MSG_FILTERED_BLOCK = 3 , MSG_CMPCT_BLOCK = 4 , MSG_WITNESS_BLOCK = MSG_BLOCK | MSG_WITNESS_FLAG , MSG_WITNESS_TX = MSG_TX | MSG_WITNESS_FLAG
}
 getdata / inv message types. More...
 

Functions

std::vector< std::string > serviceFlagsToStr (uint64_t flags)
 Convert service flags (a bitmask of NODE_*) to human readable strings. More...
 
constexpr ServiceFlags SeedsServiceFlags ()
 State independent service flags. More...
 
static bool MayHaveUsefulAddressDB (ServiceFlags services)
 Checks if a peer with the given service flags may be capable of having a robust address-storage DB. More...
 
GenTxid ToGenTxid (const CInv &inv)
 Convert a TX/WITNESS_TX/WTX CInv to a GenTxid. More...
 

Variables

constexpr const char * NetMsgType::VERSION {"version"}
 The version message provides information about the transmitting node to the receiving node at the beginning of a connection. More...
 
constexpr const char * NetMsgType::VERACK {"verack"}
 The verack message acknowledges a previously-received version message, informing the connecting node that it can begin to send other messages. More...
 
constexpr const char * NetMsgType::ADDR {"addr"}
 The addr (IP address) message relays connection information for peers on the network. More...
 
constexpr const char * NetMsgType::ADDRV2 {"addrv2"}
 The addrv2 message relays connection information for peers on the network just like the addr message, but is extended to allow gossiping of longer node addresses (see BIP155). More...
 
constexpr const char * NetMsgType::SENDADDRV2 {"sendaddrv2"}
 The sendaddrv2 message signals support for receiving ADDRV2 messages (BIP155). More...
 
constexpr const char * NetMsgType::INV {"inv"}
 The inv message (inventory message) transmits one or more inventories of objects known to the transmitting peer. More...
 
constexpr const char * NetMsgType::GETDATA {"getdata"}
 The getdata message requests one or more data objects from another node. More...
 
constexpr const char * NetMsgType::MERKLEBLOCK {"merkleblock"}
 The merkleblock message is a reply to a getdata message which requested a block using the inventory type MSG_MERKLEBLOCK. More...
 
constexpr const char * NetMsgType::GETBLOCKS {"getblocks"}
 The getblocks message requests an inv message that provides block header hashes starting from a particular point in the block chain. More...
 
constexpr const char * NetMsgType::GETHEADERS {"getheaders"}
 The getheaders message requests a headers message that provides block headers starting from a particular point in the block chain. More...
 
constexpr const char * NetMsgType::TX {"tx"}
 The tx message transmits a single transaction. More...
 
constexpr const char * NetMsgType::HEADERS {"headers"}
 The headers message sends one or more block headers to a node which previously requested certain headers with a getheaders message. More...
 
constexpr const char * NetMsgType::BLOCK {"block"}
 The block message transmits a single serialized block. More...
 
constexpr const char * NetMsgType::GETADDR {"getaddr"}
 The getaddr message requests an addr message from the receiving node, preferably one with lots of IP addresses of other receiving nodes. More...
 
constexpr const char * NetMsgType::MEMPOOL {"mempool"}
 The mempool message requests the TXIDs of transactions that the receiving node has verified as valid but which have not yet appeared in a block. More...
 
constexpr const char * NetMsgType::PING {"ping"}
 The ping message is sent periodically to help confirm that the receiving peer is still connected. More...
 
constexpr const char * NetMsgType::PONG {"pong"}
 The pong message replies to a ping message, proving to the pinging node that the ponging node is still alive. More...
 
constexpr const char * NetMsgType::NOTFOUND {"notfound"}
 The notfound message is a reply to a getdata message which requested an object the receiving node does not have available for relay. More...
 
constexpr const char * NetMsgType::FILTERLOAD {"filterload"}
 The filterload message tells the receiving peer to filter all relayed transactions and requested merkle blocks through the provided filter. More...
 
constexpr const char * NetMsgType::FILTERADD {"filteradd"}
 The filteradd message tells the receiving peer to add a single element to a previously-set bloom filter, such as a new public key. More...
 
constexpr const char * NetMsgType::FILTERCLEAR {"filterclear"}
 The filterclear message tells the receiving peer to remove a previously-set bloom filter. More...
 
constexpr const char * NetMsgType::SENDHEADERS {"sendheaders"}
 Indicates that a node prefers to receive new block announcements via a "headers" message rather than an "inv". More...
 
constexpr const char * NetMsgType::FEEFILTER {"feefilter"}
 The feefilter message tells the receiving peer not to inv us any txs which do not meet the specified min fee rate. More...
 
constexpr const char * NetMsgType::SENDCMPCT {"sendcmpct"}
 Contains a 1-byte bool and 8-byte LE version number. More...
 
constexpr const char * NetMsgType::CMPCTBLOCK {"cmpctblock"}
 Contains a CBlockHeaderAndShortTxIDs object - providing a header and list of "short txids". More...
 
constexpr const char * NetMsgType::GETBLOCKTXN {"getblocktxn"}
 Contains a BlockTransactionsRequest Peer should respond with "blocktxn" message. More...
 
constexpr const char * NetMsgType::BLOCKTXN {"blocktxn"}
 Contains a BlockTransactions. More...
 
constexpr const char * NetMsgType::GETCFILTERS {"getcfilters"}
 getcfilters requests compact filters for a range of blocks. More...
 
constexpr const char * NetMsgType::CFILTER {"cfilter"}
 cfilter is a response to a getcfilters request containing a single compact filter. More...
 
constexpr const char * NetMsgType::GETCFHEADERS {"getcfheaders"}
 getcfheaders requests a compact filter header and the filter hashes for a range of blocks, which can then be used to reconstruct the filter headers for those blocks. More...
 
constexpr const char * NetMsgType::CFHEADERS {"cfheaders"}
 cfheaders is a response to a getcfheaders request containing a filter header and a vector of filter hashes for each subsequent block in the requested range. More...
 
constexpr const char * NetMsgType::GETCFCHECKPT {"getcfcheckpt"}
 getcfcheckpt requests evenly spaced compact filter headers, enabling parallelized download and validation of the headers between them. More...
 
constexpr const char * NetMsgType::CFCHECKPT {"cfcheckpt"}
 cfcheckpt is a response to a getcfcheckpt request containing a vector of evenly spaced filter headers for blocks on the requested chain. More...
 
constexpr const char * NetMsgType::WTXIDRELAY {"wtxidrelay"}
 Indicates that a node prefers to relay transactions via wtxid, rather than txid. More...
 
constexpr const char * NetMsgType::SENDTXRCNCL {"sendtxrcncl"}
 Contains a 4-byte version number and an 8-byte salt. More...
 
const std::array ALL_NET_MESSAGE_TYPES
 All known message types (see above). More...
 
const uint32_t MSG_WITNESS_FLAG = 1 << 30
 getdata message type flags More...
 
const uint32_t MSG_TYPE_MASK = 0xffffffff >> 2
 

Enumeration Type Documentation

◆ GetDataMsg

enum GetDataMsg : uint32_t

getdata / inv message types.

These numbers are defined by the protocol. When adding a new value, be sure to mention it in the respective BIP.

Enumerator
UNDEFINED 
MSG_TX 
MSG_BLOCK 
MSG_WTX 

Defined in BIP 339.

MSG_FILTERED_BLOCK 

Defined in BIP37.

MSG_CMPCT_BLOCK 

Defined in BIP152.

MSG_WITNESS_BLOCK 

Defined in BIP144.

MSG_WITNESS_TX 

Defined in BIP144.

Definition at line 477 of file protocol.h.

◆ ServiceFlags

enum ServiceFlags : uint64_t

nServices flags

Enumerator
NODE_NONE 
NODE_NETWORK 
NODE_BLOOM 
NODE_WITNESS 
NODE_COMPACT_FILTERS 
NODE_NETWORK_LIMITED 
NODE_P2P_V2 

Definition at line 309 of file protocol.h.

Function Documentation

◆ MayHaveUsefulAddressDB()

static bool MayHaveUsefulAddressDB ( ServiceFlags  services)
inlinestatic

Checks if a peer with the given service flags may be capable of having a robust address-storage DB.

Definition at line 360 of file protocol.h.

Here is the caller graph for this function:

◆ SeedsServiceFlags()

constexpr ServiceFlags SeedsServiceFlags ( )
constexpr

State independent service flags.

If the return value is changed, contrib/seeds/makeseeds.py should be updated appropriately to filter for nodes with desired service flags (compatible with our new flags).

Definition at line 354 of file protocol.h.

Here is the caller graph for this function:

◆ serviceFlagsToStr()

std::vector< std::string > serviceFlagsToStr ( uint64_t  flags)

Convert service flags (a bitmask of NODE_*) to human readable strings.

It supports unknown service flags which will be returned as "UNKNOWN[...]".

Parameters
[in]flagsmultiple NODE_* bitwise-OR-ed together

Definition at line 108 of file protocol.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToGenTxid()

GenTxid ToGenTxid ( const CInv inv)

Convert a TX/WITNESS_TX/WTX CInv to a GenTxid.

Definition at line 121 of file protocol.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ALL_NET_MESSAGE_TYPES

const std::array ALL_NET_MESSAGE_TYPES
inline

All known message types (see above).

Keep this in the same order as the list of messages above.

Definition at line 270 of file protocol.h.

◆ MSG_TYPE_MASK

const uint32_t MSG_TYPE_MASK = 0xffffffff >> 2

Definition at line 471 of file protocol.h.

◆ MSG_WITNESS_FLAG

const uint32_t MSG_WITNESS_FLAG = 1 << 30

getdata message type flags

Definition at line 470 of file protocol.h.