6 #ifndef BITCOIN_PROTOCOL_H 7 #define BITCOIN_PROTOCOL_H 65 inline constexpr
const char*
VERSION{
"version"};
70 inline constexpr
const char*
VERACK{
"verack"};
75 inline constexpr
const char*
ADDR{
"addr"};
81 inline constexpr
const char*
ADDRV2{
"addrv2"};
92 inline constexpr
const char*
INV{
"inv"};
96 inline constexpr
const char*
GETDATA{
"getdata"};
117 inline constexpr
const char*
TX{
"tx"};
123 inline constexpr
const char*
HEADERS{
"headers"};
127 inline constexpr
const char*
BLOCK{
"block"};
132 inline constexpr
const char*
GETADDR{
"getaddr"};
139 inline constexpr
const char*
MEMPOOL{
"mempool"};
144 inline constexpr
const char*
PING{
"ping"};
150 inline constexpr
const char*
PONG{
"pong"};
229 inline constexpr
const char*
CFILTER{
"cfilter"};
368 static constexpr std::chrono::seconds
TIME_INIT{100000000};
391 static constexpr uint32_t DISK_VERSION_ADDRV2{1 << 29}; 392 static_assert((DISK_VERSION_INIT & ~DISK_VERSION_IGNORE_MASK) == 0, "DISK_VERSION_INIT must be covered by DISK_VERSION_IGNORE_MASK"); 393 static_assert((DISK_VERSION_ADDRV2 & DISK_VERSION_IGNORE_MASK) == 0, "DISK_VERSION_ADDRV2 must not be covered by DISK_VERSION_IGNORE_MASK"); 396 CAddress() : CService{} {}; 397 CAddress(CService ipIn, ServiceFlags nServicesIn) : CService{ipIn}, nServices{nServicesIn} {}; 398 CAddress(CService ipIn, ServiceFlags nServicesIn, NodeSeconds time) : CService{ipIn}, nTime{time}, nServices{nServicesIn} {}; 404 struct SerParams : CNetAddr::SerParams { 408 static constexpr SerParams V1_NETWORK{{CNetAddr::Encoding::V1}, Format::Network}; 409 static constexpr SerParams V2_NETWORK{{CNetAddr::Encoding::V2}, Format::Network}; 410 static constexpr SerParams V1_DISK{{CNetAddr::Encoding::V1}, Format::Disk}; 411 static constexpr SerParams V2_DISK{{CNetAddr::Encoding::V2}, Format::Disk}; 413 SERIALIZE_METHODS(CAddress, obj) 416 auto& params = SER_PARAMS(SerParams); 417 if (params.fmt == Format::Disk) { 418 // In the disk serialization format, the encoding (v1 or v2) is determined by a flag version 419 // that's part of the serialization itself. ADDRV2_FORMAT in the stream version only determines
425 if (stored_format_version == 0) {
431 throw std::ios_base::failure(
"Unsupported CAddress disk format version");
444 uint64_t services_tmp;
445 SER_WRITE(obj, services_tmp = obj.nServices);
447 SER_READ(obj, obj.nServices = static_cast<ServiceFlags>(services_tmp));
453 READWRITE(ser_params(AsBase<CService>(obj)));
465 static_cast<const CService&
>(a) == static_cast<const CService&>(b);
531 #endif // BITCOIN_PROTOCOL_H
constexpr const char * SENDTXRCNCL
Contains a 4-byte version number and an 8-byte salt.
static constexpr std::chrono::seconds TIME_INIT
constexpr const char * CFHEADERS
cfheaders is a response to a getcfheaders request containing a filter header and a vector of filter h...
ServiceFlags
nServices flags
std::string GetCommand() const
std::string ToString() const
bool IsMsgFilteredBlk() const
constexpr const char * SENDHEADERS
Indicates that a node prefers to receive new block announcements via a "headers" message rather than ...
bool IsMsgCmpctBlk() const
constexpr const char * NOTFOUND
The notfound message is a reply to a getdata message which requested an object the receiving node doe...
constexpr const char * WTXIDRELAY
Indicates that a node prefers to relay transactions via wtxid, rather than txid.
constexpr const char * PING
The ping message is sent periodically to help confirm that the receiving peer is still connected...
GenTxid ToGenTxid(const CInv &inv)
Convert a TX/WITNESS_TX/WTX CInv to a GenTxid.
constexpr const char * HEADERS
The headers message sends one or more block headers to a node which previously requested certain head...
const uint32_t MSG_WITNESS_FLAG
getdata message type flags
constexpr const char * ADDRV2
The addrv2 message relays connection information for peers on the network just like the addr message...
constexpr const char * GETCFILTERS
getcfilters requests compact filters for a range of blocks.
const uint32_t MSG_TYPE_MASK
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class...
constexpr const char * GETCFCHECKPT
getcfcheckpt requests evenly spaced compact filter headers, enabling parallelized download and valida...
constexpr const char * FILTERADD
The filteradd message tells the receiving peer to add a single element to a previously-set bloom filt...
static constexpr uint32_t DISK_VERSION_IGNORE_MASK
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds
std::array< uint8_t, 4 > MessageStartChars
constexpr const char * GETBLOCKS
The getblocks message requests an inv message that provides block header hashes starting from a parti...
constexpr const char * VERSION
The version message provides information about the transmitting node to the receiving node at the beg...
static constexpr uint32_t DISK_VERSION_INIT
Historically, CAddress disk serialization stored the CLIENT_VERSION, optionally OR'ed with the ADDRV2...
constexpr ServiceFlags SeedsServiceFlags()
State independent service flags.
constexpr const char * GETBLOCKTXN
Contains a BlockTransactionsRequest Peer should respond with "blocktxn" message.
constexpr const char * GETHEADERS
The getheaders message requests a headers message that provides block headers starting from a particu...
constexpr const char * SENDADDRV2
The sendaddrv2 message signals support for receiving ADDRV2 messages (BIP155).
constexpr const char * MERKLEBLOCK
The merkleblock message is a reply to a getdata message which requested a block using the inventory t...
Bitcoin protocol message types.
constexpr const char * FILTERCLEAR
The filterclear message tells the receiving peer to remove a previously-set bloom filter...
constexpr const char * VERACK
The verack message acknowledges a previously-received version message, informing the connecting node ...
constexpr const char * CFILTER
cfilter is a response to a getcfilters request containing a single compact filter.
A combination of a network address (CNetAddr) and a (TCP) port.
static constexpr SerParams V1
A CService with information about it as peer.
constexpr const char * GETCFHEADERS
getcfheaders requests a compact filter header and the filter hashes for a range of blocks...
constexpr const char * BLOCK
The block message transmits a single serialized block.
constexpr const char * GETDATA
The getdata message requests one or more data objects from another node.
NodeSeconds nTime
Always included in serialization. The behavior is unspecified if the value is not representable as ui...
bool IsMsgWitnessBlk() const
static bool MayHaveUsefulAddressDB(ServiceFlags services)
Checks if a peer with the given service flags may be capable of having a robust address-storage DB...
constexpr const char * ADDR
The addr (IP address) message relays connection information for peers on the network.
constexpr const char * MEMPOOL
The mempool message requests the TXIDs of transactions that the receiving node has verified as valid ...
constexpr const char * BLOCKTXN
Contains a BlockTransactions.
constexpr const char * CMPCTBLOCK
Contains a CBlockHeaderAndShortTxIDs object - providing a header and list of "short txids"...
ServiceFlags nServices
Serialized as uint64_t in V1, and as CompactSize in V2.
constexpr const char * PONG
The pong message replies to a ping message, proving to the pinging node that the ponging node is stil...
constexpr const char * FILTERLOAD
The filterload message tells the receiving peer to filter all relayed transactions and requested merk...
const std::array ALL_NET_MESSAGE_TYPES
All known message types (see above).
constexpr const char * INV
The inv message (inventory message) transmits one or more inventories of objects known to the transmi...
constexpr const char * CFCHECKPT
cfcheckpt is a response to a getcfcheckpt request containing a vector of evenly spaced filter headers...
std::vector< std::string > serviceFlagsToStr(uint64_t flags)
Convert service flags (a bitmask of NODE_*) to human readable strings.
GetDataMsg
getdata / inv message types.
static constexpr uint32_t DISK_VERSION_ADDRV2
The version number written in disk serialized addresses to indicate V2 serializations.
static constexpr SerParams V2
constexpr const char * TX
The tx message transmits a single transaction.
#define SER_READ(obj, code)
#define SER_WRITE(obj, code)
friend bool operator<(const CInv &a, const CInv &b)
A generic txid reference (txid or wtxid).
constexpr const char * FEEFILTER
The feefilter message tells the receiving peer not to inv us any txs which do not meet the specified ...
constexpr const char * GETADDR
The getaddr message requests an addr message from the receiving node, preferably one with lots of IP ...
constexpr const char * SENDCMPCT
Contains a 1-byte bool and 8-byte LE version number.
friend bool operator==(const CAddress &a, const CAddress &b)
SERIALIZE_METHODS(CInv, obj)