Skip to content

Commit 9f939f3

Browse files
theuniFuzzbawls
authored andcommitted
net: switch all callers to connman for pushing messages
Drop all of the old stuff.
1 parent 8f9011d commit 9f939f3

File tree

8 files changed

+57
-295
lines changed

8 files changed

+57
-295
lines changed

src/main.cpp

Lines changed: 40 additions & 40 deletions
Large diffs are not rendered by default.

src/masternode-budget.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ void CBudgetManager::Sync(CNode* pfrom, const uint256& nProp, bool fPartial)
13641364
++it1;
13651365
}
13661366

1367-
pfrom->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_BUDGET_PROP, nInvCount);
1367+
g_connman->PushMessage(pfrom, NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_BUDGET_PROP, nInvCount);
13681368

13691369
LogPrint(BCLog::MNBUDGET, "CBudgetManager::Sync - sent %d items\n", nInvCount);
13701370

@@ -1392,7 +1392,7 @@ void CBudgetManager::Sync(CNode* pfrom, const uint256& nProp, bool fPartial)
13921392
++it3;
13931393
}
13941394

1395-
pfrom->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_BUDGET_FIN, nInvCount);
1395+
g_connman->PushMessage(pfrom, NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_BUDGET_FIN, nInvCount);
13961396
LogPrint(BCLog::MNBUDGET, "CBudgetManager::Sync - sent %d items\n", nInvCount);
13971397
}
13981398

@@ -1410,7 +1410,7 @@ bool CBudgetManager::UpdateProposal(CBudgetVote& vote, CNode* pfrom, std::string
14101410
mapOrphanMasternodeBudgetVotes[vote.nProposalHash] = vote;
14111411

14121412
if (!askedForSourceProposalOrBudget.count(vote.nProposalHash)) {
1413-
pfrom->PushMessage(NetMsgType::BUDGETVOTESYNC, vote.nProposalHash);
1413+
g_connman->PushMessage(pfrom, NetMsgType::BUDGETVOTESYNC, vote.nProposalHash);
14141414
askedForSourceProposalOrBudget[vote.nProposalHash] = GetTime();
14151415
}
14161416
}
@@ -1437,7 +1437,7 @@ bool CBudgetManager::UpdateFinalizedBudget(CFinalizedBudgetVote& vote, CNode* pf
14371437
mapOrphanFinalizedBudgetVotes[vote.nBudgetHash] = vote;
14381438

14391439
if (!askedForSourceProposalOrBudget.count(vote.nBudgetHash)) {
1440-
pfrom->PushMessage(NetMsgType::BUDGETVOTESYNC, vote.nBudgetHash);
1440+
g_connman->PushMessage(pfrom, NetMsgType::BUDGETVOTESYNC, vote.nBudgetHash);
14411441
askedForSourceProposalOrBudget[vote.nBudgetHash] = GetTime();
14421442
}
14431443
}

src/masternode-payments.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ void CMasternodePayments::Sync(CNode* node, int nCountNeeded)
784784
}
785785
++it;
786786
}
787-
node->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_MNW, nInvCount);
787+
g_connman->PushMessage(node, NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_MNW, nInvCount);
788788
}
789789

790790
std::string CMasternodePayments::ToString() const

