aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorAmiti Uttarwar <amiti@uttarwar.org>2021-03-22 15:48:17 -0700
committerAmiti Uttarwar <amiti@uttarwar.org>2021-07-29 17:40:17 -0700
commit2fcaec7bbb96d6fe72a7e3a5744b0c35c79733e8 (patch)
treea1e9a9b03bd4ba4db75cabc00853f6078c077e0f /src/net_processing.cpp
parent7925f3aba820f8965293148ef666c59f87dd3c7f (diff)
downloadbitcoin-2fcaec7bbb96d6fe72a7e3a5744b0c35c79733e8.tar.xz
[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.
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp26
1 files changed, 25 insertions, 1 deletions
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<CAddress> 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<CRollingBloomFilter> m_addr_known;
+ std::unique_ptr<CRollingBloomFilter> 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<CRollingBloomFilter>(5000, 0.001);
+ }
+
+ return true;
+}
+
bool PeerManagerImpl::SendMessages(CNode* pto)
{
PeerRef peer = GetPeerRef(pto->GetId());