Bitcoin Core 30.99.0
P2P Digital Currency
netaddress.h
Go to the documentation of this file.
1// Copyright (c) 2009-present 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 <string_view>
22#include <vector>
23
33enum Network {
36
39
42
45
48
51
55
58};
59
62static const std::array<uint8_t, 12> IPV4_IN_IPV6_PREFIX{
63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF};
64
69static const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX{
70 0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43};
71
77static const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX{
78 0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24 // 0xFD + sha256("bitcoin")[0:5].
79};
80
83static constexpr uint8_t CJDNS_PREFIX{0xFC};
84
86static constexpr size_t ADDR_IPV4_SIZE = 4;
87
89static constexpr size_t ADDR_IPV6_SIZE = 16;
90
93static constexpr size_t ADDR_TORV3_SIZE = 32;
94
96static constexpr size_t ADDR_I2P_SIZE = 32;
97
99static constexpr size_t ADDR_CJDNS_SIZE = 16;
100
102static constexpr size_t ADDR_INTERNAL_SIZE = 10;
103
105static constexpr uint16_t I2P_SAM31_PORT{0};
106
107std::string OnionToString(std::span<const uint8_t> addr);
108
113{
114protected:
120
125
130 uint32_t m_scope_id{0};
131
132public:
134 explicit CNetAddr(const struct in_addr& ipv4Addr);
135 void SetIP(const CNetAddr& ip);
136
143 void SetLegacyIPv6(std::span<const uint8_t> ipv6);
144
145 bool SetInternal(const std::string& name);
146
155 bool SetSpecial(std::string_view addr);
156
157 bool IsBindAny() const; // INADDR_ANY equivalent
158 [[nodiscard]] bool IsIPv4() const { return m_net == NET_IPV4; } // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
159 [[nodiscard]] bool IsIPv6() const { return m_net == NET_IPV6; } // IPv6 address (not mapped IPv4, not Tor)
160 bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
161 bool IsRFC2544() const; // IPv4 inter-network communications (198.18.0.0/15)
162 bool IsRFC6598() const; // IPv4 ISP-level NAT (100.64.0.0/10)
163 bool IsRFC5737() const; // IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24)
164 bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32)
165 bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16)
166 bool IsRFC3964() const; // IPv6 6to4 tunnelling (2002::/16)
167 bool IsRFC4193() const; // IPv6 unique local (FC00::/7)
168 bool IsRFC4380() const; // IPv6 Teredo tunnelling (2001::/32)
169 bool IsRFC4843() const; // IPv6 ORCHID (deprecated) (2001:10::/28)
170 bool IsRFC7343() const; // IPv6 ORCHIDv2 (2001:20::/28)
171 bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64)
172 bool IsRFC6052() const; // IPv6 well-known prefix for IPv4-embedded address (64:FF9B::/96)
173 bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) (actually defined in RFC2765)
174 bool IsHeNet() const; // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
175 [[nodiscard]] bool IsTor() const { return m_net == NET_ONION; }
176 [[nodiscard]] bool IsI2P() const { return m_net == NET_I2P; }
177 [[nodiscard]] bool IsCJDNS() const { return m_net == NET_CJDNS; }
178 [[nodiscard]] bool HasCJDNSPrefix() const { return m_addr[0] == CJDNS_PREFIX; }
179 bool IsLocal() const;
180 bool IsRoutable() const;
181 bool IsInternal() const;
182 bool IsValid() const;
183
189 [[nodiscard]] bool IsPrivacyNet() const { return IsTor() || IsI2P(); }
190
194 bool IsAddrV1Compatible() const;
195
196 enum Network GetNetwork() const;
197 std::string ToStringAddr() 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 std::vector<unsigned char> GetAddrBytes() const;
207 int GetReachabilityFrom(const CNetAddr& paddrPartner) const;
208
209 explicit CNetAddr(const struct in6_addr& pipv6Addr, const uint32_t scope = 0);
210 bool GetIn6Addr(struct in6_addr* pipv6Addr) const;
211
212 friend bool operator==(const CNetAddr& a, const CNetAddr& b);
213 friend bool operator!=(const CNetAddr& a, const CNetAddr& b) { return !(a == b); }
214 friend bool operator<(const CNetAddr& a, const CNetAddr& b);
215
219 bool IsRelayable() const
220 {
221 return IsIPv4() || IsIPv6() || IsTor() || IsI2P() || IsCJDNS();
222 }
223
224 enum class Encoding {
225 V1,
226 V2,
227 };
228 struct SerParams {
231 };
232 static constexpr SerParams V1{Encoding::V1};
233 static constexpr SerParams V2{Encoding::V2};
234
238 template <typename Stream>
239 void Serialize(Stream& s) const
240 {
241 if (s.template GetParams<SerParams>().enc == Encoding::V2) {
243 } else {
245 }
246 }
247
251 template <typename Stream>
252 void Unserialize(Stream& s)
253 {
254 if (s.template GetParams<SerParams>().enc == Encoding::V2) {
256 } else {
258 }
259 }
260
264 enum BIP155Network : uint8_t {
265 IPV4 = 1,
266 IPV6 = 2,
267 TORV2 = 3,
268 TORV3 = 4,
269 I2P = 5,
270 CJDNS = 6,
271 };
272
273 friend class CSubNet;
274
275private:
283 bool SetTor(std::string_view addr);
284
292 bool SetI2P(std::string_view addr);
293
297 static constexpr size_t V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE;
298
304 static constexpr size_t MAX_ADDRV2_SIZE = 512;
305
312
320 bool SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size);
321
325 void SerializeV1Array(uint8_t (&arr)[V1_SERIALIZATION_SIZE]) const
326 {
327 size_t prefix_size;
328
329 switch (m_net) {
330 case NET_IPV6:
331 assert(m_addr.size() == sizeof(arr));
332 memcpy(arr, m_addr.data(), m_addr.size());
333 return;
334 case NET_IPV4:
335 prefix_size = sizeof(IPV4_IN_IPV6_PREFIX);
336 assert(prefix_size + m_addr.size() == sizeof(arr));
337 memcpy(arr, IPV4_IN_IPV6_PREFIX.data(), prefix_size);
338 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
339 return;
340 case NET_INTERNAL:
341 prefix_size = sizeof(INTERNAL_IN_IPV6_PREFIX);
342 assert(prefix_size + m_addr.size() == sizeof(arr));
343 memcpy(arr, INTERNAL_IN_IPV6_PREFIX.data(), prefix_size);
344 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
345 return;
346 case NET_ONION:
347 case NET_I2P:
348 case NET_CJDNS:
349 break;
350 case NET_UNROUTABLE:
351 case NET_MAX:
352 assert(false);
353 } // no default case, so the compiler can warn about missing cases
354
355 // Serialize ONION, I2P and CJDNS as all-zeros.
356 memset(arr, 0x0, V1_SERIALIZATION_SIZE);
357 }
358
362 template <typename Stream>
363 void SerializeV1Stream(Stream& s) const
364 {
365 uint8_t serialized[V1_SERIALIZATION_SIZE];
366
367 SerializeV1Array(serialized);
368
369 s << serialized;
370 }
371
375 template <typename Stream>
376 void SerializeV2Stream(Stream& s) const
377 {
378 if (IsInternal()) {
379 // Serialize NET_INTERNAL as embedded in IPv6. We need to
380 // serialize such addresses from addrman.
381 s << static_cast<uint8_t>(BIP155Network::IPV6);
384 return;
385 }
386
387 s << static_cast<uint8_t>(GetBIP155Network());
388 s << m_addr;
389 }
390
401 {
402 // Use SetLegacyIPv6() so that m_net is set correctly. For example
403 // ::FFFF:0102:0304 should be set as m_net=NET_IPV4 (1.2.3.4).
404 SetLegacyIPv6(arr);
405 }
406
410 template <typename Stream>
411 void UnserializeV1Stream(Stream& s)
412 {
413 uint8_t serialized[V1_SERIALIZATION_SIZE];
414
415 s >> serialized;
416
417 UnserializeV1Array(serialized);
418 }
419
423 template <typename Stream>
424 void UnserializeV2Stream(Stream& s)
425 {
426 uint8_t bip155_net;
427 s >> bip155_net;
428
429 size_t address_size;
430 s >> COMPACTSIZE(address_size);
431
432 if (address_size > MAX_ADDRV2_SIZE) {
433 throw std::ios_base::failure(strprintf(
434 "Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
435 }
436
437 m_scope_id = 0;
438
439 if (SetNetFromBIP155Network(bip155_net, address_size)) {
440 m_addr.resize(address_size);
441 s >> std::span{m_addr};
442
443 if (m_net != NET_IPV6) {
444 return;
445 }
446
447 // Do some special checks on IPv6 addresses.
448
449 // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
450 // gossiped but could be coming from addrman, when unserializing from
451 // disk.
454 memmove(m_addr.data(), m_addr.data() + INTERNAL_IN_IPV6_PREFIX.size(),
457 return;
458 }
459
462 return;
463 }
464
465 // IPv4 and TORv2 are not supposed to be embedded in IPv6 (like in V1
466 // encoding). Unserialize as !IsValid(), thus ignoring them.
467 } else {
468 // If we receive an unknown BIP155 network id (from the future?) then
469 // ignore the address - unserialize as !IsValid().
470 s.ignore(address_size);
471 }
472
473 // Mimic a default-constructed CNetAddr object which is !IsValid() and thus
474 // will not be gossiped, but continue reading next addresses from the stream.
475 m_net = NET_IPV6;
477 }
478};
479
481{
482protected:
486 uint8_t netmask[16];
488 bool valid;
489
490public:
494 CSubNet();
495
503 CSubNet(const CNetAddr& addr, uint8_t mask);
504
512 CSubNet(const CNetAddr& addr, const CNetAddr& mask);
513
518 explicit CSubNet(const CNetAddr& addr);
519
520 bool Match(const CNetAddr& addr) const;
521
522 std::string ToString() const;
523 bool IsValid() const;
524
525 friend bool operator==(const CSubNet& a, const CSubNet& b);
526 friend bool operator!=(const CSubNet& a, const CSubNet& b) { return !(a == b); }
527 friend bool operator<(const CSubNet& a, const CSubNet& b);
528};
529
531class CService : public CNetAddr
532{
533protected:
534 uint16_t port; // host order
535
536public:
537 CService();
538 CService(const CNetAddr& ip, uint16_t port);
539 CService(const struct in_addr& ipv4Addr, uint16_t port);
540 explicit CService(const struct sockaddr_in& addr);
541 uint16_t GetPort() const;
542 bool GetSockAddr(struct sockaddr* paddr, socklen_t* addrlen) const;
550 bool SetSockAddr(const struct sockaddr* paddr, socklen_t addrlen);
555 [[nodiscard]] sa_family_t GetSAFamily() const;
556 friend bool operator==(const CService& a, const CService& b);
557 friend bool operator!=(const CService& a, const CService& b) { return !(a == b); }
558 friend bool operator<(const CService& a, const CService& b);
559 std::vector<unsigned char> GetKey() const;
560 std::string ToStringAddrPort() const;
561
562 CService(const struct in6_addr& ipv6Addr, uint16_t port);
563 explicit CService(const struct sockaddr_in6& addr);
564
566 {
567 READWRITE(AsBase<CNetAddr>(obj), Using<BigEndianFormatter<2>>(obj.port));
568 }
569
570 friend class CServiceHash;
571 friend CService MaybeFlipIPv6toCJDNS(const CService& service);
572};
573
575{
576public:
578 : m_salt_k0{FastRandomContext().rand64()},
579 m_salt_k1{FastRandomContext().rand64()}
580 {
581 }
582
583 CServiceHash(uint64_t salt_k0, uint64_t salt_k1) : m_salt_k0{salt_k0}, m_salt_k1{salt_k1} {}
584
585 size_t operator()(const CService& a) const noexcept
586 {
588 hasher.Write(a.m_net);
589 hasher.Write(a.port);
590 hasher.Write(a.m_addr);
591 return static_cast<size_t>(hasher.Finalize());
592 }
593
594private:
595 const uint64_t m_salt_k0;
596 const uint64_t m_salt_k1;
597};
598
599#endif // BITCOIN_NETADDRESS_H
Network address.
Definition: netaddress.h:113
Network GetNetClass() const
Definition: netaddress.cpp:674
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition: netaddress.h:325
bool IsRelayable() const
Whether this address should be relayed to other peers even if we can't reach it ourselves.
Definition: netaddress.h:219
std::string ToStringAddr() const
Definition: netaddress.cpp:580
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
Definition: netaddress.h:376
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
Definition: netaddress.h:119
bool IsBindAny() const
Definition: netaddress.cpp:303
bool IsRFC6052() const
Definition: netaddress.cpp:351
void SetIP(const CNetAddr &ip)
Definition: netaddress.cpp:107
bool IsRFC7343() const
Definition: netaddress.cpp:387
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Try to get our IPv6 (or CJDNS) address.
Definition: netaddress.cpp:642
std::vector< unsigned char > GetAddrBytes() const
Definition: netaddress.cpp:692
bool IsCJDNS() const
Definition: netaddress.h:177
bool IsTor() const
Definition: netaddress.h:175
bool IsRoutable() const
Definition: netaddress.cpp:462
bool GetInAddr(struct in_addr *pipv4Addr) const
Try to get our IPv4 address.
Definition: netaddress.cpp:623
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition: netaddress.cpp:652
bool HasCJDNSPrefix() const
Definition: netaddress.h:178
Network m_net
Network to which this address belongs.
Definition: netaddress.h:124
bool IsRFC5737() const
Definition: netaddress.cpp:334
bool IsPrivacyNet() const
Whether this object is a privacy network.
Definition: netaddress.h:189
static constexpr SerParams V1
Definition: netaddress.h:232
bool SetSpecial(std::string_view addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:212
void UnserializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE])
Unserialize from a pre-ADDRv2/BIP155 format from an array.
Definition: netaddress.h:400
bool IsRFC6598() const
Definition: netaddress.cpp:329
bool IsRFC1918() const
Definition: netaddress.cpp:311
friend bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:603
bool IsValid() const
Definition: netaddress.cpp:424
bool IsIPv4() const
Definition: netaddress.h:158
BIP155Network GetBIP155Network() const
Get the BIP155 network id of this address.
Definition: netaddress.cpp:27
void SetLegacyIPv6(std::span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Definition: netaddress.cpp:138
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
Definition: netaddress.cpp:657
void SerializeV1Stream(Stream &s) const
Serialize in pre-ADDRv2/BIP155 format to a stream.
Definition: netaddress.h:363
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
Definition: netaddress.h:130
bool IsRFC3849() const
Definition: netaddress.cpp:341
bool IsHeNet() const
Definition: netaddress.cpp:393
void Serialize(Stream &s) const
Serialize to a stream.
Definition: netaddress.h:239
bool IsLocal() const
Definition: netaddress.cpp:398
void Unserialize(Stream &s)
Unserialize from a stream.
Definition: netaddress.h:252
bool SetI2P(std::string_view addr)
Parse an I2P address and set this object to it.
Definition: netaddress.cpp:263
@ V2
BIP155 encoding.
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition: netaddress.h:297
static constexpr SerParams V2
Definition: netaddress.h:233
bool IsIPv6() const
Definition: netaddress.h:159
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition: netaddress.h:411
bool IsInternal() const
Definition: netaddress.cpp:472
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:369
friend bool operator!=(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.h:213
static constexpr size_t MAX_ADDRV2_SIZE
Maximum size of an address as defined in BIP155 (in bytes).
Definition: netaddress.h:304
bool IsRFC2544() const
Definition: netaddress.cpp:319
enum Network GetNetwork() const
Definition: netaddress.cpp:496
bool IsRFC6145() const
Definition: netaddress.cpp:374
int GetReachabilityFrom(const CNetAddr &paddrPartner) const
Calculates a metric for how reachable (*this) is from a given partner.
Definition: netaddress.cpp:713
CNetAddr()
Construct an unspecified IPv6 network address (::/128).
bool IsRFC3964() const
Definition: netaddress.cpp:346
void UnserializeV2Stream(Stream &s)
Unserialize from a ADDRv2 / BIP155 format.
Definition: netaddress.h:424
bool SetTor(std::string_view addr)
Parse a Tor address and set this object to it.
Definition: netaddress.cpp:229
bool IsRFC4380() const
Definition: netaddress.cpp:358
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:608
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:477
BIP155Network
BIP155 network ids recognized by this software.
Definition: netaddress.h:264
bool IsRFC3927() const
Definition: netaddress.cpp:324
bool IsRFC4862() const
Definition: netaddress.cpp:363
bool IsRFC4843() const
Definition: netaddress.cpp:381
bool IsI2P() const
Definition: netaddress.h:176
size_t operator()(const CService &a) const noexcept
Definition: netaddress.h:585
const uint64_t m_salt_k0
Definition: netaddress.h:595
CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
Definition: netaddress.h:583
const uint64_t m_salt_k1
Definition: netaddress.h:596
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:532
SERIALIZE_METHODS(CService, obj)
Definition: netaddress.h:565
friend bool operator<(const CService &a, const CService &b)
Definition: netaddress.cpp:845
bool SetSockAddr(const struct sockaddr *paddr, socklen_t addrlen)
Set CService from a network sockaddr.
Definition: netaddress.cpp:806
friend bool operator!=(const CService &a, const CService &b)
Definition: netaddress.h:557
uint16_t GetPort() const
Definition: netaddress.cpp:835
friend bool operator==(const CService &a, const CService &b)
Definition: netaddress.cpp:840
sa_family_t GetSAFamily() const
Get the address family.
Definition: netaddress.cpp:822
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:946
uint16_t port
Definition: netaddress.h:534
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
Definition: netaddress.cpp:862
std::string ToStringAddrPort() const
Definition: netaddress.cpp:903
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:895
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:81
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:32
friend bool operator!=(const CSubNet &a, const CSubNet &b)
Definition: netaddress.h:526
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:488
CNetAddr network
Network (base) address.
Definition: netaddress.h:484
friend bool operator==(const CSubNet &a, const CSubNet &b)
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:486
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:914
bool Match(const CNetAddr &addr) const
Fast randomness source.
Definition: random.h:386
size_type size() const
Definition: prevector.h:255
value_type * data()
Definition: prevector.h:489
void resize(size_type new_size)
Definition: prevector.h:284
void assign(size_type n, const T &val)
Definition: prevector.h:184
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:257
static constexpr uint8_t CJDNS_PREFIX
All CJDNS addresses start with 0xFC.
Definition: netaddress.h:83
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
Definition: netaddress.h:99
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
Definition: netaddress.h:93
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
Definition: netaddress.h:96
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
Definition: netaddress.h:102
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:77
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
Definition: netaddress.h:86
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:69
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:105
Network
A network type.
Definition: netaddress.h:33
@ NET_I2P
I2P.
Definition: netaddress.h:47
@ NET_CJDNS
CJDNS.
Definition: netaddress.h:50
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:57
@ NET_ONION
TOR (v2 or v3)
Definition: netaddress.h:44
@ NET_IPV6
IPv6.
Definition: netaddress.h:41
@ NET_IPV4
IPv4.
Definition: netaddress.h:38
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:35
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:54
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:62
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
Definition: netaddress.h:89
std::string OnionToString(std::span< const uint8_t > addr)
Definition: netaddress.cpp:569
@ IPV6
Definition: netbase.cpp:294
const char * name
Definition: rest.cpp:48
#define SER_PARAMS_OPFUNC
Helper macro for SerParams structs.
Definition: serialize.h:1211
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class.
Definition: serialize.h:488
#define COMPACTSIZE(obj)
Definition: serialize.h:492
#define READWRITE(...)
Definition: serialize.h:145
const Encoding enc
Definition: netaddress.h:229
Serialization wrapper class for custom integers and enums.
Definition: serialize.h:521
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1172
assert(!tx.IsCoinBase())