Bitcoin Core 22.99.0
P2P Digital Currency
netaddress.h
Go to the documentation of this file.
1// Copyright (c) 2009-2020 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_NETADDRESS_H
6#define BITCOIN_NETADDRESS_H
7
8#if defined(HAVE_CONFIG_H)
10#endif
11
12#include <attributes.h>
13#include <compat.h>
14#include <crypto/siphash.h>
15#include <prevector.h>
16#include <random.h>
17#include <serialize.h>
18#include <tinyformat.h>
19#include <util/strencodings.h>
20#include <util/string.h>
21
22#include <array>
23#include <cstdint>
24#include <ios>
25#include <string>
26#include <vector>
27
34static constexpr int ADDRV2_FORMAT = 0x20000000;
35
45enum Network {
48
51
54
57
60
63
67
70};
71
74static const std::array<uint8_t, 12> IPV4_IN_IPV6_PREFIX{
75 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF};
76
81static const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX{
82 0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43};
83
89static const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX{
90 0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24 // 0xFD + sha256("bitcoin")[0:5].
91};
92
94static constexpr size_t ADDR_IPV4_SIZE = 4;
95
97static constexpr size_t ADDR_IPV6_SIZE = 16;
98
101static constexpr size_t ADDR_TORV3_SIZE = 32;
102
104static constexpr size_t ADDR_I2P_SIZE = 32;
105
107static constexpr size_t ADDR_CJDNS_SIZE = 16;
108
110static constexpr size_t ADDR_INTERNAL_SIZE = 10;
111
113static constexpr uint16_t I2P_SAM31_PORT{0};
114
119{
120protected:
126
131
136 uint32_t m_scope_id{0};
137
138public:
139 CNetAddr();
140 explicit CNetAddr(const struct in_addr& ipv4Addr);
141 void SetIP(const CNetAddr& ip);
142
150
151 bool SetInternal(const std::string& name);
152
161 bool SetSpecial(const std::string& addr);
162
163 bool IsBindAny() const; // INADDR_ANY equivalent
164 bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
165 bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor)
166 bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
167 bool IsRFC2544() const; // IPv4 inter-network communications (198.18.0.0/15)
168 bool IsRFC6598() const; // IPv4 ISP-level NAT (100.64.0.0/10)
169 bool IsRFC5737() const; // IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24)
170 bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32)
171 bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16)
172 bool IsRFC3964() const; // IPv6 6to4 tunnelling (2002::/16)
173 bool IsRFC4193() const; // IPv6 unique local (FC00::/7)
174 bool IsRFC4380() const; // IPv6 Teredo tunnelling (2001::/32)
175 bool IsRFC4843() const; // IPv6 ORCHID (deprecated) (2001:10::/28)
176 bool IsRFC7343() const; // IPv6 ORCHIDv2 (2001:20::/28)
177 bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64)
178 bool IsRFC6052() const; // IPv6 well-known prefix for IPv4-embedded address (64:FF9B::/96)
179 bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) (actually defined in RFC2765)
180 bool IsHeNet() const; // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
181 bool IsTor() const;
182 bool IsI2P() const;
183 bool IsCJDNS() const;
184 bool IsLocal() const;
185 bool IsRoutable() const;
186 bool IsInternal() const;
187 bool IsValid() const;
188
192 bool IsAddrV1Compatible() const;
193
194 enum Network GetNetwork() const;
195 std::string ToString() const;
196 std::string ToStringIP() const;
197 uint64_t GetHash() const;
198 bool GetInAddr(struct in_addr* pipv4Addr) const;
199 Network GetNetClass() const;
200
202 uint32_t GetLinkedIPv4() const;
204 bool HasLinkedIPv4() const;
205
206 // The AS on the BGP path to the node we use to diversify
207 // peers in AddrMan bucketing based on the AS infrastructure.
208 // The ip->AS mapping depends on how asmap is constructed.
209 uint32_t GetMappedAS(const std::vector<bool>& asmap) const;
210
211 std::vector<unsigned char> GetGroup(const std::vector<bool>& asmap) const;
212 std::vector<unsigned char> GetAddrBytes() const;
213 int GetReachabilityFrom(const CNetAddr* paddrPartner = nullptr) const;
214
215 explicit CNetAddr(const struct in6_addr& pipv6Addr, const uint32_t scope = 0);
216 bool GetIn6Addr(struct in6_addr* pipv6Addr) const;
217
218 friend bool operator==(const CNetAddr& a, const CNetAddr& b);
219 friend bool operator!=(const CNetAddr& a, const CNetAddr& b) { return !(a == b); }
220 friend bool operator<(const CNetAddr& a, const CNetAddr& b);
221
225 bool IsRelayable() const
226 {
227 return IsIPv4() || IsIPv6() || IsTor() || IsI2P() || IsCJDNS();
228 }
229
233 template <typename Stream>
234 void Serialize(Stream& s) const
235 {
236 if (s.GetVersion() & ADDRV2_FORMAT) {
238 } else {
240 }
241 }
242
246 template <typename Stream>
247 void Unserialize(Stream& s)
248 {
249 if (s.GetVersion() & ADDRV2_FORMAT) {
251 } else {
253 }
254 }
255
256 friend class CSubNet;
257
258private:
266 bool SetTor(const std::string& addr);
267
275 bool SetI2P(const std::string& addr);
276
280 enum BIP155Network : uint8_t {
281 IPV4 = 1,
282 IPV6 = 2,
283 TORV2 = 3,
284 TORV3 = 4,
285 I2P = 5,
286 CJDNS = 6,
287 };
288
292 static constexpr size_t V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE;
293
299 static constexpr size_t MAX_ADDRV2_SIZE = 512;
300
307
315 bool SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size);
316
320 void SerializeV1Array(uint8_t (&arr)[V1_SERIALIZATION_SIZE]) const
321 {
322 size_t prefix_size;
323
324 switch (m_net) {
325 case NET_IPV6:
326 assert(m_addr.size() == sizeof(arr));
327 memcpy(arr, m_addr.data(), m_addr.size());
328 return;
329 case NET_IPV4:
330 prefix_size = sizeof(IPV4_IN_IPV6_PREFIX);
331 assert(prefix_size + m_addr.size() == sizeof(arr));
332 memcpy(arr, IPV4_IN_IPV6_PREFIX.data(), prefix_size);
333 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
334 return;
335 case NET_INTERNAL:
336 prefix_size = sizeof(INTERNAL_IN_IPV6_PREFIX);
337 assert(prefix_size + m_addr.size() == sizeof(arr));
338 memcpy(arr, INTERNAL_IN_IPV6_PREFIX.data(), prefix_size);
339 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
340 return;
341 case NET_ONION:
342 case NET_I2P:
343 case NET_CJDNS:
344 break;
345 case NET_UNROUTABLE:
346 case NET_MAX:
347 assert(false);
348 } // no default case, so the compiler can warn about missing cases
349
350 // Serialize ONION, I2P and CJDNS as all-zeros.
351 memset(arr, 0x0, V1_SERIALIZATION_SIZE);
352 }
353
357 template <typename Stream>
358 void SerializeV1Stream(Stream& s) const
359 {
360 uint8_t serialized[V1_SERIALIZATION_SIZE];
361
362 SerializeV1Array(serialized);
363
364 s << serialized;
365 }
366
370 template <typename Stream>
371 void SerializeV2Stream(Stream& s) const
372 {
373 if (IsInternal()) {
374 // Serialize NET_INTERNAL as embedded in IPv6. We need to
375 // serialize such addresses from addrman.
376 s << static_cast<uint8_t>(BIP155Network::IPV6);
379 return;
380 }
381
382 s << static_cast<uint8_t>(GetBIP155Network());
383 s << m_addr;
384 }
385
390 {
391 // Use SetLegacyIPv6() so that m_net is set correctly. For example
392 // ::FFFF:0102:0304 should be set as m_net=NET_IPV4 (1.2.3.4).
393 SetLegacyIPv6(arr);
394 }
395
399 template <typename Stream>
400 void UnserializeV1Stream(Stream& s)
401 {
402 uint8_t serialized[V1_SERIALIZATION_SIZE];
403
404 s >> serialized;
405
406 UnserializeV1Array(serialized);
407 }
408
412 template <typename Stream>
413 void UnserializeV2Stream(Stream& s)
414 {
415 uint8_t bip155_net;
416 s >> bip155_net;
417
418 size_t address_size;
419 s >> COMPACTSIZE(address_size);
420
421 if (address_size > MAX_ADDRV2_SIZE) {
422 throw std::ios_base::failure(strprintf(
423 "Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
424 }
425
426 m_scope_id = 0;
427
428 if (SetNetFromBIP155Network(bip155_net, address_size)) {
429 m_addr.resize(address_size);
430 s >> MakeSpan(m_addr);
431
432 if (m_net != NET_IPV6) {
433 return;
434 }
435
436 // Do some special checks on IPv6 addresses.
437
438 // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
439 // gossiped but could be coming from addrman, when unserializing from
440 // disk.
443 memmove(m_addr.data(), m_addr.data() + INTERNAL_IN_IPV6_PREFIX.size(),
446 return;
447 }
448
451 return;
452 }
453
454 // IPv4 and TORv2 are not supposed to be embedded in IPv6 (like in V1
455 // encoding). Unserialize as !IsValid(), thus ignoring them.
456 } else {
457 // If we receive an unknown BIP155 network id (from the future?) then
458 // ignore the address - unserialize as !IsValid().
459 s.ignore(address_size);
460 }
461
462 // Mimic a default-constructed CNetAddr object which is !IsValid() and thus
463 // will not be gossiped, but continue reading next addresses from the stream.
464 m_net = NET_IPV6;
465 m_addr.assign(ADDR_IPV6_SIZE, 0x0);
466 }
467};
468
470{
471protected:
475 uint8_t netmask[16];
477 bool valid;
478
479 bool SanityCheck() const;
480
481public:
485 CSubNet();
486
494 CSubNet(const CNetAddr& addr, uint8_t mask);
495
503 CSubNet(const CNetAddr& addr, const CNetAddr& mask);
504
509 explicit CSubNet(const CNetAddr& addr);
510
511 bool Match(const CNetAddr& addr) const;
512
513 std::string ToString() const;
514 bool IsValid() const;
515
516 friend bool operator==(const CSubNet& a, const CSubNet& b);
517 friend bool operator!=(const CSubNet& a, const CSubNet& b) { return !(a == b); }
518 friend bool operator<(const CSubNet& a, const CSubNet& b);
519};
520
522class CService : public CNetAddr
523{
524protected:
525 uint16_t port; // host order
526
527public:
528 CService();
529 CService(const CNetAddr& ip, uint16_t port);
530 CService(const struct in_addr& ipv4Addr, uint16_t port);
531 explicit CService(const struct sockaddr_in& addr);
532 uint16_t GetPort() const;
533 bool GetSockAddr(struct sockaddr* paddr, socklen_t* addrlen) const;
534 bool SetSockAddr(const struct sockaddr* paddr);
535 friend bool operator==(const CService& a, const CService& b);
536 friend bool operator!=(const CService& a, const CService& b) { return !(a == b); }
537 friend bool operator<(const CService& a, const CService& b);
538 std::vector<unsigned char> GetKey() const;
539 std::string ToString() const;
540 std::string ToStringPort() const;
541 std::string ToStringIPPort() const;
542
543 CService(const struct in6_addr& ipv6Addr, uint16_t port);
544 explicit CService(const struct sockaddr_in6& addr);
545
547 {
548 READWRITEAS(CNetAddr, obj);
550 }
551
552 friend class CServiceHash;
553 friend CService MaybeFlipIPv6toCJDNS(const CService& service);
554};
555
557{
558public:
559 size_t operator()(const CService& a) const noexcept
560 {
562 hasher.Write(a.m_net);
563 hasher.Write(a.port);
564 hasher.Write(a.m_addr.data(), a.m_addr.size());
565 return static_cast<size_t>(hasher.Finalize());
566 }
567
568private:
569 const uint64_t m_salt_k0 = GetRand(std::numeric_limits<uint64_t>::max());
570 const uint64_t m_salt_k1 = GetRand(std::numeric_limits<uint64_t>::max());
571};
572
573#endif // BITCOIN_NETADDRESS_H
Network address.
Definition: netaddress.h:119
Network GetNetClass() const
Definition: netaddress.cpp:707
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition: netaddress.h:320
bool IsRelayable() const
Whether this address should be relayed to other peers even if we can't reach it ourselves.
Definition: netaddress.h:225
std::string ToStringIP() const
Definition: netaddress.cpp:608
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
Definition: netaddress.h:371
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
Definition: netaddress.h:125
bool IsBindAny() const
Definition: netaddress.cpp:310
bool IsRFC6052() const
Definition: netaddress.cpp:362
void SetIP(const CNetAddr &ip)
Definition: netaddress.cpp:107
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:212
bool IsRFC7343() const
Definition: netaddress.cpp:398
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Try to get our IPv6 (or CJDNS) address.
Definition: netaddress.cpp:675
std::vector< unsigned char > GetAddrBytes() const
Definition: netaddress.cpp:826
std::string ToString() const
Definition: netaddress.cpp:631
bool IsCJDNS() const
Check whether this object represents a CJDNS address.
Definition: netaddress.cpp:423
bool IsTor() const
Check whether this object represents a TOR address.
Definition: netaddress.cpp:413
bool IsRoutable() const
Definition: netaddress.cpp:490
bool GetInAddr(struct in_addr *pipv4Addr) const
Try to get our IPv4 address.
Definition: netaddress.cpp:656
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition: netaddress.cpp:685
Network m_net
Network to which this address belongs.
Definition: netaddress.h:130
bool IsRFC5737() const
Definition: netaddress.cpp:345
void SetLegacyIPv6(Span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Definition: netaddress.cpp:138
bool SetI2P(const std::string &addr)
Parse an I2P address and set this object to it.
Definition: netaddress.cpp:269
void UnserializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE])
Unserialize from a pre-ADDRv2/BIP155 format from an array.
Definition: netaddress.h:389
bool IsRFC6598() const
Definition: netaddress.cpp:340
bool IsRFC1918() const
Definition: netaddress.cpp:322
friend bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:636
bool IsValid() const
Definition: netaddress.cpp:451
bool IsIPv4() const
Definition: netaddress.cpp:318
BIP155Network GetBIP155Network() const
Get the BIP155 network id of this address.
Definition: netaddress.cpp:27
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
Definition: netaddress.cpp:690
bool SetTor(const std::string &addr)
Parse a Tor address and set this object to it.
Definition: netaddress.cpp:229
void SerializeV1Stream(Stream &s) const
Serialize in pre-ADDRv2/BIP155 format to a stream.
Definition: netaddress.h:358
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
Definition: netaddress.h:136
bool IsRFC3849() const
Definition: netaddress.cpp:352
bool IsHeNet() const
Definition: netaddress.cpp:404
void Serialize(Stream &s) const
Serialize to a stream.
Definition: netaddress.h:234
bool IsLocal() const
Definition: netaddress.cpp:425
void Unserialize(Stream &s)
Unserialize from a stream.
Definition: netaddress.h:247
uint64_t GetHash() const
Definition: netaddress.cpp:836
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition: netaddress.h:292
bool IsIPv6() const
Definition: netaddress.cpp:320
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition: netaddress.h:400
bool IsInternal() const
Definition: netaddress.cpp:500
bool SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size)
Set m_net from the provided BIP155 network id and size after validation.
Definition: netaddress.cpp:49
bool SetInternal(const std::string &name)
Create an "internal" address that represents a name or FQDN.
Definition: netaddress.cpp:173
bool IsRFC4193() const
Definition: netaddress.cpp:380
friend bool operator!=(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.h:219
std::vector< unsigned char > GetGroup(const std::vector< bool > &asmap) const
Get the canonical identifier of our network group.
Definition: netaddress.cpp:766
uint32_t GetMappedAS(const std::vector< bool > &asmap) const
Definition: netaddress.cpp:725
int GetReachabilityFrom(const CNetAddr *paddrPartner=nullptr) const
Calculates a metric for how reachable (*this) is from a given partner.
Definition: netaddress.cpp:858
static constexpr size_t MAX_ADDRV2_SIZE
Maximum size of an address as defined in BIP155 (in bytes).
Definition: netaddress.h:299
bool IsRFC2544() const
Definition: netaddress.cpp:330
enum Network GetNetwork() const
Definition: netaddress.cpp:524
bool IsRFC6145() const
Definition: netaddress.cpp:385
CNetAddr()
Construct an unspecified IPv6 network address (::/128).
Definition: netaddress.cpp:105
bool IsRFC3964() const
Definition: netaddress.cpp:357
void UnserializeV2Stream(Stream &s)
Unserialize from a ADDRv2 / BIP155 format.
Definition: netaddress.h:413
bool IsRFC4380() const
Definition: netaddress.cpp:369
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:641
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:505
BIP155Network
BIP155 network ids recognized by this software.
Definition: netaddress.h:280
bool IsRFC3927() const
Definition: netaddress.cpp:335
bool IsRFC4862() const
Definition: netaddress.cpp:374
bool IsRFC4843() const
Definition: netaddress.cpp:392
bool IsI2P() const
Check whether this object represents an I2P address.
Definition: netaddress.cpp:418
size_t operator()(const CService &a) const noexcept
Definition: netaddress.h:559
const uint64_t m_salt_k0
Definition: netaddress.h:569
const uint64_t m_salt_k1
Definition: netaddress.h:570
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:523
SERIALIZE_METHODS(CService, obj)
Definition: netaddress.h:546
std::string ToStringIPPort() const
std::string ToString() const
friend bool operator<(const CService &a, const CService &b)
Definition: netaddress.cpp:976
friend bool operator!=(const CService &a, const CService &b)
Definition: netaddress.h:536
uint16_t GetPort() const
Definition: netaddress.cpp:966
bool SetSockAddr(const struct sockaddr *paddr)
Definition: netaddress.cpp:952
friend bool operator==(const CService &a, const CService &b)
Definition: netaddress.cpp:971
std::string ToStringPort() const
friend CService MaybeFlipIPv6toCJDNS(const CService &service)
If an IPv6 address belongs to the address range used by the CJDNS network and the CJDNS network is re...
Definition: net.cpp:240
uint16_t port
Definition: netaddress.h:525
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
Definition: netaddress.cpp:993
std::vector< unsigned char > GetKey() const
SipHash-2-4.
Definition: siphash.h:14
uint64_t Finalize() const
Compute the 64-bit SipHash-2-4 of the data written so far.
Definition: siphash.cpp:76
CSipHasher & Write(uint64_t data)
Hash a 64-bit integer worth of data It is treated as if this was the little-endian interpretation of ...
Definition: siphash.cpp:28
friend bool operator!=(const CSubNet &a, const CSubNet &b)
Definition: netaddress.h:517
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:477
CNetAddr network
Network (base) address.
Definition: netaddress.h:473
bool SanityCheck() const
friend bool operator==(const CSubNet &a, const CSubNet &b)
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:475
std::string ToString() const
bool IsValid() const
friend bool operator<(const CSubNet &a, const CSubNet &b)
CSubNet()
Construct an invalid subnet (empty, Match() always returns false).
bool Match(const CNetAddr &addr) const
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:93
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition: prevector.h:37
static CService ip(uint32_t i)
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
Definition: netaddress.h:107
static constexpr int ADDRV2_FORMAT
A flag that is ORed into the protocol version to designate that addresses should be serialized in (un...
Definition: netaddress.h:34
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
Definition: netaddress.h:101
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
Definition: netaddress.h:104
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
Definition: netaddress.h:110
static const std::array< uint8_t, 6 > INTERNAL_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded "internal" address.
Definition: netaddress.h:89
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
Definition: netaddress.h:94
static const std::array< uint8_t, 6 > TORV2_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded TORv2 address.
Definition: netaddress.h:81
static constexpr uint16_t I2P_SAM31_PORT
SAM 3.1 and earlier do not support specifying ports and force the port to 0.
Definition: netaddress.h:113
Network
A network type.
Definition: netaddress.h:45
@ NET_I2P
I2P.
Definition: netaddress.h:59
@ NET_CJDNS
CJDNS.
Definition: netaddress.h:62
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:69
@ NET_ONION
TOR (v2 or v3)
Definition: netaddress.h:56
@ NET_IPV6
IPv6.
Definition: netaddress.h:53
@ NET_IPV4
IPv4.
Definition: netaddress.h:50
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:47
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:66
static const std::array< uint8_t, 12 > IPV4_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded IPv4 address.
Definition: netaddress.h:74
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
Definition: netaddress.h:97
@ IPV6
Definition: netbase.cpp:281
uint64_t GetRand(uint64_t nMax) noexcept
Generate a uniform random integer in the range [0..range).
Definition: random.cpp:591
const char * name
Definition: rest.cpp:43
#define READWRITEAS(type, obj)
Definition: serialize.h:148
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class.
Definition: serialize.h:440
#define COMPACTSIZE(obj)
Definition: serialize.h:444
#define READWRITE(...)
Definition: serialize.h:147
constexpr Span< A > MakeSpan(A(&a)[N])
MakeSpan for arrays:
Definition: span.h:222
bool HasPrefix(const T1 &obj, const std::array< uint8_t, PREFIX_LEN > &prefix)
Check whether a container begins with the given prefix.
Definition: string.h:99
Serialization wrapper class for custom integers and enums.
Definition: serialize.h:473
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
assert(!tx.IsCoinBase())