![]() |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Network address. More...
#include <netaddress.h>
Public Member Functions | |
CNetAddr () | |
Construct an unspecified IPv6 network address (::/128). More... | |
CNetAddr (const struct in_addr &ipv4Addr) | |
void | SetIP (const CNetAddr &ip) |
void | SetLegacyIPv6 (Span< const uint8_t > ipv6) |
Set from a legacy IPv6 address. More... | |
bool | SetInternal (const std::string &name) |
Create an "internal" address that represents a name or FQDN. More... | |
bool | SetSpecial (const std::string &addr) |
Parse a Tor or I2P address and set this object to it. More... | |
bool | IsBindAny () const |
bool | IsIPv4 () const |
bool | IsIPv6 () const |
bool | IsRFC1918 () const |
bool | IsRFC2544 () const |
bool | IsRFC6598 () const |
bool | IsRFC5737 () const |
bool | IsRFC3849 () const |
bool | IsRFC3927 () const |
bool | IsRFC3964 () const |
bool | IsRFC4193 () const |
bool | IsRFC4380 () const |
bool | IsRFC4843 () const |
bool | IsRFC7343 () const |
bool | IsRFC4862 () const |
bool | IsRFC6052 () const |
bool | IsRFC6145 () const |
bool | IsHeNet () const |
bool | IsTor () const |
Check whether this object represents a TOR address. More... | |
bool | IsI2P () const |
Check whether this object represents an I2P address. More... | |
bool | IsCJDNS () const |
Check whether this object represents a CJDNS address. More... | |
bool | IsLocal () const |
bool | IsRoutable () const |
bool | IsInternal () const |
bool | IsValid () const |
bool | IsAddrV1Compatible () const |
Check if the current object can be serialized in pre-ADDRv2/BIP155 format. More... | |
enum Network | GetNetwork () const |
std::string | ToString () const |
std::string | ToStringIP () const |
uint64_t | GetHash () const |
bool | GetInAddr (struct in_addr *pipv4Addr) const |
Try to get our IPv4 address. More... | |
Network | GetNetClass () const |
uint32_t | GetLinkedIPv4 () const |
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv4 address as a uint32. More... | |
bool | HasLinkedIPv4 () const |
Whether this address has a linked IPv4 address (see GetLinkedIPv4()). More... | |
uint32_t | GetMappedAS (const std::vector< bool > &asmap) const |
std::vector< unsigned char > | GetGroup (const std::vector< bool > &asmap) const |
Get the canonical identifier of our network group. More... | |
std::vector< unsigned char > | GetAddrBytes () const |
int | GetReachabilityFrom (const CNetAddr *paddrPartner=nullptr) const |
Calculates a metric for how reachable (*this) is from a given partner. More... | |
CNetAddr (const struct in6_addr &pipv6Addr, const uint32_t scope=0) | |
bool | GetIn6Addr (struct in6_addr *pipv6Addr) const |
Try to get our IPv6 (or CJDNS) address. More... | |
bool | IsRelayable () const |
Whether this address should be relayed to other peers even if we can't reach it ourselves. More... | |
template<typename Stream > | |
void | Serialize (Stream &s) const |
Serialize to a stream. More... | |
template<typename Stream > | |
void | Unserialize (Stream &s) |
Unserialize from a stream. More... | |
Protected Attributes | |
prevector< ADDR_IPV6_SIZE, uint8_t > | m_addr {ADDR_IPV6_SIZE, 0x0} |
Raw representation of the network address. More... | |
Network | m_net {NET_IPV6} |
Network to which this address belongs. More... | |
uint32_t | m_scope_id {0} |
Scope id if scoped/link-local IPV6 address. More... | |
Private Types | |
enum | BIP155Network : uint8_t { IPV4 = 1, IPV6 = 2, TORV2 = 3, TORV3 = 4, I2P = 5, CJDNS = 6 } |
BIP155 network ids recognized by this software. More... | |
Private Member Functions | |
bool | SetTor (const std::string &addr) |
Parse a Tor address and set this object to it. More... | |
bool | SetI2P (const std::string &addr) |
Parse an I2P address and set this object to it. More... | |
BIP155Network | GetBIP155Network () const |
Get the BIP155 network id of this address. More... | |
bool | SetNetFromBIP155Network (uint8_t possible_bip155_net, size_t address_size) |
Set m_net from the provided BIP155 network id and size after validation. More... | |
void | SerializeV1Array (uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const |
Serialize in pre-ADDRv2/BIP155 format to an array. More... | |
template<typename Stream > | |
void | SerializeV1Stream (Stream &s) const |
Serialize in pre-ADDRv2/BIP155 format to a stream. More... | |
template<typename Stream > | |
void | SerializeV2Stream (Stream &s) const |
Serialize as ADDRv2 / BIP155. More... | |
void | UnserializeV1Array (uint8_t(&arr)[V1_SERIALIZATION_SIZE]) |
Unserialize from a pre-ADDRv2/BIP155 format from an array. More... | |
template<typename Stream > | |
void | UnserializeV1Stream (Stream &s) |
Unserialize from a pre-ADDRv2/BIP155 format from a stream. More... | |
template<typename Stream > | |
void | UnserializeV2Stream (Stream &s) |
Unserialize from a ADDRv2 / BIP155 format. More... | |
Static Private Attributes | |
static constexpr size_t | V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE |
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes). More... | |
static constexpr size_t | MAX_ADDRV2_SIZE = 512 |
Maximum size of an address as defined in BIP155 (in bytes). More... | |
Friends | |
class | CSubNet |
bool | operator== (const CNetAddr &a, const CNetAddr &b) |
bool | operator!= (const CNetAddr &a, const CNetAddr &b) |
bool | operator< (const CNetAddr &a, const CNetAddr &b) |
Network address.
Definition at line 118 of file netaddress.h.
|
private |
BIP155 network ids recognized by this software.
Enumerator | |
---|---|
IPV4 | |
IPV6 | |
TORV2 | |
TORV3 | |
I2P | |
CJDNS |
Definition at line 280 of file netaddress.h.
CNetAddr::CNetAddr | ( | ) |
Construct an unspecified IPv6 network address (::/128).
Definition at line 105 of file netaddress.cpp.
|
explicit |
|
explicit |
std::vector< unsigned char > CNetAddr::GetAddrBytes | ( | ) | const |
Definition at line 826 of file netaddress.cpp.
|
private |
Get the BIP155 network id of this address.
Must not be called for IsInternal() objects.
Definition at line 27 of file netaddress.cpp.
std::vector< unsigned char > CNetAddr::GetGroup | ( | const std::vector< bool > & | asmap | ) | const |
Get the canonical identifier of our network group.
The groups are assigned in a way where it should be costly for an attacker to obtain addresses with many different group identifiers, even if it is cheap to obtain addresses with the same identifier.
Definition at line 766 of file netaddress.cpp.
uint64_t CNetAddr::GetHash | ( | ) | const |
Definition at line 836 of file netaddress.cpp.
bool CNetAddr::GetIn6Addr | ( | struct in6_addr * | pipv6Addr | ) | const |
Try to get our IPv6 (or CJDNS) address.
[out] | pipv6Addr | The in6_addr struct to which to copy. |
Definition at line 675 of file netaddress.cpp.
bool CNetAddr::GetInAddr | ( | struct in_addr * | pipv4Addr | ) | const |
Try to get our IPv4 address.
[out] | pipv4Addr | The in_addr struct to which to copy. |
Definition at line 656 of file netaddress.cpp.
uint32_t CNetAddr::GetLinkedIPv4 | ( | ) | const |
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv4 address as a uint32.
Definition at line 690 of file netaddress.cpp.
uint32_t CNetAddr::GetMappedAS | ( | const std::vector< bool > & | asmap | ) | const |
Definition at line 725 of file netaddress.cpp.
Network CNetAddr::GetNetClass | ( | ) | const |
Definition at line 707 of file netaddress.cpp.
enum Network CNetAddr::GetNetwork | ( | ) | const |
Definition at line 524 of file netaddress.cpp.
int CNetAddr::GetReachabilityFrom | ( | const CNetAddr * | paddrPartner = nullptr | ) | const |
Calculates a metric for how reachable (*this) is from a given partner.
Definition at line 858 of file netaddress.cpp.
bool CNetAddr::HasLinkedIPv4 | ( | ) | const |
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition at line 685 of file netaddress.cpp.
bool CNetAddr::IsAddrV1Compatible | ( | ) | const |
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition at line 505 of file netaddress.cpp.
bool CNetAddr::IsBindAny | ( | ) | const |
Definition at line 310 of file netaddress.cpp.
bool CNetAddr::IsCJDNS | ( | ) | const |
Check whether this object represents a CJDNS address.
Definition at line 423 of file netaddress.cpp.
bool CNetAddr::IsHeNet | ( | ) | const |
Definition at line 404 of file netaddress.cpp.
bool CNetAddr::IsI2P | ( | ) | const |
Check whether this object represents an I2P address.
Definition at line 418 of file netaddress.cpp.
bool CNetAddr::IsInternal | ( | ) | const |
Definition at line 500 of file netaddress.cpp.
bool CNetAddr::IsIPv4 | ( | ) | const |
bool CNetAddr::IsIPv6 | ( | ) | const |
bool CNetAddr::IsLocal | ( | ) | const |
Definition at line 425 of file netaddress.cpp.
|
inline |
Whether this address should be relayed to other peers even if we can't reach it ourselves.
Definition at line 225 of file netaddress.h.
bool CNetAddr::IsRFC1918 | ( | ) | const |
Definition at line 322 of file netaddress.cpp.
bool CNetAddr::IsRFC2544 | ( | ) | const |
Definition at line 330 of file netaddress.cpp.
bool CNetAddr::IsRFC3849 | ( | ) | const |
Definition at line 352 of file netaddress.cpp.
bool CNetAddr::IsRFC3927 | ( | ) | const |
Definition at line 335 of file netaddress.cpp.
bool CNetAddr::IsRFC3964 | ( | ) | const |
Definition at line 357 of file netaddress.cpp.
bool CNetAddr::IsRFC4193 | ( | ) | const |
Definition at line 380 of file netaddress.cpp.
bool CNetAddr::IsRFC4380 | ( | ) | const |
Definition at line 369 of file netaddress.cpp.
bool CNetAddr::IsRFC4843 | ( | ) | const |
Definition at line 392 of file netaddress.cpp.
bool CNetAddr::IsRFC4862 | ( | ) | const |
Definition at line 374 of file netaddress.cpp.
bool CNetAddr::IsRFC5737 | ( | ) | const |
Definition at line 345 of file netaddress.cpp.
bool CNetAddr::IsRFC6052 | ( | ) | const |
Definition at line 362 of file netaddress.cpp.
bool CNetAddr::IsRFC6145 | ( | ) | const |
Definition at line 385 of file netaddress.cpp.
bool CNetAddr::IsRFC6598 | ( | ) | const |
Definition at line 340 of file netaddress.cpp.
bool CNetAddr::IsRFC7343 | ( | ) | const |
Definition at line 398 of file netaddress.cpp.
bool CNetAddr::IsRoutable | ( | ) | const |
Definition at line 490 of file netaddress.cpp.
bool CNetAddr::IsTor | ( | ) | const |
Check whether this object represents a TOR address.
Definition at line 413 of file netaddress.cpp.
bool CNetAddr::IsValid | ( | ) | const |
Definition at line 451 of file netaddress.cpp.
|
inline |
Serialize to a stream.
Definition at line 234 of file netaddress.h.
|
inlineprivate |
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition at line 320 of file netaddress.h.
|
inlineprivate |
Serialize in pre-ADDRv2/BIP155 format to a stream.
Definition at line 358 of file netaddress.h.
|
inlineprivate |
Serialize as ADDRv2 / BIP155.
Definition at line 371 of file netaddress.h.
|
private |
Parse an I2P address and set this object to it.
[in] | addr | Address to parse, must be a valid C string, for example ukeu3k5oycgaauneqgtnvselmt4yemvoilkln7jpvamvfx7dnkdq.b32.i2p. |
Definition at line 269 of file netaddress.cpp.
bool CNetAddr::SetInternal | ( | const std::string & | name | ) |
Create an "internal" address that represents a name or FQDN.
AddrMan uses these fake addresses to keep track of which DNS seeds were used.
Definition at line 173 of file netaddress.cpp.
void CNetAddr::SetIP | ( | const CNetAddr & | ip | ) |
Definition at line 107 of file netaddress.cpp.
void CNetAddr::SetLegacyIPv6 | ( | Span< const uint8_t > | ipv6 | ) |
Set from a legacy IPv6 address.
Legacy IPv6 address may be a normal IPv6 address, or another address (e.g. IPv4) disguised as IPv6. This encoding is used in the legacy addr
encoding.
Definition at line 138 of file netaddress.cpp.
|
private |
Set m_net
from the provided BIP155 network id and size after validation.
true | the network was recognized, is valid and m_net was set |
false | not recognised (from future?) and should be silently ignored |
std::ios_base::failure | if the network is one of the BIP155 founding networks (id 1..6) with wrong address size. |
Definition at line 49 of file netaddress.cpp.
bool CNetAddr::SetSpecial | ( | const std::string & | addr | ) |
Parse a Tor or I2P address and set this object to it.
[in] | addr | Address to parse, for example pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion or ukeu3k5oycgaauneqgtnvselmt4yemvoilkln7jpvamvfx7dnkdq.b32.i2p. |
Definition at line 212 of file netaddress.cpp.
|
private |
Parse a Tor address and set this object to it.
[in] | addr | Address to parse, must be a valid C string, for example pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion. |
Definition at line 229 of file netaddress.cpp.
std::string CNetAddr::ToString | ( | ) | const |
Definition at line 631 of file netaddress.cpp.
std::string CNetAddr::ToStringIP | ( | ) | const |
Definition at line 608 of file netaddress.cpp.
|
inline |
Unserialize from a stream.
Definition at line 247 of file netaddress.h.
|
inlineprivate |
Unserialize from a pre-ADDRv2/BIP155 format from an array.
This function is only called from UnserializeV1Stream() and is a wrapper for SetLegacyIPv6(); however, we keep it for symmetry with SerializeV1Array() to have pairs of ser/unser functions and to make clear that if one is altered, a corresponding reverse modification should be applied to the other.
Definition at line 395 of file netaddress.h.
|
inlineprivate |
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition at line 406 of file netaddress.h.
|
inlineprivate |
Unserialize from a ADDRv2 / BIP155 format.
Definition at line 419 of file netaddress.h.
|
friend |
Definition at line 256 of file netaddress.h.
Definition at line 219 of file netaddress.h.
Definition at line 641 of file netaddress.cpp.
Definition at line 636 of file netaddress.cpp.
|
protected |
Raw representation of the network address.
In network byte order (big endian) for IPv4 and IPv6.
Definition at line 125 of file netaddress.h.
Network to which this address belongs.
Definition at line 130 of file netaddress.h.
|
protected |
Scope id if scoped/link-local IPV6 address.
See https://tools.ietf.org/html/rfc4007
Definition at line 136 of file netaddress.h.
|
staticconstexprprivate |
Maximum size of an address as defined in BIP155 (in bytes).
This is only the size of the address, not the entire CNetAddr object when serialized.
Definition at line 299 of file netaddress.h.
|
staticconstexprprivate |
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition at line 292 of file netaddress.h.