Skip to content

Commit 83f8821

Browse files
committed
refactor: add IsAddrCompatible() to CNode
1 parent d9a4738 commit 83f8821

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/net.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,18 +1176,23 @@ class CNode
11761176
m_addr_known->insert(_addr.GetKey());
11771177
}
11781178

1179-
void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
1179+
/**
1180+
* Whether the peer supports the address. For example, a peer that does not
1181+
* implement BIP155 cannot receive Tor v3 addresses because it requires
1182+
* ADDRv2 (BIP155) encoding.
1183+
*/
1184+
bool IsAddrCompatible(const CAddress& addr) const
11801185
{
1181-
// Whether the peer supports the address in `_addr`. For example,
1182-
// nodes that do not implement BIP155 cannot receive Tor v3 addresses
1183-
// because they require ADDRv2 (BIP155) encoding.
1184-
const bool addr_format_supported = m_wants_addrv2 || _addr.IsAddrV1Compatible();
1186+
return m_wants_addrv2 || addr.IsAddrV1Compatible();
1187+
}
11851188

1189+
void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
1190+
{
11861191
// Known checking here is only to save space from duplicates.
11871192
// SendMessages will filter it again for knowns that were added
11881193
// after addresses were pushed.
11891194
assert(m_addr_known);
1190-
if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey()) && addr_format_supported) {
1195+
if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey()) && IsAddrCompatible(_addr)) {
11911196
if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
11921197
vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr;
11931198
} else {

0 commit comments

Comments
 (0)