mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Merge #20661: Only select from addrv2-capable peers for torv3 address relay
37fe80e626
Only consider addrv2 peers for relay of non-addrv1 addresses (Pieter Wuille)83f8821a6f
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: ACK37fe80e626
vasild: ACK37fe80e626
Tree-SHA512: 18a854ea43ad473cf89b9c5193b524109d7af75c26f7aa7e26cd72ad0db52f19c8001d566c607a7e6772bc314f770f09b6c3e07282d110c5daea193edc592cd2
This commit is contained in:
commit
ad3d4b3929
2 changed files with 13 additions and 8 deletions
17
src/net.h
17
src/net.h
|
@ -1177,18 +1177,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 {
|
||||||
|
|
|
@ -1443,8 +1443,8 @@ static void RelayAddress(const CNode& originator,
|
||||||
std::array<std::pair<uint64_t, CNode*>,2> best{{{0, nullptr}, {0, nullptr}}};
|
std::array<std::pair<uint64_t, CNode*>,2> best{{{0, nullptr}, {0, nullptr}}};
|
||||||
assert(nRelayNodes <= best.size());
|
assert(nRelayNodes <= best.size());
|
||||||
|
|
||||||
auto sortfunc = [&best, &hasher, nRelayNodes, &originator](CNode* pnode) {
|
auto sortfunc = [&best, &hasher, nRelayNodes, &originator, &addr](CNode* pnode) {
|
||||||
if (pnode->RelayAddrsWithConn() && pnode != &originator) {
|
if (pnode->RelayAddrsWithConn() && pnode != &originator && pnode->IsAddrCompatible(addr)) {
|
||||||
uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize();
|
uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize();
|
||||||
for (unsigned int i = 0; i < nRelayNodes; i++) {
|
for (unsigned int i = 0; i < nRelayNodes; i++) {
|
||||||
if (hashKey > best[i].first) {
|
if (hashKey > best[i].first) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue