 |
Bitcoin Core
23.99.0
P2P Digital Currency
|
Go to the documentation of this file.
5 #ifndef BITCOIN_NETADDRESS_H
6 #define BITCOIN_NETADDRESS_H
8 #if defined(HAVE_CONFIG_H)
74 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF};
81 0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43};
89 0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24
139 explicit CNetAddr(
const struct in_addr& ipv4Addr);
196 bool GetInAddr(
struct in_addr* pipv4Addr)
const;
207 explicit CNetAddr(
const struct in6_addr& pipv6Addr,
const uint32_t scope = 0);
208 bool GetIn6Addr(
struct in6_addr* pipv6Addr)
const;
225 template <
typename Stream>
238 template <
typename Stream>
258 bool SetTor(
const std::string& addr);
267 bool SetI2P(
const std::string& addr);
349 template <
typename Stream>
362 template <
typename Stream>
397 template <
typename Stream>
410 template <
typename Stream>
457 s.ignore(address_size);
528 CService(
const struct in_addr& ipv4Addr, uint16_t
port);
529 explicit CService(
const struct sockaddr_in& addr);
531 bool GetSockAddr(
struct sockaddr* paddr, socklen_t* addrlen)
const;
536 std::vector<unsigned char>
GetKey()
const;
541 CService(
const struct in6_addr& ipv6Addr, uint16_t
port);
542 explicit CService(
const struct sockaddr_in6& addr);
568 hasher.
Write(a.m_net);
569 hasher.
Write(a.port);
570 hasher.
Write(a.m_addr.data(), a.m_addr.size());
571 return static_cast<size_t>(hasher.
Finalize());
579 #endif // BITCOIN_NETADDRESS_H
static constexpr int ADDRV2_FORMAT
A flag that is ORed into the protocol version to designate that addresses should be serialized in (un...
A combination of a network address (CNetAddr) and a (TCP) port.
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
friend bool operator!=(const CService &a, const CService &b)
static constexpr uint16_t I2P_SAM31_PORT
SAM 3.1 and earlier do not support specifying ports and force the port to 0.
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
bool SetI2P(const std::string &addr)
Parse an I2P address and set this object to it.
bool SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size)
Set m_net from the provided BIP155 network id and size after validation.
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
std::vector< unsigned char > GetAddrBytes() const
void SetLegacyIPv6(Span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Network GetNetClass() const
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
static const std::array< uint8_t, 6 > TORV2_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded TORv2 address.
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Try to get our IPv6 (or CJDNS) address.
int GetReachabilityFrom(const CNetAddr *paddrPartner=nullptr) const
Calculates a metric for how reachable (*this) is from a given partner.
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
bool HasPrefix(const T1 &obj, const std::array< uint8_t, PREFIX_LEN > &prefix)
Check whether a container begins with the given prefix.
std::string ToString() const
void UnserializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE])
Unserialize from a pre-ADDRv2/BIP155 format from an array.
bool SetTor(const std::string &addr)
Parse a Tor address and set this object to it.
bool valid
Is this value valid? (only used to signal parse errors)
friend bool operator!=(const CSubNet &a, const CSubNet &b)
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
#define READWRITEAS(type, obj)
bool IsRelayable() const
Whether this address should be relayed to other peers even if we can't reach it ourselves.
std::string ToStringIPPort() const
static constexpr size_t MAX_ADDRV2_SIZE
Maximum size of an address as defined in BIP155 (in bytes).
bool Match(const CNetAddr &addr) const
bool GetInAddr(struct in_addr *pipv4Addr) const
Try to get our IPv4 address.
BIP155Network GetBIP155Network() const
Get the BIP155 network id of this address.
std::string ToStringIP() const
void Unserialize(Stream &s)
Unserialize from a stream.
A Span is an object that can refer to a contiguous sequence of objects.
CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
bool IsI2P() const
Check whether this object represents an I2P address.
enum Network GetNetwork() const
std::string ToString() const
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
CNetAddr network
Network (base) address.
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
static CService ip(uint32_t i)
bool SetSockAddr(const struct sockaddr *paddr)
uint64_t Finalize() const
Compute the 64-bit SipHash-2-4 of the data written so far.
void UnserializeV2Stream(Stream &s)
Unserialize from a ADDRv2 / BIP155 format.
void SerializeV1Stream(Stream &s) const
Serialize in pre-ADDRv2/BIP155 format to a stream.
SERIALIZE_METHODS(CService, obj)
std::string ToStringPort() const
static const std::array< uint8_t, 6 > INTERNAL_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded "internal" address.
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
friend bool operator<(const CSubNet &a, const CSubNet &b)
bool IsCJDNS() const
Check whether this object represents a CJDNS address.
friend bool operator!=(const CNetAddr &a, const CNetAddr &b)
friend bool operator==(const CNetAddr &a, const CNetAddr &b)
static const std::array< uint8_t, 12 > IPV4_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded IPv4 address.
BIP155Network
BIP155 network ids recognized by this software.
void resize(size_type new_size)
uint8_t netmask[16]
Netmask, in network byte order.
friend bool operator==(const CService &a, const CService &b)
void assign(size_type n, const T &val)
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
friend bool operator==(const CSubNet &a, const CSubNet &b)
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
std::string ToString() const
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
@ NET_ONION
TOR (v2 or v3)
bool IsTor() const
Check whether this object represents a TOR address.
size_t operator()(const CService &a) const noexcept
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
bool SetInternal(const std::string &name)
Create an "internal" address that represents a name or FQDN.
Network m_net
Network to which this address belongs.
CNetAddr()
Construct an unspecified IPv6 network address (::/128).
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class.
CSubNet()
Construct an invalid subnet (empty, Match() always returns false).
void Serialize(Stream &s) const
Serialize to a stream.
void SetIP(const CNetAddr &ip)
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...
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 ...
std::vector< unsigned char > GetKey() const
friend bool operator<(const CService &a, const CService &b)