Skip to content

Commit 2fcaec7

Browse files
committed
[net_processing] Introduce SetupAddressRelay
Idempotent function that initializes m_addr_known for connections that support address relay (anything other than block-relay-only). Unused until the next commit.
1 parent 7925f3a commit 2fcaec7

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/net_processing.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ struct Peer {
226226
std::vector<CAddress> m_addrs_to_send;
227227
/** Probabilistic filter of addresses that this peer already knows.
228228
* Used to avoid relaying addresses to this peer more than once. */
229-
const std::unique_ptr<CRollingBloomFilter> m_addr_known;
229+
std::unique_ptr<CRollingBloomFilter> m_addr_known;
230230
/** Whether a getaddr request to this peer is outstanding. */
231231
bool m_getaddr_sent{false};
232232
/** Guards address sending timers. */
@@ -612,6 +612,14 @@ class PeerManagerImpl final : public PeerManager
612612
* @param[in] vRecv The raw message received
613613
*/
614614
void ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv);
615+
616+
/** Checks if address relay is permitted with peer. Initializes
617+
* `m_addr_known` bloom filter if needed.
618+
*
619+
* @return True if address relay is enabled with peer
620+
* False if address relay is disallowed
621+
*/
622+
bool SetupAddressRelay(CNode& node, Peer& peer);
615623
};
616624
} // namespace
617625

@@ -4423,6 +4431,22 @@ class CompareInvMempoolOrder
44234431
};
44244432
}
44254433

4434+
bool PeerManagerImpl::SetupAddressRelay(CNode& node, Peer& peer)
4435+
{
4436+
// We don't participate in addr relay with outbound block-relay-only
4437+
// connections to prevent providing adversaries with the additional
4438+
// information of addr traffic to infer the link.
4439+
if (node.IsBlockOnlyConn()) return false;
4440+
4441+
if (!RelayAddrsWithPeer(peer)) {
4442+
// First addr message we have received from the peer, initialize
4443+
// m_addr_known
4444+
peer.m_addr_known = std::make_unique<CRollingBloomFilter>(5000, 0.001);
4445+
}
4446+
4447+
return true;
4448+
}
4449+
44264450
bool PeerManagerImpl::SendMessages(CNode* pto)
44274451
{
44284452
PeerRef peer = GetPeerRef(pto->GetId());

0 commit comments

Comments
 (0)