Bitcoin ABC 0.32.6
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
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 ToString() const;
212 std::string ToStringIP() const;
213 bool GetInAddr(struct in_addr *pipv4Addr) const;
214 Network GetNetClass() const;
215
218 uint32_t GetLinkedIPv4() const;
220 bool HasLinkedIPv4() const;
221
222 // The AS on the BGP path to the node we use to diversify
223 // peers in AddrMan bucketing based on the AS infrastructure.
224 // The ip->AS mapping depends on how asmap is constructed.
225 uint32_t GetMappedAS(const std::vector<bool> &asmap) const;
226
227 std::vector<uint8_t> GetGroup(const std::vector<bool> &asmap) const;
228 std::vector<uint8_t> GetAddrBytes() const;
229 int GetReachabilityFrom(const CNetAddr *paddrPartner = nullptr) const;
230
231 explicit CNetAddr(const struct in6_addr &pipv6Addr,
232 const uint32_t scope = 0);
233 bool GetIn6Addr(struct in6_addr *pipv6Addr) const;
234
235 friend bool operator==(const CNetAddr &a, const CNetAddr &b);
236 friend bool operator!=(const CNetAddr &a, const CNetAddr &b) {
237 return !(a == b);
238 }
239 friend bool operator<(const CNetAddr &a, const CNetAddr &b);
240
245 bool IsRelayable() const { return IsIPv4() || IsIPv6() || IsTor(); }
246
247 enum class Encoding {
248 V1,
250 V2,
251 };
252 struct SerParams {
254 };
255 static constexpr SerParams V1{Encoding::V1};
256 static constexpr SerParams V2{Encoding::V2};
257
261 template <typename Stream> void Serialize(Stream &s) const {
262 if (s.GetParams().enc == Encoding::V2) {
264 } else {
266 }
267 }
268
272 template <typename Stream> void Unserialize(Stream &s) {
273 if (s.GetParams().enc == Encoding::V2) {
275 } else {
277 }
278 }
279
280 friend class CSubNet;
281
282private:
291 bool SetTor(const std::string &addr);
292
300 bool SetI2P(const std::string &addr);
301
305 enum BIP155Network : uint8_t {
306 IPV4 = 1,
307 IPV6 = 2,
308 TORV2 = 3,
309 TORV3 = 4,
310 I2P = 5,
311 CJDNS = 6,
312 };
313
317 static constexpr size_t V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE;
318
324 static constexpr size_t MAX_ADDRV2_SIZE = 512;
325
332
343 bool SetNetFromBIP155Network(uint8_t possible_bip155_net,
344 size_t address_size);
345
349 void SerializeV1Array(uint8_t (&arr)[V1_SERIALIZATION_SIZE]) const {
350 size_t prefix_size;
351
352 switch (m_net) {
353 case NET_IPV6:
354 assert(m_addr.size() == sizeof(arr));
355 memcpy(arr, m_addr.data(), m_addr.size());
356 return;
357 case NET_IPV4:
358 prefix_size = sizeof(IPV4_IN_IPV6_PREFIX);
359 assert(prefix_size + m_addr.size() == sizeof(arr));
360 memcpy(arr, IPV4_IN_IPV6_PREFIX.data(), prefix_size);
361 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
362 return;
363 case NET_ONION:
364 if (m_addr.size() == ADDR_TORV3_SIZE) {
365 break;
366 }
367 prefix_size = sizeof(TORV2_IN_IPV6_PREFIX);
368 assert(prefix_size + m_addr.size() == sizeof(arr));
369 memcpy(arr, TORV2_IN_IPV6_PREFIX.data(), prefix_size);
370 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
371 return;
372 case NET_INTERNAL:
373 prefix_size = sizeof(INTERNAL_IN_IPV6_PREFIX);
374 assert(prefix_size + m_addr.size() == sizeof(arr));
375 memcpy(arr, INTERNAL_IN_IPV6_PREFIX.data(), prefix_size);
376 memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
377 return;
378 case NET_I2P:
379 break;
380 case NET_CJDNS:
381 break;
382 case NET_UNROUTABLE:
383 case NET_MAX:
384 assert(false);
385 } // no default case, so the compiler can warn about missing cases
386
387 // Serialize TORv3, I2P and CJDNS as all-zeros.
388 memset(arr, 0x0, V1_SERIALIZATION_SIZE);
389 }
390
394 template <typename Stream> void SerializeV1Stream(Stream &s) const {
395 uint8_t serialized[V1_SERIALIZATION_SIZE];
396
397 SerializeV1Array(serialized);
398
399 s << serialized;
400 }
401
405 template <typename Stream> void SerializeV2Stream(Stream &s) const {
406 if (IsInternal()) {
407 // Serialize NET_INTERNAL as embedded in IPv6. We need to
408 // serialize such addresses from addrman.
409 s << static_cast<uint8_t>(BIP155Network::IPV6);
412 return;
413 }
414
415 s << static_cast<uint8_t>(GetBIP155Network());
416 s << m_addr;
417 }
418
423 // Use SetLegacyIPv6() so that m_net is set correctly. For example
424 // ::FFFF:0102:0304 should be set as m_net=NET_IPV4 (1.2.3.4).
425 SetLegacyIPv6(arr);
426 }
427
431 template <typename Stream> void UnserializeV1Stream(Stream &s) {
432 uint8_t serialized[V1_SERIALIZATION_SIZE];
433
434 s >> serialized;
435
436 UnserializeV1Array(serialized);
437 }
438
442 template <typename Stream> void UnserializeV2Stream(Stream &s) {
443 uint8_t bip155_net;
444 s >> bip155_net;
445
446 size_t address_size;
447 s >> COMPACTSIZE(address_size);
448
449 if (address_size > MAX_ADDRV2_SIZE) {
450 throw std::ios_base::failure(strprintf(
451 "Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
452 }
453
454 m_scope_id = 0;
455
456 if (SetNetFromBIP155Network(bip155_net, address_size)) {
457 m_addr.resize(address_size);
458 s >> Span{m_addr};
459
460 if (m_net != NET_IPV6) {
461 return;
462 }
463
464 // Do some special checks on IPv6 addresses.
465
466 // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
467 // gossiped but could be coming from addrman, when unserializing
468 // from disk.
471 memmove(m_addr.data(),
475 return;
476 }
477
480 return;
481 }
482
483 // IPv4 and TORv2 are not supposed to be embedded in IPv6 (like in
484 // V1 encoding). Unserialize as !IsValid(), thus ignoring them.
485 } else {
486 // If we receive an unknown BIP155 network id (from the future?)
487 // then ignore the address - unserialize as !IsValid().
488 s.ignore(address_size);
489 }
490
491 // Mimic a default-constructed CNetAddr object which is !IsValid() and
492 // thus will not be gossiped, but continue reading next addresses from
493 // the stream.
494 m_net = NET_IPV6;
496 }
497};
498
499class CSubNet {
500protected:
504 uint8_t netmask[16];
506 bool valid;
507
508 bool SanityCheck() const;
509
510public:
514 CSubNet();
515
523 CSubNet(const CNetAddr &addr, uint8_t mask);
524
533 CSubNet(const CNetAddr &addr, const CNetAddr &mask);
534
540 explicit CSubNet(const CNetAddr &addr);
541
542 bool Match(const CNetAddr &addr) const;
543
544 std::string ToString() const;
545 bool IsValid() const;
546
547 friend bool operator==(const CSubNet &a, const CSubNet &b);
548 friend bool operator!=(const CSubNet &a, const CSubNet &b) {
549 return !(a == b);
550 }
551 friend bool operator<(const CSubNet &a, const CSubNet &b);
552
554 READWRITE(obj.network);
555 if (obj.network.IsIPv4()) {
556 // Before D9176, CSubNet used the last 4 bytes of netmask to store
557 // the relevant bytes for an IPv4 mask. For compatiblity reasons,
558 // keep doing so in serialized form.
559 uint8_t dummy[12] = {0};
560 auto netmask_span = Span{obj.netmask};
561 READWRITE(dummy);
562 READWRITE(netmask_span.first(4));
563 } else {
564 READWRITE(obj.netmask);
565 }
566 READWRITE(obj.valid);
567 // Mark invalid if the result doesn't pass sanity checking.
568 SER_READ(obj, if (obj.valid) obj.valid = obj.SanityCheck());
569 }
570};
571
573class CService : public CNetAddr {
574protected:
575 // host order
576 uint16_t port;
577
578public:
579 CService();
580 CService(const CNetAddr &ip, uint16_t port);
581 CService(const struct in_addr &ipv4Addr, uint16_t port);
582 explicit CService(const struct sockaddr_in &addr);
583 uint16_t GetPort() const;
584 bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const;
585 bool SetSockAddr(const struct sockaddr *paddr);
586 friend bool operator==(const CService &a, const CService &b);
587 friend bool operator!=(const CService &a, const CService &b) {
588 return !(a == b);
589 }
590 friend bool operator<(const CService &a, const CService &b);
591 std::vector<uint8_t> GetKey() const;
592 std::string ToString() const;
593 std::string ToStringPort() const;
594 std::string ToStringIPPort() const;
595
596 CService(const struct in6_addr &ipv6Addr, uint16_t port);
597 explicit CService(const struct sockaddr_in6 &addr);
598
600 READWRITE(AsBase<CNetAddr>(obj),
601 Using<BigEndianFormatter<2>>(obj.port));
602 }
603
604 friend class CServiceHash;
605};
606
608public:
610 : m_salt_k0{FastRandomContext().rand64()},
611 m_salt_k1{FastRandomContext().rand64()} {}
612
613 CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
614 : m_salt_k0{salt_k0}, m_salt_k1{salt_k1} {}
615
616 size_t operator()(const CService &a) const noexcept {
618 hasher.Write(a.m_net);
619 hasher.Write(a.port);
620 hasher.Write(a.m_addr);
621 return static_cast<size_t>(hasher.Finalize());
622 }
623
624private:
625 const uint64_t m_salt_k0;
626 const uint64_t m_salt_k1;
627};
628
629#endif // BITCOIN_NETADDRESS_H
Network address.
Definition: netaddress.h:114
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:349
bool IsRelayable() const
Whether this address should be relayed to other peers even if we can't reach it ourselves.
Definition: netaddress.h:245
std::string ToStringIP() const
Definition: netaddress.cpp:623
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
Definition: netaddress.h:405
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: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: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:255
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:422
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:394
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:261
bool IsLocal() const
Definition: netaddress.cpp:448
void Unserialize(Stream &s)
Unserialize from a stream.
Definition: netaddress.h:272
@ V2
BIP155 encoding.
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition: netaddress.h:317
static constexpr SerParams V2
Definition: netaddress.h:256
bool IsIPv6() const
Definition: netaddress.cpp:341
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition: netaddress.h:431
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:236
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:324
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:442
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:305
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:616
const uint64_t m_salt_k0
Definition: netaddress.h:625
CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
Definition: netaddress.h:613
const uint64_t m_salt_k1
Definition: netaddress.h:626
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:573
SERIALIZE_METHODS(CService, obj)
Definition: netaddress.h:599
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:587
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:576
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:548
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:506
CNetAddr network
Network (base) address.
Definition: netaddress.h:502
bool SanityCheck() const
friend bool operator==(const CSubNet &a, const CSubNet &b)
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:504
std::string ToString() const
SERIALIZE_METHODS(CSubNet, obj)
Definition: netaddress.h:553
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:308
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:253
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())