Skip to content

Commit d1a2295

Browse files
JeremyRubintheuni
authored andcommitted
Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
1 parent 98591c5 commit d1a2295

File tree

7 files changed

+41
-15
lines changed

7 files changed

+41
-15
lines changed

src/main.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,7 +3091,6 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
30913091
pnode->PushBlockHash(hash);
30923092
}
30933093
}
3094-
return true;
30953094
});
30963095
}
30973096
// Notify external listeners about the new tip.
@@ -4727,7 +4726,6 @@ static void RelayTransaction(const CTransaction& tx, CConnman& connman)
47274726
connman.ForEachNode([&inv](CNode* pnode)
47284727
{
47294728
pnode->PushInventory(inv);
4730-
return true;
47314729
});
47324730
}
47334731

@@ -4749,7 +4747,6 @@ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman& connma
47494747
uint64_t hashKey = CSipHasher(hasher).Write(pnode->id).Finalize();
47504748
mapMix.emplace(hashKey, pnode);
47514749
}
4752-
return true;
47534750
};
47544751

47554752
auto pushfunc = [&addr, &mapMix, &nRelayNodes] {

src/net.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,7 @@ bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func)
26972697
return found != nullptr && func(found);
26982698
}
26992699

2700-
bool CConnman::ForEachNode(std::function<bool(CNode* pnode)> func)
2700+
bool CConnman::ForEachNodeContinueIf(std::function<bool(CNode* pnode)> func)
27012701
{
27022702
LOCK(cs_vNodes);
27032703
for (auto&& node : vNodes)
@@ -2706,7 +2706,7 @@ bool CConnman::ForEachNode(std::function<bool(CNode* pnode)> func)
27062706
return true;
27072707
}
27082708

2709-
bool CConnman::ForEachNode(std::function<bool(const CNode* pnode)> func) const
2709+
bool CConnman::ForEachNodeContinueIf(std::function<bool(const CNode* pnode)> func) const
27102710
{
27112711
LOCK(cs_vNodes);
27122712
for (const auto& node : vNodes)
@@ -2715,7 +2715,7 @@ bool CConnman::ForEachNode(std::function<bool(const CNode* pnode)> func) const
27152715
return true;
27162716
}
27172717

2718-
bool CConnman::ForEachNodeThen(std::function<bool(CNode* pnode)> pre, std::function<void()> post)
2718+
bool CConnman::ForEachNodeContinueIfThen(std::function<bool(CNode* pnode)> pre, std::function<void()> post)
27192719
{
27202720
bool ret = true;
27212721
LOCK(cs_vNodes);
@@ -2728,7 +2728,7 @@ bool CConnman::ForEachNodeThen(std::function<bool(CNode* pnode)> pre, std::funct
27282728
return ret;
27292729
}
27302730

2731-
bool CConnman::ForEachNodeThen(std::function<bool(const CNode* pnode)> pre, std::function<void()> post) const
2731+
bool CConnman::ForEachNodeContinueIfThen(std::function<bool(const CNode* pnode)> pre, std::function<void()> post) const
27322732
{
27332733
bool ret = true;
27342734
LOCK(cs_vNodes);
@@ -2741,6 +2741,35 @@ bool CConnman::ForEachNodeThen(std::function<bool(const CNode* pnode)> pre, std:
27412741
return ret;
27422742
}
27432743

2744+
void CConnman::ForEachNode(std::function<void(CNode* pnode)> func)
2745+
{
2746+
LOCK(cs_vNodes);
2747+
for (auto&& node : vNodes)
2748+
func(node);
2749+
}
2750+
2751+
void CConnman::ForEachNode(std::function<void(const CNode* pnode)> func) const
2752+
{
2753+
LOCK(cs_vNodes);
2754+
for (const auto& node : vNodes)
2755+
func(node);
2756+
}
2757+
2758+
void CConnman::ForEachNodeThen(std::function<void(CNode* pnode)> pre, std::function<void()> post)
2759+
{
2760+
LOCK(cs_vNodes);
2761+
for (auto&& node : vNodes)
2762+
pre(node);
2763+
post();
2764+
}
2765+
2766+
void CConnman::ForEachNodeThen(std::function<void(const CNode* pnode)> pre, std::function<void()> post) const
2767+
{
2768+
LOCK(cs_vNodes);
2769+
for (const auto& node : vNodes)
2770+
pre(node);
2771+
post();
2772+
}
27442773
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) {
27452774
return nNow + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5);
27462775
}

src/net.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,14 @@ class CConnman
129129
bool CheckIncomingNonce(uint64_t nonce);
130130

131131
bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
132-
bool ForEachNode(std::function<bool(CNode* pnode)> func);
133-
bool ForEachNode(std::function<bool(const CNode* pnode)> func) const;
134-
bool ForEachNodeThen(std::function<bool(CNode* pnode)> pre, std::function<void()> post);
135-
bool ForEachNodeThen(std::function<bool(const CNode* pnode)> pre, std::function<void()> post) const;
132+
bool ForEachNodeContinueIf(std::function<bool(CNode* pnode)> func);
133+
bool ForEachNodeContinueIf(std::function<bool(const CNode* pnode)> func) const;
134+
bool ForEachNodeContinueIfThen(std::function<bool(CNode* pnode)> pre, std::function<void()> post);
135+
bool ForEachNodeContinueIfThen(std::function<bool(const CNode* pnode)> pre, std::function<void()> post) const;
136+
void ForEachNode(std::function<void(CNode* pnode)> func);
137+
void ForEachNode(std::function<void(const CNode* pnode)> func) const;
138+
void ForEachNodeThen(std::function<void(CNode* pnode)> pre, std::function<void()> post);
139+
void ForEachNodeThen(std::function<void(const CNode* pnode)> pre, std::function<void()> post) const;
136140

137141
void RelayTransaction(const CTransaction& tx);
138142

src/rpc/misc.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ UniValue setmocktime(const UniValue& params, bool fHelp)
481481
if(g_connman) {
482482
g_connman->ForEachNode([t](CNode* pnode) {
483483
pnode->nLastSend = pnode->nLastRecv = t;
484-
return true;
485484
});
486485
}
487486

src/rpc/net.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ UniValue ping(const UniValue& params, bool fHelp)
6161
// Request that each node send a ping during next message processing pass
6262
g_connman->ForEachNode([](CNode* pnode) {
6363
pnode->fPingQueued = true;
64-
return true;
6564
});
6665
return NullUniValue;
6766
}

src/rpc/rawtransaction.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,6 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp)
898898
g_connman->ForEachNode([&inv](CNode* pnode)
899899
{
900900
pnode->PushInventory(inv);
901-
return true;
902901
});
903902
return hashTx.GetHex();
904903
}

src/wallet/wallet.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,6 @@ bool CWalletTx::RelayWalletTransaction(CConnman* connman)
14651465
connman->ForEachNode([&inv](CNode* pnode)
14661466
{
14671467
pnode->PushInventory(inv);
1468-
return true;
14691468
});
14701469
return true;
14711470
}

0 commit comments

Comments
 (0)