Bitcoin Core 28.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#include <compat/compat.h>
9#include <crypto/siphash.h>
10#include <prevector.h>
11#include <random.h>
12#include <serialize.h>
13#include <tinyformat.h>
14#include <util/strencodings.h>
15#include <util/string.h>
16
17#include <array>
18#include <cstdint>
19#include <ios>
20#include <string>
21#include <vector>
22
32enum Network {
35
38
41
44
47
50
54
57};
58
61static const std::array<uint8_t, 12> IPV4_IN_IPV6_PREFIX{
62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF};
63
68static const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX{
69 0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43};
70
76static const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX{
77 0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24 // 0xFD + sha256("bitcoin")[0:5].
78};
79
82static constexpr uint8_t CJDNS_PREFIX{0xFC};
83
85static constexpr size_t ADDR_IPV4_SIZE = 4;
86
88static constexpr size_t ADDR_IPV6_SIZE = 16;
89
92static constexpr size_t ADDR_TORV3_SIZE = 32;
93
95static constexpr size_t ADDR_I2P_SIZE = 32;
96
98static constexpr size_t ADDR_CJDNS_SIZE = 16;
99
101static constexpr size_t ADDR_INTERNAL_SIZE = 10;
102
104static constexpr uint16_t I2P_SAM31_PORT{0};
105
106std::string OnionToString(Span<const uint8_t> addr);
107
112{
113protected:
119
124
129 uint32_t m_scope_id{0};
130
131public:
133 explicit CNetAddr(const struct in_addr& ipv4Addr);
134 void SetIP(const CNetAddr& ip);
135
143
144 bool SetInternal(const std::string& name);
145
154 bool SetSpecial(const std::string& addr);
155
156 bool IsBindAny() const; // INADDR_ANY equivalent
157 [[nodiscard]] bool IsIPv4() const { return m_net == NET_IPV4; } // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
158 [[nodiscard]] bool IsIPv6() const { return m_net == NET_IPV6; } // IPv6 address (not mapped IPv4, not Tor)
159 bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
160 bool IsRFC2544() const; // IPv4 inter-network communications (198.18.0.0/15)
161 bool IsRFC6598() const; // IPv4 ISP-level NAT (100.64.0.0/10)
162 bool IsRFC5737() const; // IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24)
163 bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32)
164 bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16)
165 bool IsRFC3964() const; // IPv6 6to4 tunnelling (2002::/16)
166 bool IsRFC4193() const; // IPv6 unique local (FC00::/7)
167 bool IsRFC4380() const; // IPv6 Teredo tunnelling (2001::/32)
168 bool IsRFC4843() const; // IPv6 ORCHID (deprecated) (2001:10::/28)
169 bool IsRFC7343() const; // IPv6 ORCHIDv2 (2001:20::/28)
170 bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64)
171 bool IsRFC6052() const; // IPv6 well-known prefix for IPv4-embedded address (64:FF9B::/96)
172 bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) (actually defined in RFC2765)
173 bool IsHeNet() const; // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
174 [[nodiscard]] bool IsTor() const { return m_net == NET_ONION; }
175 [[nodiscard]] bool IsI2P() const { return m_net == NET_I2P; }
176 [[nodiscard]] bool IsCJDNS() const { return m_net == NET_CJDNS; }
177 [[nodiscard]] bool HasCJDNSPrefix() const { return m_addr[0] == CJDNS_PREFIX; }
178 bool IsLocal() const;
179 bool IsRoutable() const;
180 bool IsInternal() const;
181 bool IsValid() const;
182
188 [[nodiscard]] bool IsPrivacyNet() const { return IsTor() || IsI2P(); }
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) 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
223 enum class Encoding {
224 V1,
225 V2,
226 };
227 struct SerParams {
230 };
231 static constexpr SerParams V1{Encoding::V1};
232 static constexpr SerParams V2{Encoding::V2};
233
237 template <typename Stream>
238 void Serialize(Stream& s) const
239 {
240 if (s.template GetParams<SerParams>().enc == Encoding::V2) {
242 } else {
244 }
245 }
246
250 template <typename Stream>
251 void Unserialize(Stream& s)
252 {
253 if (s.template GetParams<SerParams>().enc == Encoding::V2) {
255 } else {
257 }
258 }
259
263 enum BIP155Network : uint8_t {
264 IPV4 = 1,
265 IPV6 = 2,
266 TORV2 = 3,
267 TORV3 = 4,
268 I2P = 5,
269 CJDNS = 6,
270 };
271
272 friend class CSubNet;
273
274private:
282 bool SetTor(const std::string& addr);
283
291 bool SetI2P(const std::string& addr);
292
296 static constexpr size_t V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE;
297
303 static constexpr size_t MAX_ADDRV2_SIZE = 512;
304
311
319 bool SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size);
320
324 void SerializeV1Array(uint8_t (&arr)[V1_SERIALIZATION_SIZE]) const
325 {
326 size_t prefix_size;
327
328 switch (m_net) {
329 case NET_IPV6:
330 assert(m_addr.size() == sizeof(arr));
331 memcpy(arr, m_addr.data(), m_addr.size());
332 return;
333 case NET_IPV4:
334 prefix_size = sizeof(IPV4_IN_IPV6_PREFIX);
335 assert(prefix_size + m_addr.size() == sizeof(arr));
336 memcpy(arr, IPV4_IN_IPV6_PREFIX.data(), prefix_size);
337 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
338 return;
339 case NET_INTERNAL:
340 prefix_size = sizeof(INTERNAL_IN_IPV6_PREFIX);
341 assert(prefix_size + m_addr.size() == sizeof(arr));
342 memcpy(arr, INTERNAL_IN_IPV6_PREFIX.data(), prefix_size);
343 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
344 return;
345 case NET_ONION:
346 case NET_I2P:
347 case NET_CJDNS:
348 break;
349 case NET_UNROUTABLE:
350 case NET_MAX:
351 assert(false);
352 } // no default case, so the compiler can warn about missing cases
353
354 // Serialize ONION, I2P and CJDNS as all-zeros.
355 memset(arr, 0x0, V1_SERIALIZATION_SIZE);
356 }
357
361 template <typename Stream>
362 void SerializeV1Stream(Stream& s) const
363 {
364 uint8_t serialized[V1_SERIALIZATION_SIZE];
365
366 SerializeV1Array(serialized);
367
368 s << serialized;
369 }
370
374 template <typename Stream>
375 void SerializeV2Stream(Stream& s) const
376 {
377 if (IsInternal()) {
378 // Serialize NET_INTERNAL as embedded in IPv6. We need to
379 // serialize such addresses from addrman.
380 s << static_cast<uint8_t>(BIP155Network::IPV6);
383 return;
384 }
385
386 s << static_cast<uint8_t>(GetBIP155Network());
387 s << m_addr;
388 }
389
400 {
401 // Use SetLegacyIPv6() so that m_net is set correctly. For example
402 // ::FFFF:0102:0304 should be set as m_net=NET_IPV4 (1.2.3.4).
403 SetLegacyIPv6(arr);
404 }
405
409 template <typename Stream>
410 void UnserializeV1Stream(Stream& s)
411 {
412 uint8_t serialized[V1_SERIALIZATION_SIZE];
413
414 s >> serialized;
415
416 UnserializeV1Array(serialized);
417 }
418
422 template <typename Stream>
423 void UnserializeV2Stream(Stream& s)
424 {
425 uint8_t bip155_net;
426 s >> bip155_net;
427
428 size_t address_size;
429 s >> COMPACTSIZE(address_size);
430
431 if (address_size > MAX_ADDRV2_SIZE) {
432 throw std::ios_base::failure(strprintf(
433 "Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
434 }
435
436 m_scope_id = 0;
437
438 if (SetNetFromBIP155Network(bip155_net, address_size)) {
439 m_addr.resize(address_size);
440 s >> Span{m_addr};
441
442 if (m_net != NET_IPV6) {
443 return;
444 }
445
446 // Do some special checks on IPv6 addresses.
447
448 // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
449 // gossiped but could be coming from addrman, when unserializing from
450 // disk.
453 memmove(m_addr.data(), m_addr.data() + INTERNAL_IN_IPV6_PREFIX.size(),
456 return;
457 }
458
461 return;
462 }
463
464 // IPv4 and TORv2 are not supposed to be embedded in IPv6 (like in V1
465 // encoding). Unserialize as !IsValid(), thus ignoring them.
466 } else {
467 // If we receive an unknown BIP155 network id (from the future?) then
468 // ignore the address - unserialize as !IsValid().
469 s.ignore(address_size);
470 }
471
472 // Mimic a default-constructed CNetAddr object which is !IsValid() and thus
473 // will not be gossiped, but continue reading next addresses from the stream.
474 m_net = NET_IPV6;
476 }
477};
478
480{
481protected:
485 uint8_t netmask[16];
487 bool valid;
488
489public:
493 CSubNet();
494
502 CSubNet(const CNetAddr& addr, uint8_t mask);
503
511 CSubNet(const CNetAddr& addr, const CNetAddr& mask);
512
517 explicit CSubNet(const CNetAddr& addr);
518
519 bool Match(const CNetAddr& addr) const;
520
521 std::string ToString() const;
522 bool IsValid() const;
523
524 friend bool operator==(const CSubNet& a, const CSubNet& b);
525 friend bool operator!=(const CSubNet& a, const CSubNet& b) { return !(a == b); }
526 friend bool operator<(const CSubNet& a, const CSubNet& b);
527};
528
530class CService : public CNetAddr
531{
532protected:
533 uint16_t port; // host order
534
535public:
536 CService();
537 CService(const CNetAddr& ip, uint16_t port);
538 CService(const struct in_addr& ipv4Addr, uint16_t port);
539 explicit CService(const struct sockaddr_in& addr);
540 uint16_t GetPort() const;
541 bool GetSockAddr(struct sockaddr* paddr, socklen_t* addrlen) const;
542 bool SetSockAddr(const struct sockaddr* paddr);
547 [[nodiscard]] sa_family_t GetSAFamily() const;
548 friend bool operator==(const CService& a, const CService& b);
549 friend bool operator!=(const CService& a, const CService& b) { return !(a == b); }
550 friend bool operator<(const CService& a, const CService& b);
551 std::vector<unsigned char> GetKey() const;
552 std::string ToStringAddrPort() const;
553
554 CService(const struct in6_addr& ipv6Addr, uint16_t port);
555 explicit CService(const struct sockaddr_in6& addr);
556
558 {
559 READWRITE(AsBase<CNetAddr>(obj), Using<BigEndianFormatter<2>>(obj.port));
560 }
561
562 friend class CServiceHash;
563 friend CService MaybeFlipIPv6toCJDNS(const CService& service);
564};
565
567{
568public:
570 : m_salt_k0{FastRandomContext().rand64()},
571 m_salt_k1{FastRandomContext().rand64()}
572 {
573 }
574
575 CServiceHash(uint64_t salt_k0, uint64_t salt_k1) : m_salt_k0{salt_k0}, m_salt_k1{salt_k1} {}
576
577 size_t operator()(const CService& a) const noexcept
578 {
580 hasher.Write(a.m_net);
581 hasher.Write(a.port);
582 hasher.Write(a.m_addr);
583 return static_cast<size_t>(hasher.Finalize());
584 }
585
586private:
587 const uint64_t m_salt_k0;
588 const uint64_t m_salt_k1;
589};
590
591#endif // BITCOIN_NETADDRESS_H
Network address.
Definition: netaddress.h:112
Network GetNetClass() const
Definition: netaddress.cpp:678
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition: netaddress.h:324
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:584
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
Definition: netaddress.h:375
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
Definition: netaddress.h:118
bool IsBindAny() const
Definition: netaddress.cpp:307
bool IsRFC6052() const
Definition: netaddress.cpp:355
void SetIP(const CNetAddr &ip)
Definition: netaddress.cpp:106
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:211
bool IsRFC7343() const
Definition: netaddress.cpp:391
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Try to get our IPv6 (or CJDNS) address.
Definition: netaddress.cpp:646
std::vector< unsigned char > GetAddrBytes() const
Definition: netaddress.cpp:696
bool IsCJDNS() const
Definition: netaddress.h:176
bool IsTor() const
Definition: netaddress.h:174
bool IsRoutable() const
Definition: netaddress.cpp:466
bool GetInAddr(struct in_addr *pipv4Addr) const
Try to get our IPv4 address.
Definition: netaddress.cpp:627
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition: netaddress.cpp:656
bool HasCJDNSPrefix() const
Definition: netaddress.h:177
Network m_net
Network to which this address belongs.
Definition: netaddress.h:123
bool IsRFC5737() const
Definition: netaddress.cpp:338
bool IsPrivacyNet() const
Whether this object is a privacy network.
Definition: netaddress.h:188
void SetLegacyIPv6(Span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Definition: netaddress.cpp:137
static constexpr SerParams V1
Definition: netaddress.h:231
bool SetI2P(const std::string &addr)
Parse an I2P address and set this object to it.
Definition: netaddress.cpp:267
void UnserializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE])
Unserialize from a pre-ADDRv2/BIP155 format from an array.
Definition: netaddress.h:399
bool IsRFC6598() const
Definition: netaddress.cpp:333
bool IsRFC1918() const
Definition: netaddress.cpp:315
friend bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:607
bool IsValid() const
Definition: netaddress.cpp:428
bool IsIPv4() const
Definition: netaddress.h:157
BIP155Network GetBIP155Network() const
Get the BIP155 network id of this address.
Definition: netaddress.cpp:26
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
Definition: netaddress.cpp:661
bool SetTor(const std::string &addr)
Parse a Tor address and set this object to it.
Definition: netaddress.cpp:228
void SerializeV1Stream(Stream &s) const
Serialize in pre-ADDRv2/BIP155 format to a stream.
Definition: netaddress.h:362
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
Definition: netaddress.h:129
bool IsRFC3849() const
Definition: netaddress.cpp:345
bool IsHeNet() const
Definition: netaddress.cpp:397
void Serialize(Stream &s) const
Serialize to a stream.
Definition: netaddress.h:238
bool IsLocal() const
Definition: netaddress.cpp:402
void Unserialize(Stream &s)
Unserialize from a stream.
Definition: netaddress.h:251
@ V2
BIP155 encoding.
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition: netaddress.h:296
static constexpr SerParams V2
Definition: netaddress.h:232
bool IsIPv6() const
Definition: netaddress.h:158
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition: netaddress.h:410
bool IsInternal() const
Definition: netaddress.cpp:476
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:48
bool SetInternal(const std::string &name)
Create an "internal" address that represents a name or FQDN.
Definition: netaddress.cpp:172
bool IsRFC4193() const
Definition: netaddress.cpp:373
friend bool operator!=(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.h:212
static constexpr size_t MAX_ADDRV2_SIZE
Maximum size of an address as defined in BIP155 (in bytes).
Definition: netaddress.h:303
bool IsRFC2544() const
Definition: netaddress.cpp:323
enum Network GetNetwork() const
Definition: netaddress.cpp:500
bool IsRFC6145() const
Definition: netaddress.cpp:378
int GetReachabilityFrom(const CNetAddr &paddrPartner) const
Calculates a metric for how reachable (*this) is from a given partner.
Definition: netaddress.cpp:717
CNetAddr()
Construct an unspecified IPv6 network address (::/128).
bool IsRFC3964() const
Definition: netaddress.cpp:350
void UnserializeV2Stream(Stream &s)
Unserialize from a ADDRv2 / BIP155 format.
Definition: netaddress.h:423
bool IsRFC4380() const
Definition: netaddress.cpp:362
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:612
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:481
BIP155Network
BIP155 network ids recognized by this software.
Definition: netaddress.h:263
bool IsRFC3927() const
Definition: netaddress.cpp:328
bool IsRFC4862() const
Definition: netaddress.cpp:367
bool IsRFC4843() const
Definition: netaddress.cpp:385
bool IsI2P() const
Definition: netaddress.h:175
size_t operator()(const CService &a) const noexcept
Definition: netaddress.h:577
const uint64_t m_salt_k0
Definition: netaddress.h:587
CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
Definition: netaddress.h:575
const uint64_t m_salt_k1
Definition: netaddress.h:588
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:531
SERIALIZE_METHODS(CService, obj)
Definition: netaddress.h:557
friend bool operator<(const CService &a, const CService &b)
Definition: netaddress.cpp:847
friend bool operator!=(const CService &a, const CService &b)
Definition: netaddress.h:549
uint16_t GetPort() const
Definition: netaddress.cpp:837
bool SetSockAddr(const struct sockaddr *paddr)
Definition: netaddress.cpp:810
friend bool operator==(const CService &a, const CService &b)
Definition: netaddress.cpp:842
sa_family_t GetSAFamily() const
Get the address family.
Definition: netaddress.cpp:824
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: netbase.cpp:882
uint16_t port
Definition: netaddress.h:533
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
Definition: netaddress.cpp:864
std::string ToStringAddrPort() const
Definition: netaddress.cpp:905
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:897
SipHash-2-4.
Definition: siphash.h:15
uint64_t Finalize() const
Compute the 64-bit SipHash-2-4 of the data written so far.
Definition: siphash.cpp:77
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:525
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:487
CNetAddr network
Network (base) address.
Definition: netaddress.h:483
friend bool operator==(const CSubNet &a, const CSubNet &b)
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:485
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:916
bool Match(const CNetAddr &addr) const
Fast randomness source.
Definition: random.h:377
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:98
size_type size() const
Definition: prevector.h:294
value_type * data()
Definition: prevector.h:533
void resize(size_type new_size)
Definition: prevector.h:328
void assign(size_type n, const T &val)
Definition: prevector.h:223
static CService ip(uint32_t i)
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:245
static constexpr uint8_t CJDNS_PREFIX
All CJDNS addresses start with 0xFC.
Definition: netaddress.h:82
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
Definition: netaddress.h:98
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
Definition: netaddress.h:92
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
Definition: netaddress.h:95
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
Definition: netaddress.h:101
std::string OnionToString(Span< const uint8_t > addr)
Definition: netaddress.cpp:573
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:76
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
Definition: netaddress.h:85
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:68
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:104
Network
A network type.
Definition: netaddress.h:32
@ NET_I2P
I2P.
Definition: netaddress.h:46
@ NET_CJDNS
CJDNS.
Definition: netaddress.h:49
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:56
@ NET_ONION
TOR (v2 or v3)
Definition: netaddress.h:43
@ NET_IPV6
IPv6.
Definition: netaddress.h:40
@ NET_IPV4
IPv4.
Definition: netaddress.h:37
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:34
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:53
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:61
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
Definition: netaddress.h:88
@ IPV6
Definition: netbase.cpp:286
const char * name
Definition: rest.cpp:49
#define SER_PARAMS_OPFUNC
Helper macro for SerParams structs.
Definition: serialize.h:1218
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class.
Definition: serialize.h:495
#define COMPACTSIZE(obj)
Definition: serialize.h:499
#define READWRITE(...)
Definition: serialize.h:156
const Encoding enc
Definition: netaddress.h:228
Serialization wrapper class for custom integers and enums.
Definition: serialize.h:528
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1165
assert(!tx.IsCoinBase())