unrelated style nit in the second commit: instead of passing connman and peerman, this could be made a member function of peerman. The following diff on top of this commit compiles for me. Though, this can also be done in a separate pull.
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index e9584ddac1..84ac462099 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -258,6 +258,9 @@ public:
/** Whether to relay addresses with a peer. */
bool IsAddrRelayPeer(const CNode& pnode);
+ void RelayAddress(const CNode& originator,
+ const CAddress& addr,
+ bool fReachable);
private:
/** Consider evicting an outbound peer based on the amount of time they've been behind our tip */
@@ -1640,14 +1643,10 @@ void RelayTransaction(const uint256& txid, const uint256& wtxid, const CConnman&
* [@param](/bitcoin-bitcoin/contributor/param/)[in] addr Address to relay.
* [@param](/bitcoin-bitcoin/contributor/param/)[in] fReachable Whether the address' network is reachable. We relay unreachable
* addresses less.
- * [@param](/bitcoin-bitcoin/contributor/param/)[in] connman Connection manager to choose nodes to relay to.
- * [@param](/bitcoin-bitcoin/contributor/param/)[in] peerman PeerManager implementation being used
*/
-static void RelayAddress(const CNode& originator,
- const CAddress& addr,
- bool fReachable,
- const CConnman& connman,
- PeerManagerImpl* peerman)
+void PeerManagerImpl::RelayAddress(const CNode& originator,
+ const CAddress& addr,
+ bool fReachable)
{
if (!fReachable && !addr.IsRelayable()) return;
@@ -1655,7 +1654,7 @@ static void RelayAddress(const CNode& originator,
// Use deterministic randomness to send to the same nodes for 24 hours
// at a time so the m_addr_knowns of the chosen nodes prevent repeats
uint64_t hashAddr = addr.GetHash();
- const CSipHasher hasher = connman.GetDeterministicRandomizer(RANDOMIZER_ID_ADDRESS_RELAY).Write(hashAddr << 32).Write((GetTime() + hashAddr) / (24 * 60 * 60));
+ const CSipHasher hasher = m_connman.GetDeterministicRandomizer(RANDOMIZER_ID_ADDRESS_RELAY).Write(hashAddr << 32).Write((GetTime() + hashAddr) / (24 * 60 * 60));
FastRandomContext insecure_rand;
// Relay reachable addresses to 2 peers. Unreachable addresses are relayed randomly to 1 or 2 peers.
@@ -1664,7 +1663,7 @@ static void RelayAddress(const CNode& originator,
std::array<std::pair<uint64_t, CNode*>,2> best{{{0, nullptr}, {0, nullptr}}};
assert(nRelayNodes <= best.size());
- auto sortfunc = [&best, &hasher, nRelayNodes, &originator, &addr, &peerman](CNode* pnode) {
+ auto sortfunc = [&best, &hasher, nRelayNodes, &originator, &addr, peerman = this](CNode* pnode) {
if (peerman->IsAddrRelayPeer(*pnode) && pnode != &originator && pnode->IsAddrCompatible(addr)) {
uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize();
for (unsigned int i = 0; i < nRelayNodes; i++) {
@@ -1683,7 +1682,7 @@ static void RelayAddress(const CNode& originator,
}
};
- connman.ForEachNodeThen(std::move(sortfunc), std::move(pushfunc));
+ m_connman.ForEachNodeThen(std::move(sortfunc), std::move(pushfunc));
}
void static ProcessGetBlockData(CNode& pfrom, Peer& peer, const CChainParams& chainparams, const CInv& inv, CConnman& connman)
@@ -2885,7 +2884,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
if (addr.nTime > nSince && !pfrom.fGetAddr && vAddr.size() <= 10 && addr.IsRoutable())
{
// Relay to a limited number of other nodes
- RelayAddress(pfrom, addr, fReachable, m_connman, this);
+ RelayAddress(pfrom, addr, fReachable);
}
// Do not store addresses outside our network
if (fReachable)