Skip to content

Commit caba7ae

Browse files
committed
[net processing] Make RelayAddress() a member function of PeerManagerImpl
1 parent 86acc96 commit caba7ae

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/net_processing.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,15 @@ class PeerManagerImpl final : public PeerManager
326326
/** Send `addr` messages on a regular schedule. */
327327
void MaybeSendAddr(CNode& node, std::chrono::microseconds current_time);
328328

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+
329338
const CChainParams& m_chainparams;
330339
CConnman& m_connman;
331340
CAddrMan& m_addrman;
@@ -1483,31 +1492,23 @@ void PeerManagerImpl::RelayTransaction(const uint256& txid, const uint256& wtxid
14831492
});
14841493
}
14851494

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)
15031498
{
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+
15041505
if (!fReachable && !addr.IsRelayable()) return;
15051506

15061507
// Relay to a limited number of other nodes
15071508
// Use deterministic randomness to send to the same nodes for 24 hours
15081509
// at a time so the m_addr_knowns of the chosen nodes prevent repeats
15091510
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));
15111512
FastRandomContext insecure_rand;
15121513

15131514
// 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,
15351536
}
15361537
};
15371538

1538-
connman.ForEachNodeThen(std::move(sortfunc), std::move(pushfunc));
1539+
m_connman.ForEachNodeThen(std::move(sortfunc), std::move(pushfunc));
15391540
}
15401541

15411542
void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv& inv)
@@ -2683,7 +2684,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
26832684
if (addr.nTime > nSince && !pfrom.fGetAddr && vAddr.size() <= 10 && addr.IsRoutable())
26842685
{
26852686
// Relay to a limited number of other nodes
2686-
RelayAddress(pfrom.GetId(), addr, fReachable, m_connman);
2687+
RelayAddress(pfrom.GetId(), addr, fReachable);
26872688
}
26882689
// Do not store addresses outside our network
26892690
if (fReachable)

0 commit comments

Comments
 (0)