Bitcoin ABC  0.26.3
P2P Digital Currency
netaddress.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2016 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)
9 #include <config/bitcoin-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 <util/strencodings.h>
19 #include <util/string.h>
20 
21 #include <tinyformat.h>
22 
23 #include <array>
24 #include <cstdint>
25 #include <ios>
26 #include <string>
27 #include <vector>
28 
34 static constexpr int ADDRV2_FORMAT = 0x20000000;
35 
45 enum Network {
49 
52 
55 
58 
61 
64 
68 
71 };
72 
75 static const std::array<uint8_t, 12> IPV4_IN_IPV6_PREFIX{
76  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}};
77 
82 static const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX{
83  {0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43}};
84 
90 static const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX{
91  // 0xFD + sha256("bitcoin")[0:5].
92  {0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24}};
93 
95 static constexpr size_t ADDR_IPV4_SIZE = 4;
96 
98 static constexpr size_t ADDR_IPV6_SIZE = 16;
99 
101 static constexpr size_t ADDR_TORV2_SIZE = 10;
102 
105 static constexpr size_t ADDR_TORV3_SIZE = 32;
106 
108 static constexpr size_t ADDR_I2P_SIZE = 32;
109 
111 static constexpr size_t ADDR_CJDNS_SIZE = 16;
112 
114 static constexpr size_t ADDR_INTERNAL_SIZE = 10;
115 
117 static constexpr uint16_t I2P_SAM31_PORT{0};
118 
122 class CNetAddr {
123 protected:
129 
134 
139  uint32_t m_scope_id{0};
140 
141 public:
142  CNetAddr();
143  explicit CNetAddr(const struct in_addr &ipv4Addr);
144  void SetIP(const CNetAddr &ip);
145 
153 
154  bool SetInternal(const std::string &name);
155 
164  bool SetSpecial(const std::string &addr);
165 
166  // INADDR_ANY equivalent
167  bool IsBindAny() const;
168  // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
169  bool IsIPv4() const;
170  // IPv6 address (not mapped IPv4, not Tor)
171  bool IsIPv6() const;
172  // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
173  bool IsRFC1918() const;
174  // IPv4 inter-network communications (198.18.0.0/15)
175  bool IsRFC2544() const;
176  // IPv4 ISP-level NAT (100.64.0.0/10)
177  bool IsRFC6598() const;
178  // IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24,
179  // 203.0.113.0/24)
180  bool IsRFC5737() const;
181  // IPv6 documentation address (2001:0DB8::/32)
182  bool IsRFC3849() const;
183  // IPv4 autoconfig (169.254.0.0/16)
184  bool IsRFC3927() const;
185  // IPv6 6to4 tunnelling (2002::/16)
186  bool IsRFC3964() const;
187  // IPv6 unique local (FC00::/7)
188  bool IsRFC4193() const;
189  // IPv6 Teredo tunnelling (2001::/32)
190  bool IsRFC4380() const;
191  // IPv6 ORCHID (deprecated) (2001:10::/28)
192  bool IsRFC4843() const;
193  // IPv6 ORCHIDv2 (2001:20::/28)
194  bool IsRFC7343() const;
195  // IPv6 autoconfig (FE80::/64)
196  bool IsRFC4862() const;
197  // IPv6 well-known prefix for IPv4-embedded address (64:FF9B::/96)
198  bool IsRFC6052() const;
199  // IPv6 IPv4-translated address (::FFFF:0:0:0/96) (actually defined in
200  // RFC2765)
201  bool IsRFC6145() const;
202  // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
203  bool IsHeNet() const;
204  bool IsTor() const;
205  bool IsI2P() const;
206  bool IsCJDNS() const;
207  bool IsLocal() const;
208  bool IsRoutable() const;
209  bool IsInternal() const;
210  bool IsValid() const;
211 
216  bool IsAddrV1Compatible() const;
217 
218  enum Network GetNetwork() const;
219  std::string ToString() const;
220  std::string ToStringIP() const;
221  bool GetInAddr(struct in_addr *pipv4Addr) const;
222  Network GetNetClass() const;
223 
226  uint32_t GetLinkedIPv4() const;
228  bool HasLinkedIPv4() const;
229 
230  // The AS on the BGP path to the node we use to diversify
231  // peers in AddrMan bucketing based on the AS infrastructure.
232  // The ip->AS mapping depends on how asmap is constructed.
233  uint32_t GetMappedAS(const std::vector<bool> &asmap) const;
234 
235  std::vector<uint8_t> GetGroup(const std::vector<bool> &asmap) const;
236  std::vector<uint8_t> GetAddrBytes() const;
237  int GetReachabilityFrom(const CNetAddr *paddrPartner = nullptr) const;
238 
239  explicit CNetAddr(const struct in6_addr &pipv6Addr,
240  const uint32_t scope = 0);
241  bool GetIn6Addr(struct in6_addr *pipv6Addr) const;
242 
243  friend bool operator==(const CNetAddr &a, const CNetAddr &b);
244  friend bool operator!=(const CNetAddr &a, const CNetAddr &b) {
245  return !(a == b);
246  }
247  friend bool operator<(const CNetAddr &a, const CNetAddr &b);
248 
253  bool IsRelayable() const { return IsIPv4() || IsIPv6() || IsTor(); }
254 
258  template <typename Stream> void Serialize(Stream &s) const {
259  if (s.GetVersion() & ADDRV2_FORMAT) {
261  } else {
263  }
264  }
265 
269  template <typename Stream> void Unserialize(Stream &s) {
270  if (s.GetVersion() & ADDRV2_FORMAT) {
272  } else {
274  }
275  }
276 
277  friend class CSubNet;
278 
279 private:
288  bool SetTor(const std::string &addr);
289 
297  bool SetI2P(const std::string &addr);
298 
302  enum BIP155Network : uint8_t {
303  IPV4 = 1,
304  IPV6 = 2,
305  TORV2 = 3,
306  TORV3 = 4,
307  I2P = 5,
308  CJDNS = 6,
309  };
310 
314  static constexpr size_t V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE;
315 
321  static constexpr size_t MAX_ADDRV2_SIZE = 512;
322 
329 
340  bool SetNetFromBIP155Network(uint8_t possible_bip155_net,
341  size_t address_size);
342 
346  void SerializeV1Array(uint8_t (&arr)[V1_SERIALIZATION_SIZE]) const {
347  size_t prefix_size;
348 
349  switch (m_net) {
350  case NET_IPV6:
351  assert(m_addr.size() == sizeof(arr));
352  memcpy(arr, m_addr.data(), m_addr.size());
353  return;
354  case NET_IPV4:
355  prefix_size = sizeof(IPV4_IN_IPV6_PREFIX);
356  assert(prefix_size + m_addr.size() == sizeof(arr));
357  memcpy(arr, IPV4_IN_IPV6_PREFIX.data(), prefix_size);
358  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
359  return;
360  case NET_ONION:
361  if (m_addr.size() == ADDR_TORV3_SIZE) {
362  break;
363  }
364  prefix_size = sizeof(TORV2_IN_IPV6_PREFIX);
365  assert(prefix_size + m_addr.size() == sizeof(arr));
366  memcpy(arr, TORV2_IN_IPV6_PREFIX.data(), prefix_size);
367  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
368  return;
369  case NET_INTERNAL:
370  prefix_size = sizeof(INTERNAL_IN_IPV6_PREFIX);
371  assert(prefix_size + m_addr.size() == sizeof(arr));
372  memcpy(arr, INTERNAL_IN_IPV6_PREFIX.data(), prefix_size);
373  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
374  return;
375  case NET_I2P:
376  break;
377  case NET_CJDNS:
378  break;
379  case NET_UNROUTABLE:
380  case NET_MAX:
381  assert(false);
382  } // no default case, so the compiler can warn about missing cases
383 
384  // Serialize TORv3, I2P and CJDNS as all-zeros.
385  memset(arr, 0x0, V1_SERIALIZATION_SIZE);
386  }
387 
391  template <typename Stream> void SerializeV1Stream(Stream &s) const {
392  uint8_t serialized[V1_SERIALIZATION_SIZE];
393 
394  SerializeV1Array(serialized);
395 
396  s << serialized;
397  }
398 
402  template <typename Stream> void SerializeV2Stream(Stream &s) const {
403  if (IsInternal()) {
404  // Serialize NET_INTERNAL as embedded in IPv6. We need to
405  // serialize such addresses from addrman.
406  s << static_cast<uint8_t>(BIP155Network::IPV6);
409  return;
410  }
411 
412  s << static_cast<uint8_t>(GetBIP155Network());
413  s << m_addr;
414  }
415 
420  // Use SetLegacyIPv6() so that m_net is set correctly. For example
421  // ::FFFF:0102:0304 should be set as m_net=NET_IPV4 (1.2.3.4).
422  SetLegacyIPv6(arr);
423  }
424 
428  template <typename Stream> void UnserializeV1Stream(Stream &s) {
429  uint8_t serialized[V1_SERIALIZATION_SIZE];
430 
431  s >> serialized;
432 
433  UnserializeV1Array(serialized);
434  }
435 
439  template <typename Stream> void UnserializeV2Stream(Stream &s) {
440  uint8_t bip155_net;
441  s >> bip155_net;
442 
443  size_t address_size;
444  s >> COMPACTSIZE(address_size);
445 
446  if (address_size > MAX_ADDRV2_SIZE) {
447  throw std::ios_base::failure(strprintf(
448  "Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
449  }
450 
451  m_scope_id = 0;
452 
453  if (SetNetFromBIP155Network(bip155_net, address_size)) {
454  m_addr.resize(address_size);
455  s >> MakeSpan(m_addr);
456 
457  if (m_net != NET_IPV6) {
458  return;
459  }
460 
461  // Do some special checks on IPv6 addresses.
462 
463  // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
464  // gossiped but could be coming from addrman, when unserializing
465  // from disk.
468  memmove(m_addr.data(),
472  return;
473  }
474 
477  return;
478  }
479 
480  // IPv4 and TORv2 are not supposed to be embedded in IPv6 (like in
481  // V1 encoding). Unserialize as !IsValid(), thus ignoring them.
482  } else {
483  // If we receive an unknown BIP155 network id (from the future?)
484  // then ignore the address - unserialize as !IsValid().
485  s.ignore(address_size);
486  }
487 
488  // Mimic a default-constructed CNetAddr object which is !IsValid() and
489  // thus will not be gossiped, but continue reading next addresses from
490  // the stream.
491  m_net = NET_IPV6;
493  }
494 };
495 
496 class CSubNet {
497 protected:
501  uint8_t netmask[16];
503  bool valid;
504 
505  bool SanityCheck() const;
506 
507 public:
508  CSubNet();
509  CSubNet(const CNetAddr &addr, uint8_t mask);
510  CSubNet(const CNetAddr &addr, const CNetAddr &mask);
511 
512  // constructor for single ip subnet (<ipv4>/32 or <ipv6>/128)
513  explicit CSubNet(const CNetAddr &addr);
514 
515  bool Match(const CNetAddr &addr) const;
516 
517  std::string ToString() const;
518  bool IsValid() const;
519 
520  friend bool operator==(const CSubNet &a, const CSubNet &b);
521  friend bool operator!=(const CSubNet &a, const CSubNet &b) {
522  return !(a == b);
523  }
524  friend bool operator<(const CSubNet &a, const CSubNet &b);
525 
527  READWRITE(obj.network);
528  if (obj.network.IsIPv4()) {
529  // Before D9176, CSubNet used the last 4 bytes of netmask to store
530  // the relevant bytes for an IPv4 mask. For compatiblity reasons,
531  // keep doing so in serialized form.
532  uint8_t dummy[12] = {0};
533  READWRITE(dummy);
534  READWRITE(MakeSpan(obj.netmask).first(4));
535  } else {
536  READWRITE(obj.netmask);
537  }
538  READWRITE(obj.valid);
539  // Mark invalid if the result doesn't pass sanity checking.
540  SER_READ(obj, if (obj.valid) obj.valid = obj.SanityCheck());
541  }
542 };
543 
545 class CService : public CNetAddr {
546 protected:
547  // host order
548  uint16_t port;
549 
550 public:
551  CService();
552  CService(const CNetAddr &ip, uint16_t port);
553  CService(const struct in_addr &ipv4Addr, uint16_t port);
554  explicit CService(const struct sockaddr_in &addr);
555  uint16_t GetPort() const;
556  bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const;
557  bool SetSockAddr(const struct sockaddr *paddr);
558  friend bool operator==(const CService &a, const CService &b);
559  friend bool operator!=(const CService &a, const CService &b) {
560  return !(a == b);
561  }
562  friend bool operator<(const CService &a, const CService &b);
563  std::vector<uint8_t> GetKey() const;
564  std::string ToString() const;
565  std::string ToStringPort() const;
566  std::string ToStringIPPort() const;
567 
568  CService(const struct in6_addr &ipv6Addr, uint16_t port);
569  explicit CService(const struct sockaddr_in6 &addr);
570 
572  READWRITEAS(CNetAddr, obj);
574  }
575 
576  friend class CServiceHash;
577 };
578 
580 public:
582  : m_salt_k0{GetRand(std::numeric_limits<uint64_t>::max())},
583  m_salt_k1{GetRand(std::numeric_limits<uint64_t>::max())} {}
584 
585  CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
586  : m_salt_k0{salt_k0}, m_salt_k1{salt_k1} {}
587 
588  size_t operator()(const CService &a) const noexcept {
589  CSipHasher hasher(m_salt_k0, m_salt_k1);
590  hasher.Write(a.m_net);
591  hasher.Write(a.port);
592  hasher.Write(a.m_addr.data(), a.m_addr.size());
593  return static_cast<size_t>(hasher.Finalize());
594  }
595 
596 private:
597  const uint64_t m_salt_k0;
598  const uint64_t m_salt_k1;
599 };
600 
601 #endif // BITCOIN_NETADDRESS_H
Network address.
Definition: netaddress.h:122
Network GetNetClass() const
Definition: netaddress.cpp:711
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition: netaddress.h:346
bool IsRelayable() const
Whether this address should be relayed to other peers even if we can't reach it ourselves.
Definition: netaddress.h:253
std::string ToStringIP() const
Definition: netaddress.cpp:578
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
Definition: netaddress.h:402
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
Definition: netaddress.h:128
bool IsBindAny() const
Definition: netaddress.cpp:334
bool IsRFC6052() const
Definition: netaddress.cpp:384
void SetIP(const CNetAddr &ip)
Definition: netaddress.cpp:125
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:227
bool IsRFC7343() const
Definition: netaddress.cpp:419
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Try to get our IPv6 address.
Definition: netaddress.cpp:679
std::string ToString() const
Definition: netaddress.cpp:638
bool IsCJDNS() const
Check whether this object represents a CJDNS address.
Definition: netaddress.cpp:449
bool IsTor() const
Check whether this object represents a TOR address.
Definition: netaddress.cpp:435
bool IsRoutable() const
Definition: netaddress.cpp:514
bool GetInAddr(struct in_addr *pipv4Addr) const
Try to get our IPv4 address.
Definition: netaddress.cpp:660
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition: netaddress.cpp:688
Network m_net
Network to which this address belongs.
Definition: netaddress.h:133
bool IsRFC5737() const
Definition: netaddress.cpp:368
void SetLegacyIPv6(Span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Definition: netaddress.cpp:156
bool SetI2P(const std::string &addr)
Parse an I2P address and set this object to it.
Definition: netaddress.cpp:293
void UnserializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE])
Unserialize from a pre-ADDRv2/BIP155 format from an array.
Definition: netaddress.h:419
bool IsRFC6598() const
Definition: netaddress.cpp:364
bool IsRFC1918() const
Definition: netaddress.cpp:350
friend bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:642
bool IsValid() const
Definition: netaddress.cpp:479
bool IsIPv4() const
Definition: netaddress.cpp:342
BIP155Network GetBIP155Network() const
Get the BIP155 network id of this address.
Definition: netaddress.cpp:28
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
Definition: netaddress.cpp:693
bool SetTor(const std::string &addr)
Parse a Tor address and set this object to it.
Definition: netaddress.cpp:243
void SerializeV1Stream(Stream &s) const
Serialize in pre-ADDRv2/BIP155 format to a stream.
Definition: netaddress.h:391
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
Definition: netaddress.h:139
bool IsRFC3849() const
Definition: netaddress.cpp:375
bool IsHeNet() const
Definition: netaddress.cpp:425
void Serialize(Stream &s) const
Serialize to a stream.
Definition: netaddress.h:258
bool IsLocal() const
Definition: netaddress.cpp:453
void Unserialize(Stream &s)
Unserialize from a stream.
Definition: netaddress.h:269
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition: netaddress.h:314
bool IsIPv6() const
Definition: netaddress.cpp:346
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition: netaddress.h:428
bool IsInternal() const
Definition: netaddress.cpp:526
std::vector< uint8_t > GetGroup(const std::vector< bool > &asmap) const
Get the canonical identifier of our network group.
Definition: netaddress.cpp:773
std::vector< uint8_t > GetAddrBytes() const
Definition: netaddress.cpp:828
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:59
bool SetInternal(const std::string &name)
Create an "internal" address that represents a name or FQDN.
Definition: netaddress.cpp:188
bool IsRFC4193() const
Definition: netaddress.cpp:402
friend bool operator!=(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.h:244
uint32_t GetMappedAS(const std::vector< bool > &asmap) const
Definition: netaddress.cpp:729
int GetReachabilityFrom(const CNetAddr *paddrPartner=nullptr) const
Calculates a metric for how reachable (*this) is from a given partner.
Definition: netaddress.cpp:852
static constexpr size_t MAX_ADDRV2_SIZE
Maximum size of an address as defined in BIP155 (in bytes).
Definition: netaddress.h:321
bool IsRFC2544() const
Definition: netaddress.cpp:356
enum Network GetNetwork() const
Definition: netaddress.cpp:551
bool IsRFC6145() const
Definition: netaddress.cpp:406
CNetAddr()
Construct an unspecified IPv6 network address (::/128).
Definition: netaddress.cpp:123
bool IsRFC3964() const
Definition: netaddress.cpp:380
void UnserializeV2Stream(Stream &s)
Unserialize from a ADDRv2 / BIP155 format.
Definition: netaddress.h:439
bool IsRFC4380() const
Definition: netaddress.cpp:391
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:646
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:530
BIP155Network
BIP155 network ids recognized by this software.
Definition: netaddress.h:302
bool IsRFC3927() const
Definition: netaddress.cpp:360
bool IsRFC4862() const
Definition: netaddress.cpp:396
bool IsRFC4843() const
Definition: netaddress.cpp:413
bool IsI2P() const
Check whether this object represents an I2P address.
Definition: netaddress.cpp:442
size_t operator()(const CService &a) const noexcept
Definition: netaddress.h:588
const uint64_t m_salt_k0
Definition: netaddress.h:597
CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
Definition: netaddress.h:585
const uint64_t m_salt_k1
Definition: netaddress.h:598
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:545
SERIALIZE_METHODS(CService, obj)
Definition: netaddress.h:571
std::string ToStringIPPort() const
std::string ToString() const
friend bool operator<(const CService &a, const CService &b)
Definition: netaddress.cpp:984
std::vector< uint8_t > GetKey() const
friend bool operator!=(const CService &a, const CService &b)
Definition: netaddress.h:559
uint16_t GetPort() const
Definition: netaddress.cpp:975
bool SetSockAddr(const struct sockaddr *paddr)
Definition: netaddress.cpp:960
friend bool operator==(const CService &a, const CService &b)
Definition: netaddress.cpp:979
std::string ToStringPort() const
uint16_t port
Definition: netaddress.h:548
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
SipHash-2-4.
Definition: siphash.h:13
uint64_t Finalize() const
Compute the 64-bit SipHash-2-4 of the data written so far.
Definition: siphash.cpp:82
CSipHasher & Write(uint64_t data)
Hash a 64-bit integer worth of data.
Definition: siphash.cpp:36
friend bool operator!=(const CSubNet &a, const CSubNet &b)
Definition: netaddress.h:521
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:503
CNetAddr network
Network (base) address.
Definition: netaddress.h:499
bool SanityCheck() const
friend bool operator==(const CSubNet &a, const CSubNet &b)
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:501
std::string ToString() const
SERIALIZE_METHODS(CSubNet, obj)
Definition: netaddress.h:526
bool IsValid() const
friend bool operator<(const CSubNet &a, const CSubNet &b)
bool Match(const CNetAddr &addr) const
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:93
size_type size() const
Definition: prevector.h:386
value_type * data()
Definition: prevector.h:610
void resize(size_type new_size)
Definition: prevector.h:416
void assign(size_type n, const T &val)
Definition: prevector.h:326
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
Definition: netaddress.h:111
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:105
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
Definition: netaddress.h:108
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
Definition: netaddress.h:114
static constexpr size_t ADDR_TORV2_SIZE
Size of TORv2 address (in bytes).
Definition: netaddress.h:101
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:90
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
Definition: netaddress.h:95
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:82
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:117
Network
A network type.
Definition: netaddress.h:45
@ NET_I2P
I2P.
Definition: netaddress.h:60
@ NET_CJDNS
CJDNS.
Definition: netaddress.h:63
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:70
@ NET_ONION
TOR (v2 or v3)
Definition: netaddress.h:57
@ NET_IPV6
IPv6.
Definition: netaddress.h:54
@ NET_IPV4
IPv4.
Definition: netaddress.h:51
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:48
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:67
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:75
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
Definition: netaddress.h:98
@ IPV6
Definition: netbase.cpp:309
uint64_t GetRand(uint64_t nMax) noexcept
Generate a uniform random integer in the range [0..range).
Definition: random.cpp:650
const char * name
Definition: rest.cpp:50
#define READWRITEAS(type, obj)
Definition: serialize.h:181
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class.
Definition: serialize.h:592
#define SER_READ(obj, code)
Definition: serialize.h:183
#define COMPACTSIZE(obj)
Definition: serialize.h:598
#define READWRITE(...)
Definition: serialize.h:180
constexpr Span< A > MakeSpan(A(&a)[N])
MakeSpan for arrays:
Definition: span.h:259
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:89
Serialization wrapper class for custom integers and enums.
Definition: serialize.h:624
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
assert(!tx.IsCoinBase())