src/masternode-sync.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,14 @@ bool CMasternodeSync::SyncWithNode(CNode* pnode, bool isRegTestNet)
291291
{
292292
if (isRegTestNet) {
293293
if (RequestedMasternodeAttempt <= 2) {
294-
pnode->PushMessage(NetMsgType::GETSPORKS); //get current network sporks
294+
g_connman->PushMessageWithVersion(pnode, INIT_PROTO_VERSION, NetMsgType::GETSPORKS); //get current network sporks
295295
} else if (RequestedMasternodeAttempt < 4) {
296296
mnodeman.DsegUpdate(pnode);
297297
} else if (RequestedMasternodeAttempt < 6) {
298298
int nMnCount = mnodeman.CountEnabled();
299-
pnode->PushMessage(NetMsgType::GETMNWINNERS, nMnCount); //sync payees
299+
g_connman->PushMessage(pnode, NetMsgType::GETMNWINNERS, nMnCount); //sync payees
300300
uint256 n;
301-
pnode->PushMessage(NetMsgType::BUDGETVOTESYNC, n); //sync masternode votes
301+
g_connman->PushMessage(pnode, NetMsgType::BUDGETVOTESYNC, n); //sync masternode votes
302302
} else {
303303
RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED;
304304
}
@@ -311,7 +311,7 @@ bool CMasternodeSync::SyncWithNode(CNode* pnode, bool isRegTestNet)
311311
if (pnode->HasFulfilledRequest("getspork")) return true;
312312
pnode->FulfilledRequest("getspork");
313313

314-
pnode->PushMessage(NetMsgType::GETSPORKS); //get current network sporks
314+
g_connman->PushMessageWithVersion(pnode, INIT_PROTO_VERSION, NetMsgType::GETSPORKS); //get current network sporks
315315
if (RequestedMasternodeAttempt >= 2) GetNextAsset();
316316
RequestedMasternodeAttempt++;
317317
return false;
@@ -377,7 +377,7 @@ bool CMasternodeSync::SyncWithNode(CNode* pnode, bool isRegTestNet)
377377
if (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3) return false;
378378

379379
int nMnCount = mnodeman.CountEnabled();
380-
pnode->PushMessage(NetMsgType::GETMNWINNERS, nMnCount); //sync payees
380+
g_connman->PushMessage(pnode, NetMsgType::GETMNWINNERS, nMnCount); //sync payees
381381
RequestedMasternodeAttempt++;
382382
return false;
383383
}
@@ -410,7 +410,7 @@ bool CMasternodeSync::SyncWithNode(CNode* pnode, bool isRegTestNet)
410410
if (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3) return false;
411411

412412
uint256 n;
413-
pnode->PushMessage(NetMsgType::BUDGETVOTESYNC, n); //sync masternode votes
413+
g_connman->PushMessage(pnode, NetMsgType::BUDGETVOTESYNC, n); //sync masternode votes
414414
RequestedMasternodeAttempt++;
415415
return false;
416416
}

src/masternodeman.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void CMasternodeMan::AskForMN(CNode* pnode, CTxIn& vin)
232232
// ask for the mnb info once from the node that sent mnp
233233

234234
LogPrint(BCLog::MASTERNODE, "CMasternodeMan::AskForMN - Asking node for missing entry, vin: %s\n", vin.prevout.hash.ToString());
235-
pnode->PushMessage(NetMsgType::GETMNLIST, vin);
235+
g_connman->PushMessage(pnode, NetMsgType::GETMNLIST, vin);
236236
int64_t askAgain = GetTime() + MASTERNODE_MIN_MNP_SECONDS;
237237
mWeAskedForMasternodeListEntry[vin.prevout] = askAgain;
238238
}
@@ -437,7 +437,7 @@ void CMasternodeMan::DsegUpdate(CNode* pnode)
437437
}
438438
}
439439

440-
pnode->PushMessage(NetMsgType::GETMNLIST, CTxIn());
440+
g_connman->PushMessage(pnode, NetMsgType::GETMNLIST, CTxIn());
441441
int64_t askAgain = GetTime() + MASTERNODES_DSEG_SECONDS;
442442
mWeAskedForMasternodeList[pnode->addr] = askAgain;
443443
}
@@ -810,7 +810,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
810810
}
811811

812812
if (vin == CTxIn()) {
813-
pfrom->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_LIST, nInvCount);
813+
g_connman->PushMessage(pfrom, NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_LIST, nInvCount);
814814
LogPrint(BCLog::MASTERNODE, "dseg - Sent %d Masternode entries to peer %i\n", nInvCount, pfrom->GetId());
815815
}
816816
}

src/net.cpp

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ bool CNode::DisconnectOldProtocol(int nVersionRequired, std::string strLastComma
494494
fDisconnect = false;
495495
if (nVersion < nVersionRequired) {
496496
LogPrintf("%s : peer=%d using obsolete version %i; disconnecting\n", __func__, id, nVersion);
497-
PushMessage(NetMsgType::REJECT, strLastCommand, REJECT_OBSOLETE, strprintf("Version must be %d or greater", ActiveProtocol()));
497+
g_connman->PushMessageWithVersion(this, INIT_PROTO_VERSION, NetMsgType::REJECT, strLastCommand, REJECT_OBSOLETE, strprintf("Version must be %d or greater", ActiveProtocol()));
498498
fDisconnect = true;
499499
}
500500

@@ -2392,7 +2392,7 @@ void CConnman::RelayTransactionLockReq(const CTransaction& tx, bool relayToAll)
23922392
if (!relayToAll && !pnode->fRelayTxes)
23932393
continue;
23942394

2395-
pnode->PushMessage(NetMsgType::IX, tx);
2395+
g_connman->PushMessage(pnode, NetMsgType::IX, tx);
23962396
}
23972397
}
23982398

@@ -2584,68 +2584,6 @@ void CNode::AskFor(const CInv& inv)
25842584
mapAskFor.insert(std::make_pair(nRequestTime, inv));
25852585
}
25862586

