Bitcoin Core  24.99.0
P2P Digital Currency
netaddress.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2022 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 <compat/compat.h>
13 #include <crypto/siphash.h>
14 #include <prevector.h>
15 #include <random.h>
16 #include <serialize.h>
17 #include <tinyformat.h>
18 #include <util/strencodings.h>
19 #include <util/string.h>
20 
21 #include <array>
22 #include <cstdint>
23 #include <ios>
24 #include <string>
25 #include <vector>
26 
33 static constexpr int ADDRV2_FORMAT = 0x20000000;
34 
44 enum Network {
47 
50 
53 
56 
59 
62 
66 
69 };
70 
73 static const std::array<uint8_t, 12> IPV4_IN_IPV6_PREFIX{
74  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF};
75 
80 static const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX{
81  0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43};
82 
88 static const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX{
89  0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24 // 0xFD + sha256("bitcoin")[0:5].
90 };
91 
93 static constexpr size_t ADDR_IPV4_SIZE = 4;
94 
96 static constexpr size_t ADDR_IPV6_SIZE = 16;
97 
100 static constexpr size_t ADDR_TORV3_SIZE = 32;
101 
103 static constexpr size_t ADDR_I2P_SIZE = 32;
104 
106 static constexpr size_t ADDR_CJDNS_SIZE = 16;
107 
109 static constexpr size_t ADDR_INTERNAL_SIZE = 10;
110 
112 static constexpr uint16_t I2P_SAM31_PORT{0};
113 
114 std::string OnionToString(Span<const uint8_t> addr);
115 
119 class CNetAddr
120 {
121 protected:
127 
132 
137  uint32_t m_scope_id{0};
138 
139 public:
141  explicit CNetAddr(const struct in_addr& ipv4Addr);
142  void SetIP(const CNetAddr& ip);
143 
151 
152  bool SetInternal(const std::string& name);
153 
162  bool SetSpecial(const std::string& addr);
163 
164  bool IsBindAny() const; // INADDR_ANY equivalent
165  bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
166  bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor)
167  bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
168  bool IsRFC2544() const; // IPv4 inter-network communications (198.18.0.0/15)
169  bool IsRFC6598() const; // IPv4 ISP-level NAT (100.64.0.0/10)
170  bool IsRFC5737() const; // IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24)
171  bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32)
172  bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16)
173  bool IsRFC3964() const; // IPv6 6to4 tunnelling (2002::/16)
174  bool IsRFC4193() const; // IPv6 unique local (FC00::/7)
175  bool IsRFC4380() const; // IPv6 Teredo tunnelling (2001::/32)
176  bool IsRFC4843() const; // IPv6 ORCHID (deprecated) (2001:10::/28)
177  bool IsRFC7343() const; // IPv6 ORCHIDv2 (2001:20::/28)
178  bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64)
179  bool IsRFC6052() const; // IPv6 well-known prefix for IPv4-embedded address (64:FF9B::/96)
180  bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) (actually defined in RFC2765)
181  bool IsHeNet() const; // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
182  bool IsTor() const;
183  bool IsI2P() const;
184  bool IsCJDNS() const;
185  bool IsLocal() const;
186  bool IsRoutable() const;
187  bool IsInternal() const;
188  bool IsValid() const;
189 
193  bool IsAddrV1Compatible() const;
194 
195  enum Network GetNetwork() const;
196  std::string ToStringAddr() const;
197  bool GetInAddr(struct in_addr* pipv4Addr) const;
198  Network GetNetClass() const;
199 
201  uint32_t GetLinkedIPv4() const;
203  bool HasLinkedIPv4() const;
204 
205  std::vector<unsigned char> GetAddrBytes() const;
206  int GetReachabilityFrom(const CNetAddr* paddrPartner = nullptr) const;
207 
208  explicit CNetAddr(const struct in6_addr& pipv6Addr, const uint32_t scope = 0);
209  bool GetIn6Addr(struct in6_addr* pipv6Addr) const;
210 
211  friend bool operator==(const CNetAddr& a, const CNetAddr& b);
212  friend bool operator!=(const CNetAddr& a, const CNetAddr& b) { return !(a == b); }
213  friend bool operator<(const CNetAddr& a, const CNetAddr& b);
214 
218  bool IsRelayable() const
219  {
220  return IsIPv4() || IsIPv6() || IsTor() || IsI2P() || IsCJDNS();
221  }
222 
226  template <typename Stream>
227  void Serialize(Stream& s) const
228  {
229  if (s.GetVersion() & ADDRV2_FORMAT) {
231  } else {
233  }
234  }
235 
239  template <typename Stream>
240  void Unserialize(Stream& s)
241  {
242  if (s.GetVersion() & ADDRV2_FORMAT) {
244  } else {
246  }
247  }
248 
249  friend class CSubNet;
250 
251 private:
259  bool SetTor(const std::string& addr);
260 
268  bool SetI2P(const std::string& addr);
269 
273  enum BIP155Network : uint8_t {
274  IPV4 = 1,
275  IPV6 = 2,
276  TORV2 = 3,
277  TORV3 = 4,
278  I2P = 5,
279  CJDNS = 6,
280  };
281 
285  static constexpr size_t V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE;
286 
292  static constexpr size_t MAX_ADDRV2_SIZE = 512;
293 
300 
308  bool SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size);
309 
313  void SerializeV1Array(uint8_t (&arr)[V1_SERIALIZATION_SIZE]) const
314  {
315  size_t prefix_size;
316 
317  switch (m_net) {
318  case NET_IPV6:
319  assert(m_addr.size() == sizeof(arr));
320  memcpy(arr, m_addr.data(), m_addr.size());
321  return;
322  case NET_IPV4:
323  prefix_size = sizeof(IPV4_IN_IPV6_PREFIX);
324  assert(prefix_size + m_addr.size() == sizeof(arr));
325  memcpy(arr, IPV4_IN_IPV6_PREFIX.data(), prefix_size);
326  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
327  return;
328  case NET_INTERNAL:
329  prefix_size = sizeof(INTERNAL_IN_IPV6_PREFIX);
330  assert(prefix_size + m_addr.size() == sizeof(arr));
331  memcpy(arr, INTERNAL_IN_IPV6_PREFIX.data(), prefix_size);
332  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
333  return;
334  case NET_ONION:
335  case NET_I2P:
336  case NET_CJDNS:
337  break;
338  case NET_UNROUTABLE:
339  case NET_MAX:
340  assert(false);
341  } // no default case, so the compiler can warn about missing cases
342 
343  // Serialize ONION, I2P and CJDNS as all-zeros.
344  memset(arr, 0x0, V1_SERIALIZATION_SIZE);
345  }
346 
350  template <typename Stream>
351  void SerializeV1Stream(Stream& s) const
352  {
353  uint8_t serialized[V1_SERIALIZATION_SIZE];
354 
355  SerializeV1Array(serialized);
356 
357  s << serialized;
358  }
359 
363  template <typename Stream>
364  void SerializeV2Stream(Stream& s) const
365  {
366  if (IsInternal()) {
367  // Serialize NET_INTERNAL as embedded in IPv6. We need to
368  // serialize such addresses from addrman.
369  s << static_cast<uint8_t>(BIP155Network::IPV6);
372  return;
373  }
374 
375  s << static_cast<uint8_t>(GetBIP155Network());
376  s << m_addr;
377  }
378 
389  {
390  // Use SetLegacyIPv6() so that m_net is set correctly. For example
391  // ::FFFF:0102:0304 should be set as m_net=NET_IPV4 (1.2.3.4).
392  SetLegacyIPv6(arr);
393  }
394 
398  template <typename Stream>
399  void UnserializeV1Stream(Stream& s)
400  {
401  uint8_t serialized[V1_SERIALIZATION_SIZE];
402 
403  s >> serialized;
404 
405  UnserializeV1Array(serialized);
406  }
407 
411  template <typename Stream>
412  void UnserializeV2Stream(Stream& s)
413  {
414  uint8_t bip155_net;
415  s >> bip155_net;
416 
417  size_t address_size;
418  s >> COMPACTSIZE(address_size);
419 
420  if (address_size > MAX_ADDRV2_SIZE) {
421  throw std::ios_base::failure(strprintf(
422  "Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
423  }
424 
425  m_scope_id = 0;
426 
427  if (SetNetFromBIP155Network(bip155_net, address_size)) {
428  m_addr.resize(address_size);
429  s >> Span{m_addr};
430 
431  if (m_net != NET_IPV6) {
432  return;
433  }
434 
435  // Do some special checks on IPv6 addresses.
436 
437  // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
438  // gossiped but could be coming from addrman, when unserializing from
439  // disk.
442  memmove(m_addr.data(), m_addr.data() + INTERNAL_IN_IPV6_PREFIX.size(),
445  return;
446  }
447 
450  return;
451  }
452 
453  // IPv4 and TORv2 are not supposed to be embedded in IPv6 (like in V1
454  // encoding). Unserialize as !IsValid(), thus ignoring them.
455  } else {
456  // If we receive an unknown BIP155 network id (from the future?) then
457  // ignore the address - unserialize as !IsValid().
458  s.ignore(address_size);
459  }
460 
461  // Mimic a default-constructed CNetAddr object which is !IsValid() and thus
462  // will not be gossiped, but continue reading next addresses from the stream.
463  m_net = NET_IPV6;
465  }
466 };
467 
468 class CSubNet
469 {
470 protected:
474  uint8_t netmask[16];
476  bool valid;
477 
478 public:
482  CSubNet();
483 
491  CSubNet(const CNetAddr& addr, uint8_t mask);
492 
500  CSubNet(const CNetAddr& addr, const CNetAddr& mask);
501 
506  explicit CSubNet(const CNetAddr& addr);
507 
508  bool Match(const CNetAddr& addr) const;
509 
510  std::string ToString() const;
511  bool IsValid() const;
512 
513  friend bool operator==(const CSubNet& a, const CSubNet& b);
514  friend bool operator!=(const CSubNet& a, const CSubNet& b) { return !(a == b); }
515  friend bool operator<(const CSubNet& a, const CSubNet& b);
516 };
517 
519 class CService : public CNetAddr
520 {
521 protected:
522  uint16_t port; // host order
523 
524 public:
525  CService();
526  CService(const CNetAddr& ip, uint16_t port);
527  CService(const struct in_addr& ipv4Addr, uint16_t port);
528  explicit CService(const struct sockaddr_in& addr);
529  uint16_t GetPort() const;
530  bool GetSockAddr(struct sockaddr* paddr, socklen_t* addrlen) const;
531  bool SetSockAddr(const struct sockaddr* paddr);
532  friend bool operator==(const CService& a, const CService& b);
533  friend bool operator!=(const CService& a, const CService& b) { return !(a == b); }
534  friend bool operator<(const CService& a, const CService& b);
535  std::vector<unsigned char> GetKey() const;
536  std::string ToStringAddrPort() const;
537 
538  CService(const struct in6_addr& ipv6Addr, uint16_t port);
539  explicit CService(const struct sockaddr_in6& addr);
540 
542  {
543  READWRITEAS(CNetAddr, obj);
545  }
546 
547  friend class CServiceHash;
548  friend CService MaybeFlipIPv6toCJDNS(const CService& service);
549 };
550 
552 {
553 public:
555  : m_salt_k0{GetRand<uint64_t>()},
556  m_salt_k1{GetRand<uint64_t>()}
557  {
558  }
559 
560  CServiceHash(uint64_t salt_k0, uint64_t salt_k1) : m_salt_k0{salt_k0}, m_salt_k1{salt_k1} {}
561 
562  size_t operator()(const CService& a) const noexcept
563  {
564  CSipHasher hasher(m_salt_k0, m_salt_k1);
565  hasher.Write(a.m_net);
566  hasher.Write(a.port);
567  hasher.Write(a.m_addr.data(), a.m_addr.size());
568  return static_cast<size_t>(hasher.Finalize());
569  }
570 
571 private:
572  const uint64_t m_salt_k0;
573  const uint64_t m_salt_k1;
574 };
575 
576 #endif // BITCOIN_NETADDRESS_H
Network address.
Definition: netaddress.h:120
Network GetNetClass() const
Definition: netaddress.cpp:696
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition: netaddress.h:313
bool IsRelayable() const
Whether this address should be relayed to other peers even if we can't reach it ourselves.
Definition: netaddress.h:218
std::string ToStringAddr() const
Definition: netaddress.cpp:602
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
Definition: netaddress.h:364
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
Definition: netaddress.h:126
bool IsBindAny() const
Definition: netaddress.cpp:304
bool IsRFC6052() const
Definition: netaddress.cpp:356
void SetIP(const CNetAddr &ip)
Definition: netaddress.cpp:103
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:208
bool IsRFC7343() const
Definition: netaddress.cpp:392
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Try to get our IPv6 (or CJDNS) address.
Definition: netaddress.cpp:664
std::vector< unsigned char > GetAddrBytes() const
Definition: netaddress.cpp:714
bool IsCJDNS() const
Check whether this object represents a CJDNS address.
Definition: netaddress.cpp:417
bool IsTor() const
Check whether this object represents a TOR address.
Definition: netaddress.cpp:407
bool IsRoutable() const
Definition: netaddress.cpp:484
bool GetInAddr(struct in_addr *pipv4Addr) const
Try to get our IPv4 address.
Definition: netaddress.cpp:645
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition: netaddress.cpp:674
Network m_net
Network to which this address belongs.
Definition: netaddress.h:131
bool IsRFC5737() const
Definition: netaddress.cpp:339
void SetLegacyIPv6(Span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Definition: netaddress.cpp:134
bool SetI2P(const std::string &addr)
Parse an I2P address and set this object to it.
Definition: netaddress.cpp:264
void UnserializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE])
Unserialize from a pre-ADDRv2/BIP155 format from an array.
Definition: netaddress.h:388
bool IsRFC6598() const
Definition: netaddress.cpp:334
bool IsRFC1918() const
Definition: netaddress.cpp:316
friend bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:625
bool IsValid() const
Definition: netaddress.cpp:445
bool IsIPv4() const
Definition: netaddress.cpp:312
BIP155Network GetBIP155Network() const
Get the BIP155 network id of this address.
Definition: netaddress.cpp:23
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
Definition: netaddress.cpp:679
bool SetTor(const std::string &addr)
Parse a Tor address and set this object to it.
Definition: netaddress.cpp:225
void SerializeV1Stream(Stream &s) const
Serialize in pre-ADDRv2/BIP155 format to a stream.
Definition: netaddress.h:351
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
Definition: netaddress.h:137
bool IsRFC3849() const
Definition: netaddress.cpp:346
bool IsHeNet() const
Definition: netaddress.cpp:398
void Serialize(Stream &s) const
Serialize to a stream.
Definition: netaddress.h:227
bool IsLocal() const
Definition: netaddress.cpp:419
void Unserialize(Stream &s)
Unserialize from a stream.
Definition: netaddress.h:240
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition: netaddress.h:285
bool IsIPv6() const
Definition: netaddress.cpp:314
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition: netaddress.h:399
bool IsInternal() const
Definition: netaddress.cpp:494
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:45
bool SetInternal(const std::string &name)
Create an "internal" address that represents a name or FQDN.
Definition: netaddress.cpp:169
bool IsRFC4193() const
Definition: netaddress.cpp:374
friend bool operator!=(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.h:212
int GetReachabilityFrom(const CNetAddr *paddrPartner=nullptr) const
Calculates a metric for how reachable (*this) is from a given partner.
Definition: netaddress.cpp:738
static constexpr size_t MAX_ADDRV2_SIZE
Maximum size of an address as defined in BIP155 (in bytes).
Definition: netaddress.h:292
bool IsRFC2544() const
Definition: netaddress.cpp:324
enum Network GetNetwork() const
Definition: netaddress.cpp:518
bool IsRFC6145() const
Definition: netaddress.cpp:379
CNetAddr()
Construct an unspecified IPv6 network address (::/128).
bool IsRFC3964() const
Definition: netaddress.cpp:351
void UnserializeV2Stream(Stream &s)
Unserialize from a ADDRv2 / BIP155 format.
Definition: netaddress.h:412
bool IsRFC4380() const
Definition: netaddress.cpp:363
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:630
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:499
BIP155Network
BIP155 network ids recognized by this software.
Definition: netaddress.h:273
bool IsRFC3927() const
Definition: netaddress.cpp:329
bool IsRFC4862() const
Definition: netaddress.cpp:368
bool IsRFC4843() const
Definition: netaddress.cpp:386
bool IsI2P() const
Check whether this object represents an I2P address.
Definition: netaddress.cpp:412
size_t operator()(const CService &a) const noexcept
Definition: netaddress.h:562
const uint64_t m_salt_k0
Definition: netaddress.h:572
CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
Definition: netaddress.h:560
const uint64_t m_salt_k1
Definition: netaddress.h:573
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:520
SERIALIZE_METHODS(CService, obj)
Definition: netaddress.h:541
friend bool operator<(const CService &a, const CService &b)
Definition: netaddress.cpp:856
friend bool operator!=(const CService &a, const CService &b)
Definition: netaddress.h:533
uint16_t GetPort() const
Definition: netaddress.cpp:846
bool SetSockAddr(const struct sockaddr *paddr)
Definition: netaddress.cpp:832
friend bool operator==(const CService &a, const CService &b)
Definition: netaddress.cpp:851
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:276
uint16_t port
Definition: netaddress.h:522
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
Definition: netaddress.cpp:873
std::string ToStringAddrPort() const
Definition: netaddress.cpp:914
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:906
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:514
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:476
CNetAddr network
Network (base) address.
Definition: netaddress.h:472
friend bool operator==(const CSubNet &a, const CSubNet &b)
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:474
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).
Definition: netaddress.cpp:925
bool Match(const CNetAddr &addr) const
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:97
size_type size() const
Definition: prevector.h:284
value_type * data()
Definition: prevector.h:520
void resize(size_type new_size)
Definition: prevector.h:318
void assign(size_type n, const T &val)
Definition: prevector.h:220
static CService ip(uint32_t i)
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
Definition: netaddress.h:106
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:33
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
Definition: netaddress.h:100
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
Definition: netaddress.h:103
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
Definition: netaddress.h:109
std::string OnionToString(Span< const uint8_t > addr)
Definition: netaddress.cpp:591
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:88
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
Definition: netaddress.h:93
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:80
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:112
Network
A network type.
Definition: netaddress.h:44
@ NET_I2P
I2P.
Definition: netaddress.h:58
@ NET_CJDNS
CJDNS.
Definition: netaddress.h:61
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:68
@ NET_ONION
TOR (v2 or v3)
Definition: netaddress.h:55
@ NET_IPV6
IPv6.
Definition: netaddress.h:52
@ NET_IPV4
IPv4.
Definition: netaddress.h:49
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:46
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:65
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:73
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
Definition: netaddress.h:96
@ IPV6
Definition: netbase.cpp:281
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition: random.h:80
const char * name
Definition: rest.cpp:46
#define READWRITEAS(type, obj)
Definition: serialize.h:141
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class.
Definition: serialize.h:433
#define COMPACTSIZE(obj)
Definition: serialize.h:437
#define READWRITE(...)
Definition: serialize.h:140
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:121
Serialization wrapper class for custom integers and enums.
Definition: serialize.h:466
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1162
assert(!tx.IsCoinBase())