Bitcoin ABC 0.32.5
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 <compat.h>
13#include <crypto/siphash.h>
14#include <prevector.h>
15#include <random.h>
16#include <serialize.h>
17#include <util/strencodings.h>
18#include <util/string.h>
19
20#include <tinyformat.h>
21
22#include <array>
23#include <cstdint>
24#include <ios>
25#include <string>
26#include <vector>
27
33static constexpr int ADDRV2_FORMAT = 0x20000000;
34
44enum Network {
48
51
54
57
60
63
67
70};
71
74static const std::array<uint8_t, 12> IPV4_IN_IPV6_PREFIX{
75 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}};
76
81static const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX{
82 {0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43}};
83
89static const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX{
90 // 0xFD + sha256("bitcoin")[0:5].
91 {0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24}};
92
94static constexpr size_t ADDR_IPV4_SIZE = 4;
95
97static constexpr size_t ADDR_IPV6_SIZE = 16;
98
100static constexpr size_t ADDR_TORV2_SIZE = 10;
101
104static constexpr size_t ADDR_TORV3_SIZE = 32;
105
107static constexpr size_t ADDR_I2P_SIZE = 32;
108
110static constexpr size_t ADDR_CJDNS_SIZE = 16;
111
113static constexpr size_t ADDR_INTERNAL_SIZE = 10;
114
116static constexpr uint16_t I2P_SAM31_PORT{0};
117
121class CNetAddr {
122protected:
128
133
138 uint32_t m_scope_id{0};
139
140public:
142 explicit CNetAddr(const struct in_addr &ipv4Addr);
143 void SetIP(const CNetAddr &ip);
144
152
153 bool SetInternal(const std::string &name);
154
163 bool SetSpecial(const std::string &addr);
164
165 // INADDR_ANY equivalent
166 bool IsBindAny() const;
167 // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
168 bool IsIPv4() const;
169 // IPv6 address (not mapped IPv4, not Tor)
170 bool IsIPv6() const;
171 // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
172 bool IsRFC1918() const;
173 // IPv4 inter-network communications (198.18.0.0/15)
174 bool IsRFC2544() const;
175 // IPv4 ISP-level NAT (100.64.0.0/10)
176 bool IsRFC6598() const;
177 // IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24,
178 // 203.0.113.0/24)
179 bool IsRFC5737() const;
180 // IPv6 documentation address (2001:0DB8::/32)
181 bool IsRFC3849() const;
182 // IPv4 autoconfig (169.254.0.0/16)
183 bool IsRFC3927() const;
184 // IPv6 6to4 tunnelling (2002::/16)
185 bool IsRFC3964() const;
186 // IPv6 unique local (FC00::/7)
187 bool IsRFC4193() const;
188 // IPv6 Teredo tunnelling (2001::/32)
189 bool IsRFC4380() const;
190 // IPv6 ORCHID (deprecated) (2001:10::/28)
191 bool IsRFC4843() const;
192 // IPv6 ORCHIDv2 (2001:20::/28)
193 bool IsRFC7343() const;
194 // IPv6 autoconfig (FE80::/64)
195 bool IsRFC4862() const;
196 // IPv6 well-known prefix for IPv4-embedded address (64:FF9B::/96)
197 bool IsRFC6052() const;
198 // IPv6 IPv4-translated address (::FFFF:0:0:0/96) (actually defined in
199 // RFC2765)
200 bool IsRFC6145() const;
201 // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
202 bool IsHeNet() const;
203 bool IsTor() const;
204 bool IsI2P() const;
205 bool IsCJDNS() const;
206 bool IsLocal() const;
207 bool IsRoutable() const;
208 bool IsInternal() const;
209 bool IsValid() const;
210
215 bool IsAddrV1Compatible() const;
216
217 enum Network GetNetwork() const;
218 std::string ToString() const;
219 std::string ToStringIP() const;
220 bool GetInAddr(struct in_addr *pipv4Addr) const;
221 Network GetNetClass() const;
222
225 uint32_t GetLinkedIPv4() const;
227 bool HasLinkedIPv4() const;
228
229 // The AS on the BGP path to the node we use to diversify
230 // peers in AddrMan bucketing based on the AS infrastructure.
231 // The ip->AS mapping depends on how asmap is constructed.
232 uint32_t GetMappedAS(const std::vector<bool> &asmap) const;
233
234 std::vector<uint8_t> GetGroup(const std::vector<bool> &asmap) const;
235 std::vector<uint8_t> GetAddrBytes() const;
236 int GetReachabilityFrom(const CNetAddr *paddrPartner = nullptr) const;
237
238 explicit CNetAddr(const struct in6_addr &pipv6Addr,
239 const uint32_t scope = 0);
240 bool GetIn6Addr(struct in6_addr *pipv6Addr) const;
241
242 friend bool operator==(const CNetAddr &a, const CNetAddr &b);
243 friend bool operator!=(const CNetAddr &a, const CNetAddr &b) {
244 return !(a == b);
245 }
246 friend bool operator<(const CNetAddr &a, const CNetAddr &b);
247
252 bool IsRelayable() const { return IsIPv4() || IsIPv6() || IsTor(); }
253
257 template <typename Stream> void Serialize(Stream &s) const {
258 if (s.GetVersion() & ADDRV2_FORMAT) {
260 } else {
262 }
263 }
264
268 template <typename Stream> void Unserialize(Stream &s) {
269 if (s.GetVersion() & ADDRV2_FORMAT) {
271 } else {
273 }
274 }
275
276 friend class CSubNet;
277
278private:
287 bool SetTor(const std::string &addr);
288
296 bool SetI2P(const std::string &addr);
297
301 enum BIP155Network : uint8_t {
302 IPV4 = 1,
303 IPV6 = 2,
304 TORV2 = 3,
305 TORV3 = 4,
306 I2P = 5,
307 CJDNS = 6,
308 };
309
313 static constexpr size_t V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE;
314
320 static constexpr size_t MAX_ADDRV2_SIZE = 512;
321
328
339 bool SetNetFromBIP155Network(uint8_t possible_bip155_net,
340 size_t address_size);
341
345 void SerializeV1Array(uint8_t (&arr)[V1_SERIALIZATION_SIZE]) const {
346 size_t prefix_size;
347
348 switch (m_net) {
349 case NET_IPV6:
350 assert(m_addr.size() == sizeof(arr));
351 memcpy(arr, m_addr.data(), m_addr.size());
352 return;
353 case NET_IPV4:
354 prefix_size = sizeof(IPV4_IN_IPV6_PREFIX);
355 assert(prefix_size + m_addr.size() == sizeof(arr));
356 memcpy(arr, IPV4_IN_IPV6_PREFIX.data(), prefix_size);
357 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
358 return;
359 case NET_ONION:
360 if (m_addr.size() == ADDR_TORV3_SIZE) {
361 break;
362 }
363 prefix_size = sizeof(TORV2_IN_IPV6_PREFIX);
364 assert(prefix_size + m_addr.size() == sizeof(arr));
365 memcpy(arr, TORV2_IN_IPV6_PREFIX.data(), prefix_size);
366 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
367 return;
368 case NET_INTERNAL:
369 prefix_size = sizeof(INTERNAL_IN_IPV6_PREFIX);
370 assert(prefix_size + m_addr.size() == sizeof(arr));
371 memcpy(arr, INTERNAL_IN_IPV6_PREFIX.data(), prefix_size);
372 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
373 return;
374 case NET_I2P:
375 break;
376 case NET_CJDNS:
377 break;
378 case NET_UNROUTABLE:
379 case NET_MAX:
380 assert(false);
381 } // no default case, so the compiler can warn about missing cases
382
383 // Serialize TORv3, I2P and CJDNS as all-zeros.
384 memset(arr, 0x0, V1_SERIALIZATION_SIZE);
385 }
386
390 template <typename Stream> void SerializeV1Stream(Stream &s) const {
391 uint8_t serialized[V1_SERIALIZATION_SIZE];
392
393 SerializeV1Array(serialized);
394
395 s << serialized;
396 }
397
401 template <typename Stream> void SerializeV2Stream(Stream &s) const {
402 if (IsInternal()) {
403 // Serialize NET_INTERNAL as embedded in IPv6. We need to
404 // serialize such addresses from addrman.
405 s << static_cast<uint8_t>(BIP155Network::IPV6);
408 return;
409 }
410
411 s << static_cast<uint8_t>(GetBIP155Network());
412 s << m_addr;
413 }
414
419 // Use SetLegacyIPv6() so that m_net is set correctly. For example
420 // ::FFFF:0102:0304 should be set as m_net=NET_IPV4 (1.2.3.4).
421 SetLegacyIPv6(arr);
422 }
423
427 template <typename Stream> void UnserializeV1Stream(Stream &s) {
428 uint8_t serialized[V1_SERIALIZATION_SIZE];
429
430 s >> serialized;
431
432 UnserializeV1Array(serialized);
433 }
434
438 template <typename Stream> void UnserializeV2Stream(Stream &s) {
439 uint8_t bip155_net;
440 s >> bip155_net;
441
442 size_t address_size;
443 s >> COMPACTSIZE(address_size);
444
445 if (address_size > MAX_ADDRV2_SIZE) {
446 throw std::ios_base::failure(strprintf(
447 "Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
448 }
449
450 m_scope_id = 0;
451
452 if (SetNetFromBIP155Network(bip155_net, address_size)) {
453 m_addr.resize(address_size);
454 s >> Span{m_addr};
455
456 if (m_net != NET_IPV6) {
457 return;
458 }
459
460 // Do some special checks on IPv6 addresses.
461
462 // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
463 // gossiped but could be coming from addrman, when unserializing
464 // from disk.
467 memmove(m_addr.data(),
471 return;
472 }
473
476 return;
477 }
478
479 // IPv4 and TORv2 are not supposed to be embedded in IPv6 (like in
480 // V1 encoding). Unserialize as !IsValid(), thus ignoring them.
481 } else {
482 // If we receive an unknown BIP155 network id (from the future?)
483 // then ignore the address - unserialize as !IsValid().
484 s.ignore(address_size);
485 }
486
487 // Mimic a default-constructed CNetAddr object which is !IsValid() and
488 // thus will not be gossiped, but continue reading next addresses from
489 // the stream.
490 m_net = NET_IPV6;
492 }
493};
494
495class CSubNet {
496protected:
500 uint8_t netmask[16];
502 bool valid;
503
504 bool SanityCheck() const;
505
506public:
510 CSubNet();
511
519 CSubNet(const CNetAddr &addr, uint8_t mask);
520
529 CSubNet(const CNetAddr &addr, const CNetAddr &mask);
530
536 explicit CSubNet(const CNetAddr &addr);
537
538 bool Match(const CNetAddr &addr) const;
539
540 std::string ToString() const;
541 bool IsValid() const;
542
543 friend bool operator==(const CSubNet &a, const CSubNet &b);
544 friend bool operator!=(const CSubNet &a, const CSubNet &b) {
545 return !(a == b);
546 }
547 friend bool operator<(const CSubNet &a, const CSubNet &b);
548
550 READWRITE(obj.network);
551 if (obj.network.IsIPv4()) {
552 // Before D9176, CSubNet used the last 4 bytes of netmask to store
553 // the relevant bytes for an IPv4 mask. For compatiblity reasons,
554 // keep doing so in serialized form.
555 uint8_t dummy[12] = {0};
556 auto netmask_span = Span{obj.netmask};
557 READWRITE(dummy);
558 READWRITE(netmask_span.first(4));
559 } else {
560 READWRITE(obj.netmask);
561 }
562 READWRITE(obj.valid);
563 // Mark invalid if the result doesn't pass sanity checking.
564 SER_READ(obj, if (obj.valid) obj.valid = obj.SanityCheck());
565 }
566};
567
569class CService : public CNetAddr {
570protected:
571 // host order
572 uint16_t port;
573
574public:
575 CService();
576 CService(const CNetAddr &ip, uint16_t port);
577 CService(const struct in_addr &ipv4Addr, uint16_t port);
578 explicit CService(const struct sockaddr_in &addr);
579 uint16_t GetPort() const;
580 bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const;
581 bool SetSockAddr(const struct sockaddr *paddr);
582 friend bool operator==(const CService &a, const CService &b);
583 friend bool operator!=(const CService &a, const CService &b) {
584 return !(a == b);
585 }
586 friend bool operator<(const CService &a, const CService &b);
587 std::vector<uint8_t> GetKey() const;
588 std::string ToString() const;
589 std::string ToStringPort() const;
590 std::string ToStringIPPort() const;
591
592 CService(const struct in6_addr &ipv6Addr, uint16_t port);
593 explicit CService(const struct sockaddr_in6 &addr);
594
596 READWRITE(AsBase<CNetAddr>(obj),
597 Using<BigEndianFormatter<2>>(obj.port));
598 }
599
600 friend class CServiceHash;
601};
602
604public:
606 : m_salt_k0{FastRandomContext().rand64()},
607 m_salt_k1{FastRandomContext().rand64()} {}
608
609 CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
610 : m_salt_k0{salt_k0}, m_salt_k1{salt_k1} {}
611
612 size_t operator()(const CService &a) const noexcept {
614 hasher.Write(a.m_net);
615 hasher.Write(a.port);
616 hasher.Write(a.m_addr);
617 return static_cast<size_t>(hasher.Finalize());
618 }
619
620private:
621 const uint64_t m_salt_k0;
622 const uint64_t m_salt_k1;
623};
624
625#endif // BITCOIN_NETADDRESS_H
Network address.
Definition: netaddress.h:121
Network GetNetClass() const
Definition: netaddress.cpp:741
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition: netaddress.h:345
bool IsRelayable() const
Whether this address should be relayed to other peers even if we can't reach it ourselves.
Definition: netaddress.h:252
std::string ToStringIP() const
Definition: netaddress.cpp:623
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
Definition: netaddress.h:401
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
Definition: netaddress.h:127
bool IsBindAny() const
Definition: netaddress.cpp:329
bool IsRFC6052() const
Definition: netaddress.cpp:379
void SetIP(const CNetAddr &ip)
Definition: netaddress.cpp:122
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:224
bool IsRFC7343() const
Definition: netaddress.cpp:414
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Try to get our IPv6 address.
Definition: netaddress.cpp:709
std::string ToString() const
Definition: netaddress.cpp:668
bool IsCJDNS() const
Check whether this object represents a CJDNS address.
Definition: netaddress.cpp:444
bool IsTor() const
Check whether this object represents a TOR address.
Definition: netaddress.cpp:430
bool IsRoutable() const
Definition: netaddress.cpp:509
bool GetInAddr(struct in_addr *pipv4Addr) const
Try to get our IPv4 address.
Definition: netaddress.cpp:690
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition: netaddress.cpp:718
Network m_net
Network to which this address belongs.
Definition: netaddress.h:132
bool IsRFC5737() const
Definition: netaddress.cpp:363
void SetLegacyIPv6(Span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Definition: netaddress.cpp:153
bool SetI2P(const std::string &addr)
Parse an I2P address and set this object to it.
Definition: netaddress.cpp:289
void UnserializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE])
Unserialize from a pre-ADDRv2/BIP155 format from an array.
Definition: netaddress.h:418
bool IsRFC6598() const
Definition: netaddress.cpp:359
bool IsRFC1918() const
Definition: netaddress.cpp:345
friend bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:672
bool IsValid() const
Definition: netaddress.cpp:474
bool IsIPv4() const
Definition: netaddress.cpp:337
BIP155Network GetBIP155Network() const
Get the BIP155 network id of this address.
Definition: netaddress.cpp:25
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
Definition: netaddress.cpp:723
bool SetTor(const std::string &addr)
Parse a Tor address and set this object to it.
Definition: netaddress.cpp:240
void SerializeV1Stream(Stream &s) const
Serialize in pre-ADDRv2/BIP155 format to a stream.
Definition: netaddress.h:390
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
Definition: netaddress.h:138
bool IsRFC3849() const
Definition: netaddress.cpp:370
bool IsHeNet() const
Definition: netaddress.cpp:420
void Serialize(Stream &s) const
Serialize to a stream.
Definition: netaddress.h:257
bool IsLocal() const
Definition: netaddress.cpp:448
void Unserialize(Stream &s)
Unserialize from a stream.
Definition: netaddress.h:268
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition: netaddress.h:313
bool IsIPv6() const
Definition: netaddress.cpp:341
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition: netaddress.h:427
bool IsInternal() const
Definition: netaddress.cpp:521
std::vector< uint8_t > GetGroup(const std::vector< bool > &asmap) const
Get the canonical identifier of our network group.
Definition: netaddress.cpp:803
std::vector< uint8_t > GetAddrBytes() const
Definition: netaddress.cpp:858
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:56
bool SetInternal(const std::string &name)
Create an "internal" address that represents a name or FQDN.
Definition: netaddress.cpp:185
bool IsRFC4193() const
Definition: netaddress.cpp:397
friend bool operator!=(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.h:243
uint32_t GetMappedAS(const std::vector< bool > &asmap) const
Definition: netaddress.cpp:759
int GetReachabilityFrom(const CNetAddr *paddrPartner=nullptr) const
Calculates a metric for how reachable (*this) is from a given partner.
Definition: netaddress.cpp:882
static constexpr size_t MAX_ADDRV2_SIZE
Maximum size of an address as defined in BIP155 (in bytes).
Definition: netaddress.h:320
bool IsRFC2544() const
Definition: netaddress.cpp:351
enum Network GetNetwork() const
Definition: netaddress.cpp:546
bool IsRFC6145() const
Definition: netaddress.cpp:401
CNetAddr()
Construct an unspecified IPv6 network address (::/128).
bool IsRFC3964() const
Definition: netaddress.cpp:375
void UnserializeV2Stream(Stream &s)
Unserialize from a ADDRv2 / BIP155 format.
Definition: netaddress.h:438
bool IsRFC4380() const
Definition: netaddress.cpp:386
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:676
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:525
BIP155Network
BIP155 network ids recognized by this software.
Definition: netaddress.h:301
bool IsRFC3927() const
Definition: netaddress.cpp:355
bool IsRFC4862() const
Definition: netaddress.cpp:391
bool IsRFC4843() const
Definition: netaddress.cpp:408
bool IsI2P() const
Check whether this object represents an I2P address.
Definition: netaddress.cpp:437
size_t operator()(const CService &a) const noexcept
Definition: netaddress.h:612
const uint64_t m_salt_k0
Definition: netaddress.h:621
CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
Definition: netaddress.h:609
const uint64_t m_salt_k1
Definition: netaddress.h:622
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:569
SERIALIZE_METHODS(CService, obj)
Definition: netaddress.h:595
std::string ToStringIPPort() const
std::string ToString() const
friend bool operator<(const CService &a, const CService &b)
std::vector< uint8_t > GetKey() const
friend bool operator!=(const CService &a, const CService &b)
Definition: netaddress.h:583
uint16_t GetPort() const
bool SetSockAddr(const struct sockaddr *paddr)
Definition: netaddress.cpp:990
friend bool operator==(const CService &a, const CService &b)
std::string ToStringPort() const
uint16_t port
Definition: netaddress.h:572
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
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:83
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:544
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:502
CNetAddr network
Network (base) address.
Definition: netaddress.h:498
bool SanityCheck() const
friend bool operator==(const CSubNet &a, const CSubNet &b)
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:500
std::string ToString() const
SERIALIZE_METHODS(CSubNet, obj)
Definition: netaddress.h:549
bool IsValid() const
friend bool operator<(const CSubNet &a, const CSubNet &b)
CSubNet()
Construct an invalid subnet (empty, Match() always returns false).
bool Match(const CNetAddr &addr) const
Fast randomness source.
Definition: random.h:411
size_type size() const
Definition: prevector.h:396
value_type * data()
Definition: prevector.h:620
void resize(size_type new_size)
Definition: prevector.h:426
void assign(size_type n, const T &val)
Definition: prevector.h:328
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
Definition: netaddress.h:110
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:104
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
Definition: netaddress.h:107
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
Definition: netaddress.h:113
static constexpr size_t ADDR_TORV2_SIZE
Size of TORv2 address (in bytes).
Definition: netaddress.h:100
static const std::array< uint8_t, 6 > INTERNAL_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded "internal" address.
Definition: netaddress.h:89
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
Definition: netaddress.h:94
static const std::array< uint8_t, 6 > TORV2_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded TORv2 address.
Definition: netaddress.h:81
static constexpr uint16_t I2P_SAM31_PORT
SAM 3.1 and earlier do not support specifying ports and force the port to 0.
Definition: netaddress.h:116
Network
A network type.
Definition: netaddress.h:44
@ NET_I2P
I2P.
Definition: netaddress.h:59
@ NET_CJDNS
CJDNS.
Definition: netaddress.h:62
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:69
@ NET_ONION
TOR (v2 or v3)
Definition: netaddress.h:56
@ NET_IPV6
IPv6.
Definition: netaddress.h:53
@ NET_IPV4
IPv4.
Definition: netaddress.h:50
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:47
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:66
static const std::array< uint8_t, 12 > IPV4_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded IPv4 address.
Definition: netaddress.h:74
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
Definition: netaddress.h:97
@ IPV6
Definition: netbase.cpp:308
const char * name
Definition: rest.cpp:47
#define SER_READ(obj, code)
Definition: serialize.h:190
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class.
Definition: serialize.h:638
#define COMPACTSIZE(obj)
Definition: serialize.h:644
#define READWRITE(...)
Definition: serialize.h:189
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:120
Serialization wrapper class for custom integers and enums.
Definition: serialize.h:670
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
assert(!tx.IsCoinBase())