2587-
void CNode::BeginMessage(const char* pszCommand) EXCLUSIVE_LOCK_FUNCTION(cs_vSend)
2588-
{
2589-
ENTER_CRITICAL_SECTION(cs_vSend);
2590-
assert(ssSend.size() == 0);
2591-
ssSend << CMessageHeader(Params().MessageStart(), pszCommand, 0);
2592-
LogPrint(BCLog::NET, "sending: %s ", SanitizeString(pszCommand));
2593-
}
2594-
2595-
void CNode::AbortMessage() UNLOCK_FUNCTION(cs_vSend)
2596-
{
2597-
ssSend.clear();
2598-
2599-
LEAVE_CRITICAL_SECTION(cs_vSend);
2600-
2601-
LogPrint(BCLog::NET, "(aborted)\n");
2602-
}
2603-
2604-
void CNode::EndMessage(const char* pszCommand) UNLOCK_FUNCTION(cs_vSend)
2605-
{
2606-
// The -*messagestest options are intentionally not documented in the help message,
2607-
// since they are only used during development to debug the networking code and are
2608-
// not intended for end-users.
2609-
if (mapArgs.count("-dropmessagestest") && GetRand(GetArg("-dropmessagestest", 2)) == 0) {
2610-
LogPrint(BCLog::NET, "dropmessages DROPPING SEND MESSAGE\n");
2611-
AbortMessage();
2612-
return;
2613-
}
2614-
if (mapArgs.count("-fuzzmessagestest"))
2615-
Fuzz(GetArg("-fuzzmessagestest", 10));
2616-
2617-
if (ssSend.size() == 0) {
2618-
LEAVE_CRITICAL_SECTION(cs_vSend);
2619-
return;
2620-
}
2621-
2622-
// Set the size
2623-
unsigned int nSize = ssSend.size() - CMessageHeader::HEADER_SIZE;
2624-
WriteLE32((uint8_t*)&ssSend[CMessageHeader::MESSAGE_SIZE_OFFSET], nSize);
2625-
2626-
//log total amount of bytes per command
2627-
mapSendBytesPerMsgCmd[std::string(pszCommand)] += nSize + CMessageHeader::HEADER_SIZE;
2628-
2629-
// Set the checksum
2630-
uint256 hash = Hash(ssSend.begin() + CMessageHeader::HEADER_SIZE, ssSend.end());
2631-
unsigned int nChecksum = 0;
2632-
memcpy(&nChecksum, &hash, sizeof(nChecksum));
2633-
assert(ssSend.size() >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum));
2634-
memcpy((char*)&ssSend[CMessageHeader::CHECKSUM_OFFSET], &nChecksum, sizeof(nChecksum));
2635-
2636-
LogPrint(BCLog::NET, "(%d bytes) peer=%d\n", nSize, id);
2637-
2638-
std::deque<CSerializeData>::iterator it = vSendMsg.insert(vSendMsg.end(), CSerializeData());
2639-
ssSend.GetAndClear(*it);
2640-
nSendSize += (*it).size();
2641-
2642-
// If write queue empty, attempt "optimistic write"
2643-
if (it == vSendMsg.begin())
2644-
nOptimisticBytesWritten += SocketSendData(this);
2645-
2646-
LEAVE_CRITICAL_SECTION(cs_vSend);
2647-
}
2648-
26492587
CDataStream CConnman::BeginMessage(CNode* pnode, int nVersion, int flags, const std::string& sCommand)
26502588
{
26512589
return {SER_NETWORK, (nVersion ? nVersion : pnode->GetSendVersion()) | flags, CMessageHeader(Params().MessageStart(), sCommand.c_str(), 0) };

src/net.h

Lines changed: 0 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -804,182 +804,6 @@ class CNode
804804

805805
void AskFor(const CInv& inv);
806806

807-
// TODO: Document the postcondition of this function. Is cs_vSend locked?
808-
void BeginMessage(const char* pszCommand) EXCLUSIVE_LOCK_FUNCTION(cs_vSend);
809-
810-
// TODO: Document the precondition of this function. Is cs_vSend locked?
811-
void AbortMessage() UNLOCK_FUNCTION(cs_vSend);
812-
813-
// TODO: Document the precondition of this function. Is cs_vSend locked?
814-
void EndMessage(const char* pszCommand) UNLOCK_FUNCTION(cs_vSend);
815-
816-
void PushMessage(const char* pszCommand)
817-
{
818-
try {
819-
BeginMessage(pszCommand);
820-
EndMessage(pszCommand);
821-
} catch (...) {
822-
AbortMessage();
823-
throw;
824-
}
825-
}
826-
827-
template <typename T1>
828-
void PushMessage(const char* pszCommand, const T1& a1)
829-
{
830-
try {
831-
BeginMessage(pszCommand);
832-
ssSend << a1;
833-
EndMessage(pszCommand);
834-
} catch (...) {
835-
AbortMessage();
836-
throw;
837-
}
838-
}
839-
840-
template <typename T1, typename T2>
841-
void PushMessage(const char* pszCommand, const T1& a1, const T2& a2)
842-
{
843-
try {
844-
BeginMessage(pszCommand);
845-
ssSend << a1 << a2;
846-
EndMessage(pszCommand);
847-
} catch (...) {
848-
AbortMessage();
849-
throw;
850-
}
851-
}
852-
853-
template <typename T1, typename T2, typename T3>
854-
void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3)
855-
{
856-
try {
857-
BeginMessage(pszCommand);
858-
ssSend << a1 << a2 << a3;
859-
EndMessage(pszCommand);
860-
} catch (...) {
861-
AbortMessage();
862-
throw;
863-
}
864-
}
865-
866-
template <typename T1, typename T2, typename T3, typename T4>
867-
void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4)
868-
{
869-
try {
870-
BeginMessage(pszCommand);
871-
ssSend << a1 << a2 << a3 << a4;
872-
EndMessage(pszCommand);
873-
} catch (...) {
874-
AbortMessage();
875-
throw;
876-
}
877-
}
878-
879-
template <typename T1, typename T2, typename T3, typename T4, typename T5>
880-
void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5)
881-
{
882-
try {
883-
BeginMessage(pszCommand);
884-
ssSend << a1 << a2 << a3 << a4 << a5;
885-
EndMessage(pszCommand);
886-
} catch (...) {
887-
AbortMessage();
888-
throw;
889-
}
890-
}
891-
892-
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
893-
void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6)
894-
{
895-
try {
896-
BeginMessage(pszCommand);
897-
ssSend << a1 << a2 << a3 << a4 << a5 << a6;
898-
EndMessage(pszCommand);
899-
} catch (...) {
900-
AbortMessage();
901-
throw;
902-
}
903-
}
904-
905-
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
906-
void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6, const T7& a7)
907-
{
908-
try {
909-
BeginMessage(pszCommand);
910-
ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7;
911-
EndMessage(pszCommand);
912-
} catch (...) {
913-
AbortMessage();
914-
throw;
915-
}
916-
}
917-
918-
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
919-
void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6, const T7& a7, const T8& a8)
920-
{
921-
try {
922-
BeginMessage(pszCommand);
923-
ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8;
924-
EndMessage(pszCommand);
925-
} catch (...) {
926-
AbortMessage();
927-
throw;
928-
}
929-
}
930-
931-
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
932-
void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6, const T7& a7, const T8& a8, const T9& a9)
933-
{
934-
try {
935-
BeginMessage(pszCommand);
936-
ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9;
937-
EndMessage(pszCommand);
938-
} catch (...) {
939-
AbortMessage();
940-
throw;
941-
}
942-
}
943-
944-
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
945-
void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6, const T7& a7, const T8& a8, const T9& a9, const T10& a10)
946-
{
947-
try {
948-
BeginMessage(pszCommand);
949-
ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9 << a10;
950-
EndMessage(pszCommand);
951-
} catch (...) {
952-
AbortMessage();
953-
throw;
954-
}
955-
}
956-
957-
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11>
958-
void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6, const T7& a7, const T8& a8, const T9& a9, const T10& a10, const T11& a11)
959-
{
960-
try {
961-
BeginMessage(pszCommand);
962-
ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9 << a10 << a11;
963-
EndMessage(pszCommand);
964-
} catch (...) {
965-
AbortMessage();
966-
throw;
967-
}
968-
}
969-
970-
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12>
971-
void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6, const T7& a7, const T8& a8, const T9& a9, const T10& a10, const T11& a11, const T12& a12)
972-
{
973-
try {
974-
BeginMessage(pszCommand);
975-
ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9 << a10 << a11 << a12;
976-
EndMessage(pszCommand);
977-
} catch (...) {
978-
AbortMessage();
979-
throw;
980-
}
981-
}
982-
983807
bool HasFulfilledRequest(std::string strRequest)
984808
{
985809
for (std::string& type : vecRequestsFulfilled) {

src/spork.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void CSporkManager::ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStr
153153
std::map<SporkId, CSporkMessage>::iterator it = mapSporksActive.begin();
154154

155155
while (it != mapSporksActive.end()) {
156-
pfrom->PushMessage(NetMsgType::SPORK, it->second);
156+
g_connman->PushMessage(pfrom, NetMsgType::SPORK, it->second);
157157
it++;
158158
}
159159
}

0 commit comments

Comments
 (0)