@@ -740,6 +740,48 @@ std::pair<CService, std::set<uint256> > CMasternodeMan::PopScheduledMnbRequestCo
740740 return std::make_pair (pairFront.first , setResult);
741741}
742742
743+ void CMasternodeMan::ProcessQueuedMnbRequests (CConnman& connman)
744+ {
745+ std::pair<CService, std::set<uint256> > p = mnodeman.PopScheduledMnbRequestConnection ();
746+ if (!(p.first == CService () || p.second .empty ())) {
747+ if (connman.IsMasternodeOrDisconnectRequested (p.first )) return ;
748+ mnbQueue.push_back (std::make_pair (GetTime (), p));
749+ connman.AddPendingMasternode (p.first );
750+ }
751+
752+ if (!mnbQueue.empty ()) {
753+ // wait at least 5 seconds since we tried to open corresponding connection
754+ if (GetTime () - mnbQueue.front ().first < 5 ) {
755+ return ;
756+ }
757+
758+ auto request = mnbQueue.front ().second ;
759+ LogPrint (" masternode" , " %s -- processing mnb queue for addr=%s\n " , __func__, request.first .ToString ());
760+
761+ connman.ForNode (request.first , [&](CNode* pnode) {
762+
763+ // compile request vector
764+ std::vector<CInv> vToFetch;
765+ std::set<uint256>::iterator it = request.second .begin ();
766+ while (it != request.second .end ()) {
767+ if (*it != uint256 ()) {
768+ vToFetch.push_back (CInv (MSG_MASTERNODE_ANNOUNCE, *it));
769+ LogPrint (" masternode" , " -- asking for mnb %s from addr=%s\n " , it->ToString (), pnode->addr .ToString ());
770+ }
771+ ++it;
772+ }
773+
774+ // ask for data
775+ CNetMsgMaker msgMaker (pnode->GetSendVersion ());
776+ connman.PushMessage (pnode, msgMaker.Make (NetMsgType::GETDATA, vToFetch));
777+ return true ;
778+ });
779+
780+ // drop it from the request queue regardless
781+ mnbQueue.pop_front ();
782+ LogPrint (" masternode" , " %s -- mnb queue size: %d\n " , __func__, mnbQueue.size ());
783+ }
784+ }
743785
744786void CMasternodeMan::ProcessMessage (CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman)
745787{
@@ -1049,25 +1091,45 @@ bool CMasternodeMan::SendVerifyRequest(const CAddress& addr, const std::vector<C
10491091 return false ;
10501092 }
10511093
1052- connman.OpenMasternodeConnection (addr);
1053- bool fSuccess = connman.ForNode (addr, CConnman::AllNodes, [&](CNode* pnode){
1054- netfulfilledman.AddFulfilledRequest (addr, strprintf (" %s" , NetMsgType::MNVERIFY)+" -request" );
1055- // use random nonce, store it and require node to reply with correct one later
1056- CMasternodeVerification mnv (addr, GetRandInt (999999 ), nCachedBlockHeight - 1 );
1057- mWeAskedForVerification [addr] = mnv;
1058- LogPrintf (" CMasternodeMan::SendVerifyRequest -- verifying node using nonce %d addr=%s\n " , mnv.nonce , addr.ToString ());
1059- CNetMsgMaker msgMaker (pnode->GetSendVersion ()); // TODO this gives a warning about version not being set (we should wait for VERSION exchange)
1060- connman.PushMessage (pnode, msgMaker.Make (NetMsgType::MNVERIFY, mnv));
1061- return true ;
1062- });
1063- if (!fSuccess ) {
1064- LogPrintf (" CMasternodeMan::SendVerifyRequest -- can't connect to node to verify it, addr=%s\n " , addr.ToString ());
1065- return false ;
1066- }
1094+ if (connman.IsMasternodeOrDisconnectRequested (addr)) return false ;
10671095
1096+ connman.AddPendingMasternode (addr);
1097+ // use random nonce, store it and require node to reply with correct one later
1098+ CMasternodeVerification mnv (addr, GetRandInt (999999 ), nCachedBlockHeight - 1 );
1099+ LOCK (cs_mnvQueue);
1100+ mnvQueue.push_back (std::make_pair (GetTime (), std::make_pair (addr, mnv)));
1101+ LogPrintf (" CMasternodeMan::SendVerifyRequest -- verifying node using nonce %d addr=%s\n " , mnv.nonce , addr.ToString ());
10681102 return true ;
10691103}
10701104
1105+ void CMasternodeMan::ProcessQueuedMnvRequests (CConnman& connman)
1106+ {
1107+ LOCK (cs_mnvQueue);
1108+
1109+ if (!mnvQueue.empty ()) {
1110+ // wait at least 5 seconds since we tried to open corresponding connection
1111+ if (GetTime () - mnvQueue.front ().first < 5 ) {
1112+ return ;
1113+ }
1114+
1115+ auto request = mnvQueue.front ().second ;
1116+ LogPrint (" masternode" , " CMasternodeMan::%s -- processing mnv queue for addr=%s\n " , __func__, request.first .ToString ());
1117+
1118+ connman.ForNode (request.first , [&](CNode* pnode) {
1119+ netfulfilledman.AddFulfilledRequest (pnode->addr , strprintf (" %s" , NetMsgType::MNVERIFY)+" -request" );
1120+ // use random nonce, store it and require node to reply with correct one later
1121+ mWeAskedForVerification [pnode->addr ] = request.second ;
1122+ LogPrint (" masternode" , " -- verifying node using nonce %d addr=%s\n " , request.second .nonce , pnode->addr .ToString ());
1123+ CNetMsgMaker msgMaker (pnode->GetSendVersion ()); // TODO this gives a warning about version not being set (we should wait for VERSION exchange)
1124+ connman.PushMessage (pnode, msgMaker.Make (NetMsgType::MNVERIFY, request.second ));
1125+ return true ;
1126+ });
1127+
1128+ mnvQueue.pop_front ();
1129+ LogPrint (" masternode" , " CMasternodeMan::%s -- mnv queue size: %d\n " , __func__, mnvQueue.size ());
1130+ }
1131+ }
1132+
10711133void CMasternodeMan::SendVerifyReply (CNode* pnode, CMasternodeVerification& mnv, CConnman& connman)
10721134{
10731135 // only masternodes can sign this, why would someone ask regular node?
0 commit comments