mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-28 18:01:27 +02:00
refactor: add IsAddrCompatible() to CNode
This commit is contained in:
parent
d9a4738c9d
commit
83f8821a6f
17
src/net.h
17
src/net.h
@ -1176,18 +1176,23 @@ public:
|
|||||||
m_addr_known->insert(_addr.GetKey());
|
m_addr_known->insert(_addr.GetKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the peer supports the address. For example, a peer that does not
|
||||||
|
* implement BIP155 cannot receive Tor v3 addresses because it requires
|
||||||
|
* ADDRv2 (BIP155) encoding.
|
||||||
|
*/
|
||||||
|
bool IsAddrCompatible(const CAddress& addr) const
|
||||||
|
{
|
||||||
|
return m_wants_addrv2 || addr.IsAddrV1Compatible();
|
||||||
|
}
|
||||||
|
|
||||||
void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
|
void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
|
||||||
{
|
{
|
||||||
// Whether the peer supports the address in `_addr`. For example,
|
|
||||||
// nodes that do not implement BIP155 cannot receive Tor v3 addresses
|
|
||||||
// because they require ADDRv2 (BIP155) encoding.
|
|
||||||
const bool addr_format_supported = m_wants_addrv2 || _addr.IsAddrV1Compatible();
|
|
||||||
|
|
||||||
// Known checking here is only to save space from duplicates.
|
// Known checking here is only to save space from duplicates.
|
||||||
// SendMessages will filter it again for knowns that were added
|
// SendMessages will filter it again for knowns that were added
|
||||||
// after addresses were pushed.
|
// after addresses were pushed.
|
||||||
assert(m_addr_known);
|
assert(m_addr_known);
|
||||||
if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey()) && addr_format_supported) {
|
if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey()) && IsAddrCompatible(_addr)) {
|
||||||
if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
|
if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
|
||||||
vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr;
|
vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user