@@ -326,6 +326,15 @@ class PeerManagerImpl final : public PeerManager
326
326
/* * Send `addr` messages on a regular schedule. */
327
327
void MaybeSendAddr (CNode& node, std::chrono::microseconds current_time);
328
328
329
+ /* * Relay (gossip) an address to a few randomly chosen nodes.
330
+ *
331
+ * @param[in] originator The id of the peer that sent us the address. We don't want to relay it back.
332
+ * @param[in] addr Address to relay.
333
+ * @param[in] fReachable Whether the address' network is reachable. We relay unreachable
334
+ * addresses less.
335
+ */
336
+ void RelayAddress (NodeId originator, const CAddress& addr, bool fReachable );
337
+
329
338
const CChainParams& m_chainparams;
330
339
CConnman& m_connman;
331
340
CAddrMan& m_addrman;
@@ -1483,31 +1492,23 @@ void PeerManagerImpl::RelayTransaction(const uint256& txid, const uint256& wtxid
1483
1492
});
1484
1493
}
1485
1494
1486
- /* *
1487
- * Relay (gossip) an address to a few randomly chosen nodes.
1488
- * We choose the same nodes within a given 24h window (if the list of connected
1489
- * nodes does not change) and we don't relay to nodes that already know an
1490
- * address. So within 24h we will likely relay a given address once. This is to
1491
- * prevent a peer from unjustly giving their address better propagation by sending
1492
- * it to us repeatedly.
1493
- * @param[in] originator The id of the peer that sent us the address. We don't want to relay it back.
1494
- * @param[in] addr Address to relay.
1495
- * @param[in] fReachable Whether the address' network is reachable. We relay unreachable
1496
- * addresses less.
1497
- * @param[in] connman Connection manager to choose nodes to relay to.
1498
- */
1499
- static void RelayAddress (NodeId originator,
1500
- const CAddress& addr,
1501
- bool fReachable ,
1502
- const CConnman& connman)
1495
+ void PeerManagerImpl::RelayAddress (NodeId originator,
1496
+ const CAddress& addr,
1497
+ bool fReachable )
1503
1498
{
1499
+ // We choose the same nodes within a given 24h window (if the list of connected
1500
+ // nodes does not change) and we don't relay to nodes that already know an
1501
+ // address. So within 24h we will likely relay a given address once. This is to
1502
+ // prevent a peer from unjustly giving their address better propagation by sending
1503
+ // it to us repeatedly.
1504
+
1504
1505
if (!fReachable && !addr.IsRelayable ()) return ;
1505
1506
1506
1507
// Relay to a limited number of other nodes
1507
1508
// Use deterministic randomness to send to the same nodes for 24 hours
1508
1509
// at a time so the m_addr_knowns of the chosen nodes prevent repeats
1509
1510
uint64_t hashAddr = addr.GetHash ();
1510
- const CSipHasher hasher = connman .GetDeterministicRandomizer (RANDOMIZER_ID_ADDRESS_RELAY).Write (hashAddr << 32 ).Write ((GetTime () + hashAddr) / (24 * 60 * 60 ));
1511
+ const CSipHasher hasher = m_connman .GetDeterministicRandomizer (RANDOMIZER_ID_ADDRESS_RELAY).Write (hashAddr << 32 ).Write ((GetTime () + hashAddr) / (24 * 60 * 60 ));
1511
1512
FastRandomContext insecure_rand;
1512
1513
1513
1514
// Relay reachable addresses to 2 peers. Unreachable addresses are relayed randomly to 1 or 2 peers.
@@ -1535,7 +1536,7 @@ static void RelayAddress(NodeId originator,
1535
1536
}
1536
1537
};
1537
1538
1538
- connman .ForEachNodeThen (std::move (sortfunc), std::move (pushfunc));
1539
+ m_connman .ForEachNodeThen (std::move (sortfunc), std::move (pushfunc));
1539
1540
}
1540
1541
1541
1542
void PeerManagerImpl::ProcessGetBlockData (CNode& pfrom, Peer& peer, const CInv& inv)
@@ -2683,7 +2684,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
2683
2684
if (addr.nTime > nSince && !pfrom.fGetAddr && vAddr.size () <= 10 && addr.IsRoutable ())
2684
2685
{
2685
2686
// Relay to a limited number of other nodes
2686
- RelayAddress (pfrom.GetId (), addr, fReachable , m_connman );
2687
+ RelayAddress (pfrom.GetId (), addr, fReachable );
2687
2688
}
2688
2689
// Do not store addresses outside our network
2689
2690
if (fReachable )
0 commit comments