Skip to content

Commit ad3d4b3

Browse files
committed
Merge #20661: Only select from addrv2-capable peers for torv3 address relay
37fe80e Only consider addrv2 peers for relay of non-addrv1 addresses (Pieter Wuille) 83f8821 refactor: add IsAddrCompatible() to CNode (Pieter Wuille) Pull request description: When selecting peers to relay an address to, only pick addrv2-capable ones if the address cannot be represented in addr(v1). Without this I expect that propagation of torv3 addresses over the cleartext network will be very hard for a while. ACKs for top commit: jonatack: ACK 37fe80e vasild: ACK 37fe80e Tree-SHA512: 18a854ea43ad473cf89b9c5193b524109d7af75c26f7aa7e26cd72ad0db52f19c8001d566c607a7e6772bc314f770f09b6c3e07282d110c5daea193edc592cd2
2 parents 69f1ee1 + 37fe80e commit ad3d4b3

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/net.h

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

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

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

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,8 +1443,8 @@ static void RelayAddress(const CNode& originator,
14431443
std::array<std::pair<uint64_t, CNode*>,2> best{{{0, nullptr}, {0, nullptr}}};
14441444
assert(nRelayNodes <= best.size());
14451445

1446-
auto sortfunc = [&best, &hasher, nRelayNodes, &originator](CNode* pnode) {
1447-
if (pnode->RelayAddrsWithConn() && pnode != &originator) {
1446+
auto sortfunc = [&best, &hasher, nRelayNodes, &originator, &addr](CNode* pnode) {
1447+
if (pnode->RelayAddrsWithConn() && pnode != &originator && pnode->IsAddrCompatible(addr)) {
14481448
uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize();
14491449
for (unsigned int i = 0; i < nRelayNodes; i++) {
14501450
if (hashKey > best[i].first) {

0 commit comments

Comments
 (0)