Bitcoin Core  25.99.0
P2P Digital Currency
Public Member Functions | Public Attributes | Static Private Attributes | Friends | List of all members
CAddress Class Reference

A CService with information about it as peer. More...

#include <protocol.h>

Inheritance diagram for CAddress:
[legend]
Collaboration diagram for CAddress:
[legend]

Public Member Functions

 CAddress ()
 
 CAddress (CService ipIn, ServiceFlags nServicesIn)
 
 CAddress (CService ipIn, ServiceFlags nServicesIn, NodeSeconds time)
 
 SERIALIZE_METHODS (CAddress, obj)
 
- Public Member Functions inherited from CService
 CService ()
 
 CService (const CNetAddr &ip, uint16_t port)
 
 CService (const struct in_addr &ipv4Addr, uint16_t port)
 
 CService (const struct sockaddr_in &addr)
 
uint16_t GetPort () const
 
bool GetSockAddr (struct sockaddr *paddr, socklen_t *addrlen) const
 Obtain the IPv4/6 socket address this represents. More...
 
bool SetSockAddr (const struct sockaddr *paddr)
 
std::vector< unsigned char > GetKey () const
 
std::string ToStringAddrPort () const
 
 CService (const struct in6_addr &ipv6Addr, uint16_t port)
 
 CService (const struct sockaddr_in6 &addr)
 
 SERIALIZE_METHODS (CService, obj)
 
- Public Member Functions inherited from CNetAddr
 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 ToStringAddr () 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...
 
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...
 

Public Attributes

NodeSeconds nTime {TIME_INIT}
 Always included in serialization. The behavior is unspecified if the value is not representable as uint32_t. More...
 
ServiceFlags nServices {NODE_NONE}
 Serialized as uint64_t in V1, and as CompactSize in V2. More...
 

Static Private Attributes

static constexpr std::chrono::seconds TIME_INIT {100000000}
 
static constexpr uint32_t DISK_VERSION_INIT {220000}
 Historically, CAddress disk serialization stored the CLIENT_VERSION, optionally OR'ed with the ADDRV2_FORMAT flag to indicate V2 serialization. More...
 
static constexpr uint32_t DISK_VERSION_IGNORE_MASK {0b00000000'00000111'11111111'11111111}
 
static constexpr uint32_t DISK_VERSION_ADDRV2 {1 << 29}
 The version number written in disk serialized addresses to indicate V2 serializations. More...
 

Friends

bool operator== (const CAddress &a, const CAddress &b)
 

Additional Inherited Members

- Protected Attributes inherited from CService
uint16_t port
 
- Protected Attributes inherited from CNetAddr
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...
 

Detailed Description

A CService with information about it as peer.

Definition at line 359 of file protocol.h.

Constructor & Destructor Documentation

◆ CAddress() [1/3]

CAddress::CAddress ( )
inline

Definition at line 389 of file protocol.h.

◆ CAddress() [2/3]

CAddress::CAddress ( CService  ipIn,
ServiceFlags  nServicesIn 
)
inline

Definition at line 390 of file protocol.h.

◆ CAddress() [3/3]

CAddress::CAddress ( CService  ipIn,
ServiceFlags  nServicesIn,
NodeSeconds  time 
)
inline

Definition at line 391 of file protocol.h.

Member Function Documentation

◆ SERIALIZE_METHODS()

CAddress::SERIALIZE_METHODS ( CAddress  ,
obj   
)
inline

Definition at line 393 of file protocol.h.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator==

bool operator== ( const CAddress a,
const CAddress b 
)
friend

Definition at line 444 of file protocol.h.

Member Data Documentation

◆ DISK_VERSION_ADDRV2

constexpr uint32_t CAddress::DISK_VERSION_ADDRV2 {1 << 29}
staticconstexprprivate

The version number written in disk serialized addresses to indicate V2 serializations.

It must be exactly 1<<29, as that is the value that historical versions used for this (they used their internal ADDRV2_FORMAT flag here).

Definition at line 384 of file protocol.h.

◆ DISK_VERSION_IGNORE_MASK

constexpr uint32_t CAddress::DISK_VERSION_IGNORE_MASK {0b00000000'00000111'11111111'11111111}
staticconstexprprivate

Definition at line 380 of file protocol.h.

◆ DISK_VERSION_INIT

constexpr uint32_t CAddress::DISK_VERSION_INIT {220000}
staticconstexprprivate

Historically, CAddress disk serialization stored the CLIENT_VERSION, optionally OR'ed with the ADDRV2_FORMAT flag to indicate V2 serialization.

The first field has since been disentangled from client versioning, and now instead:

  • The low bits (masked by DISK_VERSION_IGNORE_MASK) store the fixed value DISK_VERSION_INIT, (in case any code exists that treats it as a client version) but are ignored on deserialization.
  • The high bits (masked by ~DISK_VERSION_IGNORE_MASK) store actual serialization information. Only 0 or DISK_VERSION_ADDRV2 (equal to the historical ADDRV2_FORMAT) are valid now, and any other value triggers a deserialization failure. Other values can be added later if needed.

For disk deserialization, ADDRV2_FORMAT in the stream version signals that ADDRV2 deserialization is permitted, but the actual format is determined by the high bits in the stored version field. For network serialization, the stream version having ADDRV2_FORMAT or not determines the actual format used (as it has no embedded version number).

Definition at line 379 of file protocol.h.

◆ nServices

ServiceFlags CAddress::nServices {NODE_NONE}

Serialized as uint64_t in V1, and as CompactSize in V2.

Definition at line 442 of file protocol.h.

◆ nTime

NodeSeconds CAddress::nTime {TIME_INIT}

Always included in serialization. The behavior is unspecified if the value is not representable as uint32_t.

Definition at line 440 of file protocol.h.

◆ TIME_INIT

constexpr std::chrono::seconds CAddress::TIME_INIT {100000000}
staticconstexprprivate

Definition at line 361 of file protocol.h.


The documentation for this class was generated from the following file: