@@ -224,8 +224,13 @@ struct Peer {
224
224
225
225
/* * A vector of addresses to send to the peer, limited to MAX_ADDR_TO_SEND. */
226
226
std::vector<CAddress> m_addrs_to_send;
227
- /* * Probabilistic filter of addresses that this peer already knows.
228
- * Used to avoid relaying addresses to this peer more than once. */
227
+ /* * Probabilistic filter to track recent addr messages relayed with this
228
+ * peer. Used to avoid relaying redundant addresses to this peer.
229
+ *
230
+ * We initialize this filter for outbound peers (other than
231
+ * block-relay-only connections) or when an inbound peer sends us an
232
+ * address related message (ADDR, ADDRV2, GETADDR).
233
+ **/
229
234
std::unique_ptr<CRollingBloomFilter> m_addr_known;
230
235
/* * Whether a getaddr request to this peer is outstanding. */
231
236
bool m_getaddr_sent{false };
@@ -258,9 +263,8 @@ struct Peer {
258
263
/* * Work queue of items requested by this peer **/
259
264
std::deque<CInv> m_getdata_requests GUARDED_BY (m_getdata_requests_mutex);
260
265
261
- explicit Peer (NodeId id, bool addr_relay )
266
+ explicit Peer (NodeId id)
262
267
: m_id(id)
263
- , m_addr_known{addr_relay ? std::make_unique<CRollingBloomFilter>(5000 , 0.001 ) : nullptr }
264
268
{}
265
269
};
266
270
@@ -1125,9 +1129,7 @@ void PeerManagerImpl::InitializeNode(CNode *pnode)
1125
1129
assert (m_txrequest.Count (nodeid) == 0 );
1126
1130
}
1127
1131
{
1128
- // Addr relay is disabled for outbound block-relay-only peers to
1129
- // prevent adversaries from inferring these links from addr traffic.
1130
- PeerRef peer = std::make_shared<Peer>(nodeid, /* addr_relay = */ !pnode->IsBlockOnlyConn ());
1132
+ PeerRef peer = std::make_shared<Peer>(nodeid);
1131
1133
LOCK (m_peer_mutex);
1132
1134
m_peer_map.emplace_hint (m_peer_map.end (), nodeid, std::move (peer));
1133
1135
}
@@ -2580,7 +2582,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
2580
2582
UpdatePreferredDownload (pfrom, State (pfrom.GetId ()));
2581
2583
}
2582
2584
2583
- if (!pfrom.IsInboundConn () && !pfrom.IsBlockOnlyConn ()) {
2585
+ // Self advertisement & GETADDR logic
2586
+ if (!pfrom.IsInboundConn () && SetupAddressRelay (pfrom, *peer)) {
2584
2587
// For outbound peers, we try to relay our address (so that other
2585
2588
// nodes can try to find us more quickly, as we have no guarantee
2586
2589
// that an outbound peer is even aware of how to reach us) and do a
@@ -2589,8 +2592,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
2589
2592
// empty and no one will know who we are, so these mechanisms are
2590
2593
// important to help us connect to the network.
2591
2594
//
2592
- // We skip this for block-relay-only peers to avoid potentially leaking
2593
- // information about our block-relay-only connections via address relay.
2595
+ // We skip this for block-relay-only peers. We want to avoid
2596
+ // potentially leaking addr information and we do not want to
2597
+ // indicate to the peer that we will participate in addr relay.
2594
2598
if (fListen && !m_chainman.ActiveChainstate ().IsInitialBlockDownload ())
2595
2599
{
2596
2600
CAddress addr = GetLocalAddress (&pfrom.addr , pfrom.GetLocalServices ());
@@ -2788,10 +2792,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
2788
2792
2789
2793
s >> vAddr;
2790
2794
2791
- if (!RelayAddrsWithPeer ( *peer)) {
2795
+ if (!SetupAddressRelay (pfrom, *peer)) {
2792
2796
LogPrint (BCLog::NET, " ignoring %s message from %s peer=%d\n " , msg_type, pfrom.ConnectionTypeAsString (), pfrom.GetId ());
2793
2797
return ;
2794
2798
}
2799
+
2795
2800
if (vAddr.size () > MAX_ADDR_TO_SEND)
2796
2801
{
2797
2802
Misbehaving (pfrom.GetId (), 20 , strprintf (" %s message size = %u" , msg_type, vAddr.size ()));
@@ -3725,6 +3730,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3725
3730
return ;
3726
3731
}
3727
3732
3733
+ SetupAddressRelay (pfrom, *peer);
3734
+
3728
3735
// Only send one GetAddr response per connection to reduce resource waste
3729
3736
// and discourage addr stamping of INV announcements.
3730
3737
if (peer->m_getaddr_recvd ) {
0 commit comments