Skip to content

Commit

Permalink
net_processing: making PushTierTwoGetDataRequest return a bool in cas…
Browse files Browse the repository at this point in the history
…e of pushing the message.
  • Loading branch information
furszy committed Feb 21, 2021
1 parent 51dea23 commit 10efbe5
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,77 +757,81 @@ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman& connma
connman.ForEachNodeThen(std::move(sortfunc), std::move(pushfunc));
}

void static PushTierTwoGetDataRequest(const CInv& inv,
bool static PushTierTwoGetDataRequest(const CInv& inv,
CNode* pfrom,
CConnman& connman,
CNetMsgMaker& msgMaker,
bool& pushed)
CNetMsgMaker& msgMaker)
{
if (!pushed && inv.type == MSG_SPORK) {
if (inv.type == MSG_SPORK) {
if (mapSporks.count(inv.hash)) {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << mapSporks[inv.hash];
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::SPORK, ss));
pushed = true;
return true;
}
}
if (!pushed && inv.type == MSG_MASTERNODE_WINNER) {

if (inv.type == MSG_MASTERNODE_WINNER) {
if (masternodePayments.mapMasternodePayeeVotes.count(inv.hash)) {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << masternodePayments.mapMasternodePayeeVotes[inv.hash];
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::MNWINNER, ss));
pushed = true;
return true;
}
}
if (!pushed && inv.type == MSG_BUDGET_VOTE) {

if (inv.type == MSG_BUDGET_VOTE) {
if (g_budgetman.HaveSeenProposalVote(inv.hash)) {
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::BUDGETVOTE, g_budgetman.GetProposalVoteSerialized(inv.hash)));
pushed = true;
return true;
}
}

if (!pushed && inv.type == MSG_BUDGET_PROPOSAL) {
if (inv.type == MSG_BUDGET_PROPOSAL) {
if (g_budgetman.HaveProposal(inv.hash)) {
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::BUDGETPROPOSAL, g_budgetman.GetProposalSerialized(inv.hash)));
pushed = true;
return true;
}
}

if (!pushed && inv.type == MSG_BUDGET_FINALIZED_VOTE) {
if (inv.type == MSG_BUDGET_FINALIZED_VOTE) {
if (g_budgetman.HaveSeenFinalizedBudgetVote(inv.hash)) {
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::FINALBUDGETVOTE, g_budgetman.GetFinalizedBudgetVoteSerialized(inv.hash)));
pushed = true;
return true;
}
}

if (!pushed && inv.type == MSG_BUDGET_FINALIZED) {
if (inv.type == MSG_BUDGET_FINALIZED) {
if (g_budgetman.HaveFinalizedBudget(inv.hash)) {
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::FINALBUDGET, g_budgetman.GetFinalizedBudgetSerialized(inv.hash)));
pushed = true;
return true;
}
}

if (!pushed && inv.type == MSG_MASTERNODE_ANNOUNCE) {
if (inv.type == MSG_MASTERNODE_ANNOUNCE) {
if (mnodeman.mapSeenMasternodeBroadcast.count(inv.hash)) {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << mnodeman.mapSeenMasternodeBroadcast[inv.hash];
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::MNBROADCAST, ss));
pushed = true;
return true;
}
}

if (!pushed && inv.type == MSG_MASTERNODE_PING) {
if (inv.type == MSG_MASTERNODE_PING) {
if (mnodeman.mapSeenMasternodePing.count(inv.hash)) {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << mnodeman.mapSeenMasternodePing[inv.hash];
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::MNPING, ss));
pushed = true;
return true;
}
}

// nothing was pushed.
return false;
}

void static ProcessGetData(CNode* pfrom, CConnman& connman, std::atomic<bool>& interruptMsgProc)
Expand Down Expand Up @@ -927,12 +931,10 @@ void static ProcessGetData(CNode* pfrom, CConnman& connman, std::atomic<bool>& i
}
}

// Now check if it's a tier two data request and push it.
PushTierTwoGetDataRequest(inv,
pfrom,
connman,
msgMaker,
pushed);
if (!pushed) {
// Now check if it's a tier two data request and push it.
pushed = PushTierTwoGetDataRequest(inv, pfrom, connman, msgMaker);
}

if (!pushed) {
vNotFound.push_back(inv);
Expand Down

0 comments on commit 10efbe5

Please sign in to comment.