6#ifndef BFI_BITCOIN_NET_NET_ENTITIES_HPP
7#define BFI_BITCOIN_NET_NET_ENTITIES_HPP
9#include <veriblock/bfi/bitcoin/block.hpp>
10#include <veriblock/bfi/bitcoin/serialize.hpp>
17enum ServiceFlags : uint64_t {
26 NODE_NETWORK = (1 << 0),
31 NODE_GETUTXO = (1 << 1),
37 NODE_BLOOM = (1 << 2),
41 NODE_WITNESS = (1 << 3),
46 NODE_NETWORK_LIMITED = (1 << 10),
62 ADD_SERIALIZE_METHODS;
64 template <
typename Stream,
typename Operation>
65 inline void SerializationOp(Stream& s, Operation ser_action) {
70 return (memcmp(a.ip, b.ip, 16) == 0);
85 ADD_SERIALIZE_METHODS;
87 template <
typename Stream,
typename Operation>
88 inline void SerializationOp(Stream& s, Operation ser_action) {
89 READWRITE(this->network);
90 READWRITE(this->netmask);
91 READWRITE(this->valid);
94 friend bool operator==(
const SubNet& a,
const SubNet& b) {
98 friend bool operator!=(
const SubNet& a,
const SubNet& b) {
return !(a == b); }
105 ADD_SERIALIZE_METHODS;
107 template <
typename Stream,
typename Operation>
108 inline void SerializationOp(Stream& s, Operation ser_action) {
110 READWRITE(WrapBigEndian(this->port));
122 ServiceFlags nServices;
126 ADD_SERIALIZE_METHODS;
128 template <
typename Stream,
typename Operation>
129 inline void SerializationOp(Stream& s, Operation ser_action) {
130 uint64_t nServicesInt = nServices;
132 READWRITE(nServicesInt);
133 nServices =
static_cast<ServiceFlags
>(nServicesInt);
151 ADD_SERIALIZE_METHODS;
153 template <
typename Stream,
typename Operation>
154 inline void SerializationOp(Stream& s, Operation ser_action) {
155 READWRITE(this->nVersion);
156 READWRITE(this->nCreateTime);
157 READWRITE(this->nBanUntil);
158 READWRITE(this->banReason);
162 return a.nVersion == b.nVersion && a.nCreateTime == b.nCreateTime &&
163 a.nBanUntil == b.nBanUntil && a.banReason == b.banReason;
174 ADD_SERIALIZE_METHODS;
176 template <
typename Stream,
typename Operation>
177 inline void SerializationOp(Stream& s, Operation ser_action) {
178 READWRITE(this->type);
179 READWRITE(this->hash);
182 friend bool operator==(
const Inv& a,
const Inv& b) {
183 return a.type == b.type && a.hash == b.hash;
185 friend bool operator!=(
const Inv& a,
const Inv& b) {
return !(a == b); }
190 std::vector<uint16_t> indexes;
192 ADD_SERIALIZE_METHODS;
194 template <
typename Stream,
typename Operation>
195 inline void SerializationOp(Stream& s, Operation ser_action) {
196 READWRITE(this->blockhash);
197 uint64_t indexes_size = (uint64_t)this->indexes.size();
198 READWRITE(COMPACTSIZE(indexes_size));
199 if (ser_action.ForRead()) {
201 while (indexes.size() < indexes_size) {
202 this->indexes.resize(
203 std::min((uint64_t)(1000 + this->indexes.size()), indexes_size));
204 for (; i < this->indexes.size(); ++i) {
206 READWRITE(COMPACTSIZE(index));
207 if (index > std::numeric_limits<uint16_t>::max()) {
208 throw std::ios_base::failure(
"index overflowed 16 bits");
210 this->indexes[i] = (uint16_t)index;
215 for (
size_t j = 0; j < this->indexes.size(); j++) {
216 if (int32_t(this->indexes[j]) + offset >
217 std::numeric_limits<uint16_t>::max())
218 throw std::ios_base::failure(
"indexes overflowed 16 bits");
219 this->indexes[j] = this->indexes[j] + (uint16_t)offset;
220 offset = int32_t(this->indexes[j]) + 1;
223 for (
size_t i = 0; i < this->indexes.size(); i++) {
225 this->indexes[i] - (i == 0 ? 0 : (this->indexes[i - 1] + 1));
226 READWRITE(COMPACTSIZE(index));
233 return a.blockhash == b.blockhash && a.indexes == b.indexes;
249 ADD_SERIALIZE_METHODS;
251 template <
typename Stream,
typename Operation>
252 inline void SerializationOp(Stream& s, Operation ser_action) {
253 uint64_t idx = this->index;
254 READWRITE(COMPACTSIZE(idx));
255 if (idx > std::numeric_limits<uint16_t>::max()) {
256 throw std::ios_base::failure(
"index overflowed 16-bits");
258 index = (uint16_t)idx;
264 return a.index == b.index && a.tx == b.tx;
273 static const uint32_t SHORTTXIDS_LENGTH = 6;
277 std::vector<uint64_t> shorttxids;
278 std::vector<PrefilledTransaction> prefilledtxn;
280 ADD_SERIALIZE_METHODS;
282 template <
typename Stream,
typename Operation>
283 inline void SerializationOp(Stream& s, Operation ser_action) {
284 READWRITE(this->header);
285 READWRITE(this->nonce);
287 uint64_t shorttxids_size = (uint64_t)this->shorttxids.size();
288 READWRITE(COMPACTSIZE(shorttxids_size));
289 if (ser_action.ForRead()) {
291 while (this->shorttxids.size() < shorttxids_size) {
292 this->shorttxids.resize(std::min(
293 (uint64_t)(1000 + this->shorttxids.size()), shorttxids_size));
294 for (; i < shorttxids.size(); i++) {
299 this->shorttxids[i] = (uint64_t(msb) << 32) | uint64_t(lsb);
303 for (
size_t i = 0; i < this->shorttxids.size(); i++) {
304 uint32_t lsb = this->shorttxids[i] & 0xffffffff;
305 uint16_t msb = (this->shorttxids[i] >> 32) & 0xffff;
311 READWRITE(this->prefilledtxn);
313 if (this->shorttxids.size() + this->prefilledtxn.size() >
314 std::numeric_limits<uint16_t>::max()) {
315 throw std::ios_base::failure(
"indexes overflowed 16 bits");
321 return a.header == b.header && a.nonce == b.nonce &&
322 a.shorttxids == b.shorttxids && a.prefilledtxn == b.prefilledtxn;
333 std::vector<Transaction> txn;
335 ADD_SERIALIZE_METHODS;
337 template <
typename Stream,
typename Operation>
338 inline void SerializationOp(Stream& s, Operation ser_action) {
339 READWRITE(this->blockhash);
340 uint64_t txn_size = (uint64_t)this->txn.size();
341 READWRITE(COMPACTSIZE(txn_size));
342 if (ser_action.ForRead()) {
344 while (this->txn.size() < txn_size) {
346 std::min((uint64_t)(1000 + this->txn.size()), txn_size));
347 for (; i < this->txn.size(); i++) {
348 READWRITE(this->txn[i]);
352 for (
size_t i = 0; i < txn.size(); i++) {
353 READWRITE(this->txn[i]);
360 return a.blockhash == b.blockhash && a.txn == b.txn;
369 std::vector<uint8_t> vData;
374 ADD_SERIALIZE_METHODS;
376 template <
typename Stream,
typename Operation>
377 inline void SerializationOp(Stream& s, Operation ser_action) {
378 READWRITE(this->vData);
379 READWRITE(this->nHashFuncs);
380 READWRITE(this->nTweak);
381 READWRITE(this->nFlags);
385 return a.vData == b.vData && a.nHashFuncs == b.nHashFuncs &&
386 a.nTweak == b.nTweak && a.nFlags == b.nFlags;
IP address (IPv6, or IPv4 using mapped IPv6 range.
A combination of a network address (CNetAddr) and a (TCP) port.
bool valid
Is this value valid? (only used to signal parse errors)
NetAddr network
Network (base) address.
uint8_t netmask[16]
Netmask, in network byte order.
The basic transaction that is broadcasted on the network and contained in blocks.