Skip to content

Commit

Permalink
Allow to filter for fully connected nodes when calling CopyNodeVector (
Browse files Browse the repository at this point in the history
…#1864)

And use this where needed. This avoids warnings about unset version fields
and is also generally a good thing (we really should only communicate with
nodes we know are good)
  • Loading branch information
codablock authored and UdjinM6 committed Jan 22, 2018
1 parent 4052401 commit b84afb2
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex *pindex, CConnman& co

void CGovernanceManager::RequestOrphanObjects(CConnman& connman)
{
std::vector<CNode*> vNodesCopy = connman.CopyNodeVector();
std::vector<CNode*> vNodesCopy = connman.CopyNodeVector(CConnman::FullyConnectedOnly);

std::vector<uint256> vecHashesFiltered;
{
Expand Down
4 changes: 2 additions & 2 deletions src/masternode-sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void CMasternodeSync::ProcessTick(CConnman& connman)

// gradually request the rest of the votes after sync finished
if(IsSynced()) {
std::vector<CNode*> vNodesCopy = connman.CopyNodeVector();
std::vector<CNode*> vNodesCopy = connman.CopyNodeVector(CConnman::FullyConnectedOnly);
governance.RequestGovernanceObjectVotes(vNodesCopy, connman);
connman.ReleaseNodeVector(vNodesCopy);
return;
Expand All @@ -190,7 +190,7 @@ void CMasternodeSync::ProcessTick(CConnman& connman)
LogPrintf("CMasternodeSync::ProcessTick -- nTick %d nRequestedMasternodeAssets %d nRequestedMasternodeAttempt %d nSyncProgress %f\n", nTick, nRequestedMasternodeAssets, nRequestedMasternodeAttempt, nSyncProgress);
uiInterface.NotifyAdditionalDataSyncProgressChanged(nSyncProgress);

std::vector<CNode*> vNodesCopy = connman.CopyNodeVector();
std::vector<CNode*> vNodesCopy = connman.CopyNodeVector(CConnman::FullyConnectedOnly);

BOOST_FOREACH(CNode* pnode, vNodesCopy)
{
Expand Down
2 changes: 1 addition & 1 deletion src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ bool CMasternodeMan::SendVerifyRequest(const CAddress& addr, const std::vector<C
CMasternodeVerification mnv(addr, GetRandInt(999999), nCachedBlockHeight - 1);
mWeAskedForVerification[addr] = mnv;
LogPrintf("CMasternodeMan::SendVerifyRequest -- verifying node using nonce %d addr=%s\n", mnv.nonce, addr.ToString());
CNetMsgMaker msgMaker(pnode->GetSendVersion());
CNetMsgMaker msgMaker(pnode->GetSendVersion()); // TODO this gives a warning about version not being set (we should wait for VERSION exchange)
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::MNVERIFY, mnv));
return true;
});
Expand Down
9 changes: 8 additions & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2841,18 +2841,25 @@ 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);
}

std::vector<CNode*> CConnman::CopyNodeVector()
std::vector<CNode*> CConnman::CopyNodeVector(std::function<bool(const CNode* pnode)> cond)
{
std::vector<CNode*> vecNodesCopy;
LOCK(cs_vNodes);
for(size_t i = 0; i < vNodes.size(); ++i) {
CNode* pnode = vNodes[i];
if (!cond(pnode))
continue;
pnode->AddRef();
vecNodesCopy.push_back(pnode);
}
return vecNodesCopy;
}

std::vector<CNode*> CConnman::CopyNodeVector()
{
return CopyNodeVector(AllNodes);
}

void CConnman::ReleaseNodeVector(const std::vector<CNode*>& vecNodes)
{
LOCK(cs_vNodes);
Expand Down
1 change: 1 addition & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class CConnman
ForEachNodeThen(FullyConnectedOnly, pre, post);
}

std::vector<CNode*> CopyNodeVector(std::function<bool(const CNode* pnode)> cond);
std::vector<CNode*> CopyNodeVector();
void ReleaseNodeVector(const std::vector<CNode*>& vecNodes);

Expand Down
4 changes: 2 additions & 2 deletions src/privatesend-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ bool CPrivateSendClient::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CCon
infoMixingMasternode = infoMn;
nSessionDenom = dsq.nDenom;

CNetMsgMaker msgMaker(pnode->GetSendVersion());
CNetMsgMaker msgMaker(pnode->GetSendVersion()); // TODO this gives a warning about version not being set (we should wait for VERSION exchange)
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSACCEPT, nSessionDenom, txMyCollateral));
LogPrintf("CPrivateSendClient::JoinExistingQueue -- connected (from queue), sending DSACCEPT: nSessionDenom: %d (%s), addr=%s\n",
nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), pnode->addr.ToString());
Expand Down Expand Up @@ -963,7 +963,7 @@ bool CPrivateSendClient::StartNewQueue(CAmount nValueMin, CAmount nBalanceNeedsA
nSessionDenom = CPrivateSend::GetDenominationsByAmounts(vecAmounts);
}

CNetMsgMaker msgMaker(pnode->GetSendVersion());
CNetMsgMaker msgMaker(pnode->GetSendVersion()); // TODO this gives a warning about version not being set (we should wait for VERSION exchange)
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSACCEPT, nSessionDenom, txMyCollateral));
LogPrintf("CPrivateSendClient::StartNewQueue -- connected, sending DSACCEPT, nSessionDenom: %d (%s)\n",
nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom));
Expand Down
2 changes: 1 addition & 1 deletion src/privatesend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool CDarksendQueue::CheckSignature(const CPubKey& pubKeyMasternode)

bool CDarksendQueue::Relay(CConnman& connman)
{
std::vector<CNode*> vNodesCopy = connman.CopyNodeVector();
std::vector<CNode*> vNodesCopy = connman.CopyNodeVector(CConnman::FullyConnectedOnly);
BOOST_FOREACH(CNode* pnode, vNodesCopy) {
CNetMsgMaker msgMaker(pnode->GetSendVersion());
if (pnode->nVersion >= MIN_PRIVATESEND_PEER_PROTO_VERSION)
Expand Down

0 comments on commit b84afb2

Please sign in to comment.