aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorAmiti Uttarwar <amiti@uttarwar.org>2021-07-26 11:48:58 -0700
committerAmiti Uttarwar <amiti@uttarwar.org>2021-07-29 17:41:19 -0700
commit201e4964816f8896cfe7b4f6d8ddbfffe7102f87 (patch)
tree428baf0ee19c92b69cc1894c455bcae859c88dc3 /src/net_processing.cpp
parent1d1ef2db7ea0d93c7dab4a9800ec74afa7a019eb (diff)
downloadbitcoin-201e4964816f8896cfe7b4f6d8ddbfffe7102f87.tar.xz
[net_processing] Introduce new field to indicate if addr relay is enabled
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index fe20421a21..e9bb4f2211 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -230,8 +230,25 @@ struct Peer {
* We initialize this filter for outbound peers (other than
* block-relay-only connections) or when an inbound peer sends us an
* address related message (ADDR, ADDRV2, GETADDR).
+ *
+ * Presence of this filter must correlate with m_addr_relay_enabled.
**/
std::unique_ptr<CRollingBloomFilter> m_addr_known;
+ /** Whether we are participating in address relay with this connection.
+ *
+ * We set this bool to true for outbound peers (other than
+ * block-relay-only connections), or when an inbound peer sends us an
+ * address related message (ADDR, ADDRV2, GETADDR).
+ *
+ * We use this bool to decide whether a peer is eligible for gossiping
+ * addr messages. This avoids relaying to peers that are unlikely to
+ * forward them, effectively blackholing self announcements. Reasons
+ * peers might support addr relay on the link include that they connected
+ * to us as a block-relay-only peer or they are a light client.
+ *
+ * This field must correlate with whether m_addr_known has been
+ * initialized.*/
+ std::atomic_bool m_addr_relay_enabled{false};
/** Whether a getaddr request to this peer is outstanding. */
bool m_getaddr_sent{false};
/** Guards address sending timers. */
@@ -617,8 +634,8 @@ private:
*/
void ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv);
- /** Checks if address relay is permitted with peer. Initializes
- * `m_addr_known` bloom filter if needed.
+ /** Checks if address relay is permitted with peer. If needed, initializes
+ * the m_addr_known bloom filter and sets m_addr_relay_enabled to true.
*
* @return True if address relay is enabled with peer
* False if address relay is disallowed
@@ -746,7 +763,7 @@ static CNodeState *State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
static bool RelayAddrsWithPeer(const Peer& peer)
{
- return peer.m_addr_known != nullptr;
+ return peer.m_addr_relay_enabled;
}
/**
@@ -4449,6 +4466,7 @@ bool PeerManagerImpl::SetupAddressRelay(CNode& node, Peer& 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);
+ peer.m_addr_relay_enabled = true;
}
return true;