mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-17 18:40:09 +00:00
Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
This commit is contained in:
parent
98591c5027
commit
d1a2295f0d
@ -3091,7 +3091,6 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
|
|||||||
pnode->PushBlockHash(hash);
|
pnode->PushBlockHash(hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Notify external listeners about the new tip.
|
// Notify external listeners about the new tip.
|
||||||
@ -4727,7 +4726,6 @@ static void RelayTransaction(const CTransaction& tx, CConnman& connman)
|
|||||||
connman.ForEachNode([&inv](CNode* pnode)
|
connman.ForEachNode([&inv](CNode* pnode)
|
||||||
{
|
{
|
||||||
pnode->PushInventory(inv);
|
pnode->PushInventory(inv);
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4749,7 +4747,6 @@ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman& connma
|
|||||||
uint64_t hashKey = CSipHasher(hasher).Write(pnode->id).Finalize();
|
uint64_t hashKey = CSipHasher(hasher).Write(pnode->id).Finalize();
|
||||||
mapMix.emplace(hashKey, pnode);
|
mapMix.emplace(hashKey, pnode);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto pushfunc = [&addr, &mapMix, &nRelayNodes] {
|
auto pushfunc = [&addr, &mapMix, &nRelayNodes] {
|
||||||
|
37
src/net.cpp
37
src/net.cpp
@ -2697,7 +2697,7 @@ bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func)
|
|||||||
return found != nullptr && func(found);
|
return found != nullptr && func(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConnman::ForEachNode(std::function<bool(CNode* pnode)> func)
|
bool CConnman::ForEachNodeContinueIf(std::function<bool(CNode* pnode)> func)
|
||||||
{
|
{
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
for (auto&& node : vNodes)
|
for (auto&& node : vNodes)
|
||||||
@ -2706,7 +2706,7 @@ bool CConnman::ForEachNode(std::function<bool(CNode* pnode)> func)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConnman::ForEachNode(std::function<bool(const CNode* pnode)> func) const
|
bool CConnman::ForEachNodeContinueIf(std::function<bool(const CNode* pnode)> func) const
|
||||||
{
|
{
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
for (const auto& node : vNodes)
|
for (const auto& node : vNodes)
|
||||||
@ -2715,7 +2715,7 @@ bool CConnman::ForEachNode(std::function<bool(const CNode* pnode)> func) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConnman::ForEachNodeThen(std::function<bool(CNode* pnode)> pre, std::function<void()> post)
|
bool CConnman::ForEachNodeContinueIfThen(std::function<bool(CNode* pnode)> pre, std::function<void()> post)
|
||||||
{
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
@ -2728,7 +2728,7 @@ bool CConnman::ForEachNodeThen(std::function<bool(CNode* pnode)> pre, std::funct
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConnman::ForEachNodeThen(std::function<bool(const CNode* pnode)> pre, std::function<void()> post) const
|
bool CConnman::ForEachNodeContinueIfThen(std::function<bool(const CNode* pnode)> pre, std::function<void()> post) const
|
||||||
{
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
@ -2741,6 +2741,35 @@ bool CConnman::ForEachNodeThen(std::function<bool(const CNode* pnode)> pre, std:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CConnman::ForEachNode(std::function<void(CNode* pnode)> func)
|
||||||
|
{
|
||||||
|
LOCK(cs_vNodes);
|
||||||
|
for (auto&& node : vNodes)
|
||||||
|
func(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CConnman::ForEachNode(std::function<void(const CNode* pnode)> func) const
|
||||||
|
{
|
||||||
|
LOCK(cs_vNodes);
|
||||||
|
for (const auto& node : vNodes)
|
||||||
|
func(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CConnman::ForEachNodeThen(std::function<void(CNode* pnode)> pre, std::function<void()> post)
|
||||||
|
{
|
||||||
|
LOCK(cs_vNodes);
|
||||||
|
for (auto&& node : vNodes)
|
||||||
|
pre(node);
|
||||||
|
post();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CConnman::ForEachNodeThen(std::function<void(const CNode* pnode)> pre, std::function<void()> post) const
|
||||||
|
{
|
||||||
|
LOCK(cs_vNodes);
|
||||||
|
for (const auto& node : vNodes)
|
||||||
|
pre(node);
|
||||||
|
post();
|
||||||
|
}
|
||||||
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) {
|
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) {
|
||||||
return nNow + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5);
|
return nNow + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5);
|
||||||
}
|
}
|
||||||
|
12
src/net.h
12
src/net.h
@ -129,10 +129,14 @@ public:
|
|||||||
bool CheckIncomingNonce(uint64_t nonce);
|
bool CheckIncomingNonce(uint64_t nonce);
|
||||||
|
|
||||||
bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
|
bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
|
||||||
bool ForEachNode(std::function<bool(CNode* pnode)> func);
|
bool ForEachNodeContinueIf(std::function<bool(CNode* pnode)> func);
|
||||||
bool ForEachNode(std::function<bool(const CNode* pnode)> func) const;
|
bool ForEachNodeContinueIf(std::function<bool(const CNode* pnode)> func) const;
|
||||||
bool ForEachNodeThen(std::function<bool(CNode* pnode)> pre, std::function<void()> post);
|
bool ForEachNodeContinueIfThen(std::function<bool(CNode* pnode)> pre, std::function<void()> post);
|
||||||
bool ForEachNodeThen(std::function<bool(const CNode* pnode)> pre, std::function<void()> post) const;
|
bool ForEachNodeContinueIfThen(std::function<bool(const CNode* pnode)> pre, std::function<void()> post) const;
|
||||||
|
void ForEachNode(std::function<void(CNode* pnode)> func);
|
||||||
|
void ForEachNode(std::function<void(const CNode* pnode)> func) const;
|
||||||
|
void ForEachNodeThen(std::function<void(CNode* pnode)> pre, std::function<void()> post);
|
||||||
|
void ForEachNodeThen(std::function<void(const CNode* pnode)> pre, std::function<void()> post) const;
|
||||||
|
|
||||||
void RelayTransaction(const CTransaction& tx);
|
void RelayTransaction(const CTransaction& tx);
|
||||||
|
|
||||||
|
@ -481,7 +481,6 @@ UniValue setmocktime(const UniValue& params, bool fHelp)
|
|||||||
if(g_connman) {
|
if(g_connman) {
|
||||||
g_connman->ForEachNode([t](CNode* pnode) {
|
g_connman->ForEachNode([t](CNode* pnode) {
|
||||||
pnode->nLastSend = pnode->nLastRecv = t;
|
pnode->nLastSend = pnode->nLastRecv = t;
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,6 @@ UniValue ping(const UniValue& params, bool fHelp)
|
|||||||
// Request that each node send a ping during next message processing pass
|
// Request that each node send a ping during next message processing pass
|
||||||
g_connman->ForEachNode([](CNode* pnode) {
|
g_connman->ForEachNode([](CNode* pnode) {
|
||||||
pnode->fPingQueued = true;
|
pnode->fPingQueued = true;
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
}
|
}
|
||||||
|
@ -898,7 +898,6 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp)
|
|||||||
g_connman->ForEachNode([&inv](CNode* pnode)
|
g_connman->ForEachNode([&inv](CNode* pnode)
|
||||||
{
|
{
|
||||||
pnode->PushInventory(inv);
|
pnode->PushInventory(inv);
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
return hashTx.GetHex();
|
return hashTx.GetHex();
|
||||||
}
|
}
|
||||||
|
@ -1465,7 +1465,6 @@ bool CWalletTx::RelayWalletTransaction(CConnman* connman)
|
|||||||
connman->ForEachNode([&inv](CNode* pnode)
|
connman->ForEachNode([&inv](CNode* pnode)
|
||||||
{
|
{
|
||||||
pnode->PushInventory(inv);
|
pnode->PushInventory(inv);
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user