From 2fcaec7bbb96d6fe72a7e3a5744b0c35c79733e8 Mon Sep 17 00:00:00 2001 From: Amiti Uttarwar Date: Mon, 22 Mar 2021 15:48:17 -0700 Subject: [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. --- src/net_processing.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/net_processing.cpp b/src/net_processing.cpp index a0c346b99f..1d53d1a1b7 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -226,7 +226,7 @@ struct Peer { std::vector m_addrs_to_send; /** Probabilistic filter of addresses that this peer already knows. * Used to avoid relaying addresses to this peer more than once. */ - const std::unique_ptr m_addr_known; + std::unique_ptr m_addr_known; /** Whether a getaddr request to this peer is outstanding. */ bool m_getaddr_sent{false}; /** Guards address sending timers. */ @@ -612,6 +612,14 @@ private: * @param[in] vRecv The raw message received */ void ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv); + + /** Checks if address relay is permitted with peer. Initializes + * `m_addr_known` bloom filter if needed. + * + * @return True if address relay is enabled with peer + * False if address relay is disallowed + */ + bool SetupAddressRelay(CNode& node, Peer& peer); }; } // namespace @@ -4423,6 +4431,22 @@ public: }; } +bool PeerManagerImpl::SetupAddressRelay(CNode& node, Peer& peer) +{ + // We don't participate in addr relay with outbound block-relay-only + // connections to prevent providing adversaries with the additional + // information of addr traffic to infer the link. + if (node.IsBlockOnlyConn()) return false; + + if (!RelayAddrsWithPeer(peer)) { + // First addr message we have received from the peer, initialize + // m_addr_known + peer.m_addr_known = std::make_unique(5000, 0.001); + } + + return true; +} + bool PeerManagerImpl::SendMessages(CNode* pto) { PeerRef peer = GetPeerRef(pto->GetId()); -- cgit v1.2.3