ConnectNode/FindNide:

- Use FindNode instead of explicit loops
- Do not use FindNode where we can grab node right from ConnectNode (slightly less cs_vNodes)
This commit is contained in:
UdjinM6 2015-08-04 23:51:16 +03:00
parent 8220292fb1
commit ff159ad7e7
3 changed files with 38 additions and 56 deletions

View File

@ -105,16 +105,12 @@ void CDarkSendRelay::RelayThroughNode(int nRank)
if(pmn != NULL){ if(pmn != NULL){
//printf("RelayThroughNode %s\n", pmn->addr.ToString().c_str()); //printf("RelayThroughNode %s\n", pmn->addr.ToString().c_str());
if(ConnectNode((CAddress)pmn->addr, NULL, true)){ CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, true);
if(pnode){
//printf("Connected\n"); //printf("Connected\n");
CNode* pNode = FindNode(pmn->addr); pnode->PushMessage("dsr", (*this));
if(pNode)
{
//printf("Found\n");
pNode->PushMessage("dsr", (*this));
return; return;
} }
}
} else { } else {
//printf("RelayThroughNode NULL\n"); //printf("RelayThroughNode NULL\n");
} }

View File

@ -1527,9 +1527,8 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
} }
// connect to Masternode and submit the queue request // connect to Masternode and submit the queue request
if(ConnectNode((CAddress)addr, NULL, true)){ CNode* pnode = ConnectNode((CAddress)addr, NULL, true);
CNode* pnode = FindNode(addr); if(pnode != NULL)
if(pnode)
{ {
CMasternode* pmn = mnodeman.Find(dsq.vin); CMasternode* pmn = mnodeman.Find(dsq.vin);
if(pmn == NULL) if(pmn == NULL)
@ -1546,7 +1545,6 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
strAutoDenomResult = _("Mixing in progress..."); strAutoDenomResult = _("Mixing in progress...");
dsq.time = 0; //remove node dsq.time = 0; //remove node
return true; return true;
}
} else { } else {
LogPrintf("DoAutomaticDenominating --- error connecting \n"); LogPrintf("DoAutomaticDenominating --- error connecting \n");
strAutoDenomResult = _("Error connecting to Masternode."); strAutoDenomResult = _("Error connecting to Masternode.");
@ -1577,13 +1575,8 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
lastTimeChanged = GetTimeMillis(); lastTimeChanged = GetTimeMillis();
LogPrintf("DoAutomaticDenominating -- attempt %d connection to Masternode %s\n", i, pmn->addr.ToString()); LogPrintf("DoAutomaticDenominating -- attempt %d connection to Masternode %s\n", i, pmn->addr.ToString());
if(ConnectNode((CAddress)pmn->addr, NULL, true)){ CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, true);
if(pnode != NULL){
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
if((CNetAddr)pnode->addr != (CNetAddr)pmn->addr) continue;
pSubmittedToMasternode = pmn; pSubmittedToMasternode = pmn;
vecMasternodesUsed.push_back(pmn->vin); vecMasternodesUsed.push_back(pmn->vin);
@ -1597,7 +1590,6 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
LogPrintf("DoAutomaticDenominating --- connected, sending dsa for %d\n", sessionDenom); LogPrintf("DoAutomaticDenominating --- connected, sending dsa for %d\n", sessionDenom);
strAutoDenomResult = _("Mixing in progress..."); strAutoDenomResult = _("Mixing in progress...");
return true; return true;
}
} else { } else {
i++; i++;
continue; continue;
@ -2167,6 +2159,7 @@ void CDarksendPool::RelayFinalTransaction(const int sessionID, const CTransactio
void CDarksendPool::RelayIn(const std::vector<CTxDSIn>& vin, const int64_t& nAmount, const CTransaction& txCollateral, const std::vector<CTxDSOut>& vout) void CDarksendPool::RelayIn(const std::vector<CTxDSIn>& vin, const int64_t& nAmount, const CTransaction& txCollateral, const std::vector<CTxDSOut>& vout)
{ {
if(!pSubmittedToMasternode) return;
std::vector<CTxIn> vin2; std::vector<CTxIn> vin2;
std::vector<CTxOut> vout2; std::vector<CTxOut> vout2;
@ -2177,11 +2170,8 @@ void CDarksendPool::RelayIn(const std::vector<CTxDSIn>& vin, const int64_t& nAmo
BOOST_FOREACH(CTxDSOut out, vout) BOOST_FOREACH(CTxDSOut out, vout)
vout2.push_back(out); vout2.push_back(out);
LOCK(cs_vNodes); CNode* pnode = FindNode(pSubmittedToMasternode->addr);
BOOST_FOREACH(CNode* pnode, vNodes) if(pnode != NULL) {
{
if(!pSubmittedToMasternode) return;
if((CNetAddr)pSubmittedToMasternode->addr != (CNetAddr)pnode->addr) continue;
LogPrintf("RelayIn - found master, relaying message - %s \n", pnode->addr.ToString()); LogPrintf("RelayIn - found master, relaying message - %s \n", pnode->addr.ToString());
pnode->PushMessage("dsi", vin2, nAmount, txCollateral, vout2); pnode->PushMessage("dsi", vin2, nAmount, txCollateral, vout2);
} }

View File

@ -618,12 +618,8 @@ void CMasternodeMan::ProcessMasternodeConnections()
if(!darkSendPool.pSubmittedToMasternode) return; if(!darkSendPool.pSubmittedToMasternode) return;
LOCK(cs_vNodes); CNode* pnode = FindNode(darkSendPool.pSubmittedToMasternode->addr);
if(pnode != NULL) {
BOOST_FOREACH(CNode* pnode, vNodes)
{
if(darkSendPool.pSubmittedToMasternode->addr == pnode->addr) continue;
if(pnode->fDarkSendMaster){ if(pnode->fDarkSendMaster){
LogPrintf("Closing Masternode connection %s \n", pnode->addr.ToString()); LogPrintf("Closing Masternode connection %s \n", pnode->addr.ToString());
pnode->fDisconnect = true; pnode->fDisconnect = true;