Skip to content

Commit

Permalink
net: use ForEachNode instead of manually iterating through vNodes
Browse files Browse the repository at this point in the history
ForEachNode is publicly available, which will help us extract the
functions from CConnman in a subsequent commit
  • Loading branch information
kwvg committed Apr 23, 2024
1 parent 6194e45 commit d54ba44
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3934,52 +3934,49 @@ void CConnman::RelayTransaction(const CTransaction& tx, const bool is_dstx)
}

void CConnman::RelayInv(CInv &inv, const int minProtoVersion) {
LOCK(cs_vNodes);
for (const auto& pnode : vNodes) {
ForEachNode([&](CNode* pnode) {
if (pnode->nVersion < minProtoVersion || !pnode->CanRelay())
continue;
return;
pnode->PushInventory(inv);
}
});
}

void CConnman::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const int minProtoVersion)
{
LOCK(cs_vNodes);
for (const auto& pnode : vNodes) {
ForEachNode([&](CNode* pnode) {
if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || pnode->IsBlockOnlyConn()) {
continue;
return;
}
{
LOCK(pnode->m_tx_relay->cs_filter);
if (!pnode->m_tx_relay->fRelayTxes) {
continue;
return;
}
if (pnode->m_tx_relay->pfilter && !pnode->m_tx_relay->pfilter->IsRelevantAndUpdate(relatedTx)) {
continue;
return;
}
}
pnode->PushInventory(inv);
}
});
}

void CConnman::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash, const int minProtoVersion)
{
LOCK(cs_vNodes);
for (const auto& pnode : vNodes) {
ForEachNode([&](CNode* pnode) {
if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || pnode->IsBlockOnlyConn()) {
continue;
return;
}
{
LOCK(pnode->m_tx_relay->cs_filter);
if (!pnode->m_tx_relay->fRelayTxes) {
continue;
return;
}
if (pnode->m_tx_relay->pfilter && !pnode->m_tx_relay->pfilter->contains(relatedTxHash)) {
continue;
return;
}
}
pnode->PushInventory(inv);
}
});
}

void CConnman::RecordBytesRecv(uint64_t bytes)
Expand Down

0 comments on commit d54ba44

Please sign in to comment.