Bitcoin ABC 0.32.11
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/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
37enum Network {
41
44
47
50
53
56
60
63};
64
67static const std::array<uint8_t, 12> IPV4_IN_IPV6_PREFIX{
68 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}};
69
74static const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX{
75 {0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43}};
76
82static const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX{
83 // 0xFD + sha256("bitcoin")[0:5].
84 {0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24}};
85
87static constexpr size_t ADDR_IPV4_SIZE = 4;
88
90static constexpr size_t ADDR_IPV6_SIZE = 16;
91
93static constexpr size_t ADDR_TORV2_SIZE = 10;
94
97static constexpr size_t ADDR_TORV3_SIZE = 32;
98
100static constexpr size_t ADDR_I2P_SIZE = 32;
101
103static constexpr size_t ADDR_CJDNS_SIZE = 16;
104
106static constexpr size_t ADDR_INTERNAL_SIZE = 10;
107
109static constexpr uint16_t I2P_SAM31_PORT{0};
110
114class CNetAddr {
115protected:
121
126
131 uint32_t m_scope_id{0};
132
133public:
135 explicit CNetAddr(const struct in_addr &ipv4Addr);
136 void SetIP(const CNetAddr &ip);
137
145
146 bool SetInternal(const std::string &name);
147
156 bool SetSpecial(const std::string &addr);
157
158 // INADDR_ANY equivalent
159 bool IsBindAny() const;
160 // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
161 bool IsIPv4() const;
162 // IPv6 address (not mapped IPv4, not Tor)
163 bool IsIPv6() const;
164 // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
165 bool IsRFC1918() const;
166 // IPv4 inter-network communications (198.18.0.0/15)
167 bool IsRFC2544() const;
168 // IPv4 ISP-level NAT (100.64.0.0/10)
169 bool IsRFC6598() const;
170 // IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24,
171 // 203.0.113.0/24)
172 bool IsRFC5737() const;
173 // IPv6 documentation address (2001:0DB8::/32)
174 bool IsRFC3849() const;
175 // IPv4 autoconfig (169.254.0.0/16)
176 bool IsRFC3927() const;
177 // IPv6 6to4 tunnelling (2002::/16)
178 bool IsRFC3964() const;
179 // IPv6 unique local (FC00::/7)
180 bool IsRFC4193() const;
181 // IPv6 Teredo tunnelling (2001::/32)
182 bool IsRFC4380() const;
183 // IPv6 ORCHID (deprecated) (2001:10::/28)
184 bool IsRFC4843() const;
185 // IPv6 ORCHIDv2 (2001:20::/28)
186 bool IsRFC7343() const;
187 // IPv6 autoconfig (FE80::/64)
188 bool IsRFC4862() const;
189 // IPv6 well-known prefix for IPv4-embedded address (64:FF9B::/96)
190 bool IsRFC6052() const;
191 // IPv6 IPv4-translated address (::FFFF:0:0:0/96) (actually defined in
192 // RFC2765)
193 bool IsRFC6145() const;
194 // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
195 bool IsHeNet() const;
196 bool IsTor() const;
197 bool IsI2P() const;
198 bool IsCJDNS() const;
199 bool IsLocal() const;
200 bool IsRoutable() const;
201 bool IsInternal() const;
202 bool IsValid() const;
203
208 bool IsAddrV1Compatible() const;
209
210 enum Network GetNetwork() const;
211 std::string ToStringAddr() const;
212 bool GetInAddr(struct in_addr *pipv4Addr) const;
213 Network GetNetClass() const;
214
217 uint32_t GetLinkedIPv4() const;
219 bool HasLinkedIPv4() const;
220
221 // The AS on the BGP path to the node we use to diversify
222 // peers in AddrMan bucketing based on the AS infrastructure.
223 // The ip->AS mapping depends on how asmap is constructed.
224 uint32_t GetMappedAS(const std::vector<bool> &asmap) const;
225
226 std::vector<uint8_t> GetGroup(const std::vector<bool> &asmap) const;
227 std::vector<uint8_t> GetAddrBytes() const;
228 int GetReachabilityFrom(const CNetAddr *paddrPartner = nullptr) const;
229
230 explicit CNetAddr(const struct in6_addr &pipv6Addr,
231 const uint32_t scope = 0);
232 bool GetIn6Addr(struct in6_addr *pipv6Addr) const;
233
234 friend bool operator==(const CNetAddr &a, const CNetAddr &b);
235 friend bool operator!=(const CNetAddr &a, const CNetAddr &b) {
236 return !(a == b);
237 }
238 friend bool operator<(const CNetAddr &a, const CNetAddr &b);
239
244 bool IsRelayable() const { return IsIPv4() || IsIPv6() || IsTor(); }
245
246 enum class Encoding {
247 V1,
249 V2,
250 };
251 struct SerParams {
253 };
254 static constexpr SerParams V1{Encoding::V1};
255 static constexpr SerParams V2{Encoding::V2};
256
260 template <typename Stream> void Serialize(Stream &s) const {
261 if (s.GetParams().enc == Encoding::V2) {
263 } else {
265 }
266 }
267
271 template <typename Stream> void Unserialize(Stream &s) {
272 if (s.GetParams().enc == Encoding::V2) {
274 } else {
276 }
277 }
278
279 friend class CSubNet;
280
281private:
290 bool SetTor(const std::string &addr);
291
299 bool SetI2P(const std::string &addr);
300
304 enum BIP155Network : uint8_t {
305 IPV4 = 1,
306 IPV6 = 2,
307 TORV2 = 3,
308 TORV3 = 4,
309 I2P = 5,
310 CJDNS = 6,
311 };
312
316 static constexpr size_t V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE;
317
323 static constexpr size_t MAX_ADDRV2_SIZE = 512;
324
331
342 bool SetNetFromBIP155Network(uint8_t possible_bip155_net,
343 size_t address_size);
344
348 void SerializeV1Array(uint8_t (&arr)[V1_SERIALIZATION_SIZE]) const {
349 size_t prefix_size;
350
351 switch (m_net) {
352 case NET_IPV6:
353 assert(m_addr.size() == sizeof(arr));
354 memcpy(arr, m_addr.data(), m_addr.size());
355 return;
356 case NET_IPV4:
357 prefix_size = sizeof(IPV4_IN_IPV6_PREFIX);
358 assert(prefix_size + m_addr.size() == sizeof(arr));
359 memcpy(arr, IPV4_IN_IPV6_PREFIX.data(), prefix_size);
360 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
361 return;
362 case NET_ONION:
363 if (m_addr.size() == ADDR_TORV3_SIZE) {
364 break;
365 }
366 prefix_size = sizeof(TORV2_IN_IPV6_PREFIX);
367 assert(prefix_size + m_addr.size() == sizeof(arr));
368 memcpy(arr, TORV2_IN_IPV6_PREFIX.data(), prefix_size);
369 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
370 return;
371 case NET_INTERNAL:
372 prefix_size = sizeof(INTERNAL_IN_IPV6_PREFIX);
373 assert(prefix_size + m_addr.size() == sizeof(arr));
374 memcpy(arr, INTERNAL_IN_IPV6_PREFIX.data(), prefix_size);
375 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
376 return;
377 case NET_I2P:
378 break;
379 case NET_CJDNS:
380 break;
381 case NET_UNROUTABLE:
382 case NET_MAX:
383 assert(false);
384 } // no default case, so the compiler can warn about missing cases
385
386 // Serialize TORv3, I2P and CJDNS as all-zeros.
387 memset(arr, 0x0, V1_SERIALIZATION_SIZE);
388 }
389
393 template <typename Stream> void SerializeV1Stream(Stream &s) const {
394 uint8_t serialized[V1_SERIALIZATION_SIZE];
395
396 SerializeV1Array(serialized);
397
398 s << serialized;
399 }
400
404 template <typename Stream> void SerializeV2Stream(Stream &s) const {
405 if (IsInternal()) {
406 // Serialize NET_INTERNAL as embedded in IPv6. We need to
407 // serialize such addresses from addrman.
408 s << static_cast<uint8_t>(BIP155Network::IPV6);
411 return;
412 }
413
414 s << static_cast<uint8_t>(GetBIP155Network());
415 s << m_addr;
416 }
417
422 // Use SetLegacyIPv6() so that m_net is set correctly. For example
423 // ::FFFF:0102:0304 should be set as m_net=NET_IPV4 (1.2.3.4).
424 SetLegacyIPv6(arr);
425 }
426
430 template <typename Stream> void UnserializeV1Stream(Stream &s) {
431 uint8_t serialized[V1_SERIALIZATION_SIZE];
432
433 s >> serialized;
434
435 UnserializeV1Array(serialized);
436 }
437
441 template <typename Stream> void UnserializeV2Stream(Stream &s) {
442 uint8_t bip155_net;
443 s >> bip155_net;
444
445 size_t address_size;
446 s >> COMPACTSIZE(address_size);
447
448 if (address_size > MAX_ADDRV2_SIZE) {
449 throw std::ios_base::failure(strprintf(
450 "Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
451 }
452
453 m_scope_id = 0;
454
455 if (SetNetFromBIP155Network(bip155_net, address_size)) {
456 m_addr.resize(address_size);
457 s >> Span{m_addr};
458
459 if (m_net != NET_IPV6) {
460 return;
461 }
462
463 // Do some special checks on IPv6 addresses.
464
465 // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
466 // gossiped but could be coming from addrman, when unserializing
467 // from disk.
470 memmove(m_addr.data(),
474 return;
475 }
476
479 return;
480 }
481
482 // IPv4 and TORv2 are not supposed to be embedded in IPv6 (like in
483 // V1 encoding). Unserialize as !IsValid(), thus ignoring them.
484 } else {
485 // If we receive an unknown BIP155 network id (from the future?)
486 // then ignore the address - unserialize as !IsValid().
487 s.ignore(address_size);
488 }
489
490 // Mimic a default-constructed CNetAddr object which is !IsValid() and
491 // thus will not be gossiped, but continue reading next addresses from
492 // the stream.
493 m_net = NET_IPV6;
495 }
496};
497
498class CSubNet {
499protected:
503 uint8_t netmask[16];
505 bool valid;
506
507 bool SanityCheck() const;
508
509public:
513 CSubNet();
514
522 CSubNet(const CNetAddr &addr, uint8_t mask);
523
532 CSubNet(const CNetAddr &addr, const CNetAddr &mask);
533
539 explicit CSubNet(const CNetAddr &addr);
540
541 bool Match(const CNetAddr &addr) const;
542
543 std::string ToString() const;
544 bool IsValid() const;
545
546 friend bool operator==(const CSubNet &a, const CSubNet &b);
547 friend bool operator!=(const CSubNet &a, const CSubNet &b) {
548 return !(a == b);
549 }
550 friend bool operator<(const CSubNet &a, const CSubNet &b);
551
553 READWRITE(obj.network);
554 if (obj.network.IsIPv4()) {
555 // Before D9176, CSubNet used the last 4 bytes of netmask to store
556 // the relevant bytes for an IPv4 mask. For compatiblity reasons,
557 // keep doing so in serialized form.
558 uint8_t dummy[12] = {0};
559 auto netmask_span = Span{obj.netmask};
560 READWRITE(dummy);
561 READWRITE(netmask_span.first(4));
562 } else {
563 READWRITE(obj.netmask);
564 }
565 READWRITE(obj.valid);
566 // Mark invalid if the result doesn't pass sanity checking.
567 SER_READ(obj, if (obj.valid) obj.valid = obj.SanityCheck());
568 }
569};
570
572class CService : public CNetAddr {
573protected:
574 // host order
575 uint16_t port;
576
577public:
578 CService();
579 CService(const CNetAddr &ip, uint16_t port);
580 CService(const struct in_addr &ipv4Addr, uint16_t port);
581 explicit CService(const struct sockaddr_in &addr);
582 uint16_t GetPort() const;
583 bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const;
584 bool SetSockAddr(const struct sockaddr *paddr);
585 friend bool operator==(const CService &a, const CService &b);
586 friend bool operator!=(const CService &a, const CService &b) {
587 return !(a == b);
588 }
589 friend bool operator<(const CService &a, const CService &b);
590 std::vector<uint8_t> GetKey() const;
591 std::string ToStringAddrPort() const;
592
593 CService(const struct in6_addr &ipv6Addr, uint16_t port);
594 explicit CService(const struct sockaddr_in6 &addr);
595
597 READWRITE(AsBase<CNetAddr>(obj),
598 Using<BigEndianFormatter<2>>(obj.port));
599 }
600
601 friend class CServiceHash;
602};
603
605public:
607 : m_salt_k0{FastRandomContext().rand64()},
608 m_salt_k1{FastRandomContext().rand64()} {}
609
610 CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
611 : m_salt_k0{salt_k0}, m_salt_k1{salt_k1} {}
612
613 size_t operator()(const CService &a) const noexcept {
615 hasher.Write(a.m_net);
616 hasher.Write(a.port);
617 hasher.Write(a.m_addr);
618 return static_cast<size_t>(hasher.Finalize());
619 }
620
621private:
622 const uint64_t m_salt_k0;
623 const uint64_t m_salt_k1;
624};
625
626#endif // BITCOIN_NETADDRESS_H
Network address.
Definition: netaddress.h:114
Network GetNetClass() const
Definition: netaddress.cpp:737
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition: netaddress.h:348
bool IsRelayable() const
Whether this address should be relayed to other peers even if we can't reach it ourselves.
Definition: netaddress.h:244
std::string ToStringAddr() const
Definition: netaddress.cpp:623
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
Definition: netaddress.h:404
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
Definition: netaddress.h:120
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:705
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:686
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition: netaddress.cpp:714
Network m_net
Network to which this address belongs.
Definition: netaddress.h:125
bool IsRFC5737() const
Definition: netaddress.cpp:363
void SetLegacyIPv6(Span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Definition: netaddress.cpp:153
static constexpr SerParams V1
Definition: netaddress.h:254
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:421
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:668
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:719
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:393
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
Definition: netaddress.h:131
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:260
bool IsLocal() const
Definition: netaddress.cpp:448
void Unserialize(Stream &s)
Unserialize from a stream.
Definition: netaddress.h:271
@ V2
BIP155 encoding.
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition: netaddress.h:316
static constexpr SerParams V2
Definition: netaddress.h:255
bool IsIPv6() const
Definition: netaddress.cpp:341
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition: netaddress.h:430
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:799
std::vector< uint8_t > GetAddrBytes() const
Definition: netaddress.cpp:854
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:235
uint32_t GetMappedAS(const std::vector< bool > &asmap) const
Definition: netaddress.cpp:755
int GetReachabilityFrom(const CNetAddr *paddrPartner=nullptr) const
Calculates a metric for how reachable (*this) is from a given partner.
Definition: netaddress.cpp:878
static constexpr size_t MAX_ADDRV2_SIZE
Maximum size of an address as defined in BIP155 (in bytes).
Definition: netaddress.h:323
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:441
bool IsRFC4380() const
Definition: netaddress.cpp:386
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:672
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:304
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:613
const uint64_t m_salt_k0
Definition: netaddress.h:622
CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
Definition: netaddress.h:610
const uint64_t m_salt_k1
Definition: netaddress.h:623
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:572
SERIALIZE_METHODS(CService, obj)
Definition: netaddress.h:596
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:586
uint16_t GetPort() const
bool SetSockAddr(const struct sockaddr *paddr)
Definition: netaddress.cpp:986
friend bool operator==(const CService &a, const CService &b)
uint16_t port
Definition: netaddress.h:575
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
std::string ToStringAddrPort() const
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:547
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:505
CNetAddr network
Network (base) address.
Definition: netaddress.h:501
bool SanityCheck() const
friend bool operator==(const CSubNet &a, const CSubNet &b)
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:503
std::string ToString() const
SERIALIZE_METHODS(CSubNet, obj)
Definition: netaddress.h:552
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:398
value_type * data()
Definition: prevector.h:611
void resize(size_type new_size)
Definition: prevector.h:428
void assign(size_type n, const T &val)
Definition: prevector.h:330
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
Definition: netaddress.h:103
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
Definition: netaddress.h:97
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
Definition: netaddress.h:100
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
Definition: netaddress.h:106
static constexpr size_t ADDR_TORV2_SIZE
Size of TORv2 address (in bytes).
Definition: netaddress.h:93
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:82
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
Definition: netaddress.h:87
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:74
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:109
Network
A network type.
Definition: netaddress.h:37
@ NET_I2P
I2P.
Definition: netaddress.h:52
@ NET_CJDNS
CJDNS.
Definition: netaddress.h:55
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:62
@ NET_ONION
TOR (v2 or v3)
Definition: netaddress.h:49
@ NET_IPV6
IPv6.
Definition: netaddress.h:46
@ NET_IPV4
IPv4.
Definition: netaddress.h:43
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:40
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:59
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:67
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
Definition: netaddress.h:90
@ IPV6
Definition: netbase.cpp:294
const char * name
Definition: rest.cpp:46
#define SER_READ(obj, code)
Definition: serialize.h:177
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class.
Definition: serialize.h:630
#define COMPACTSIZE(obj)
Definition: serialize.h:636
#define READWRITE(...)
Definition: serialize.h:176
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
const Encoding enc
Definition: netaddress.h:252
Serialization wrapper class for custom integers and enums.
Definition: serialize.h:662
#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())