Skip to content

Commit

Permalink
Eliminate g_connman use in spork module. (#1613)
Browse files Browse the repository at this point in the history
Pass reference to CConnman instance to methods of CSporkManager and
CSporkMessage instead of using g_connman global variable.

Signed-off-by: Oleg Girko <[email protected]>
  • Loading branch information
OlegGirko authored and UdjinM6 committed Sep 7, 2017
1 parent 91ae0b7 commit 8da26da
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
mnodeman.ProcessMessage(pfrom, strCommand, vRecv);
mnpayments.ProcessMessage(pfrom, strCommand, vRecv);
instantsend.ProcessMessage(pfrom, strCommand, vRecv);
sporkManager.ProcessSpork(pfrom, strCommand, vRecv);
sporkManager.ProcessSpork(pfrom, strCommand, vRecv, connman);
masternodeSync.ProcessMessage(pfrom, strCommand, vRecv);
governance.ProcessMessage(pfrom, strCommand, vRecv);
}
Expand Down
5 changes: 4 additions & 1 deletion src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,14 @@ UniValue spork(const UniValue& params, bool fHelp)
return "Invalid spork name";
}

if (!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");

// SPORK VALUE
int64_t nValue = params[1].get_int64();

//broadcast new spork
if(sporkManager.UpdateSpork(nSporkID, nValue)){
if(sporkManager.UpdateSpork(nSporkID, nValue, *g_connman)){
sporkManager.ExecuteSpork(nSporkID, nValue);
return "success";
} else {
Expand Down
14 changes: 7 additions & 7 deletions src/spork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CSporkManager sporkManager;

std::map<uint256, CSporkMessage> mapSporks;

void CSporkManager::ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
void CSporkManager::ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv, CConnman& connman)
{
if(fLiteMode) return; // disable all Dash specific functionality

Expand Down Expand Up @@ -55,7 +55,7 @@ void CSporkManager::ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStr

mapSporks[hash] = spork;
mapSporksActive[spork.nSporkID] = spork;
spork.Relay();
spork.Relay(connman);

//does a task if needed
ExecuteSpork(spork.nSporkID, spork.nValue);
Expand All @@ -65,7 +65,7 @@ void CSporkManager::ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStr
std::map<int, CSporkMessage>::iterator it = mapSporksActive.begin();

while(it != mapSporksActive.end()) {
g_connman->PushMessage(pfrom, NetMsgType::SPORK, it->second);
connman.PushMessage(pfrom, NetMsgType::SPORK, it->second);
it++;
}
}
Expand Down Expand Up @@ -101,13 +101,13 @@ void CSporkManager::ExecuteSpork(int nSporkID, int nValue)
}
}

bool CSporkManager::UpdateSpork(int nSporkID, int64_t nValue)
bool CSporkManager::UpdateSpork(int nSporkID, int64_t nValue, CConnman& connman)
{

CSporkMessage spork = CSporkMessage(nSporkID, nValue, GetAdjustedTime());

if(spork.Sign(strMasterPrivKey)) {
spork.Relay();
spork.Relay(connman);
mapSporks[spork.GetHash()] = spork;
mapSporksActive[nSporkID] = spork;
return true;
Expand Down Expand Up @@ -257,8 +257,8 @@ bool CSporkMessage::CheckSignature()
return true;
}

void CSporkMessage::Relay()
void CSporkMessage::Relay(CConnman& connman)
{
CInv inv(MSG_SPORK, GetHash());
g_connman->RelayInv(inv);
connman.RelayInv(inv);
}
6 changes: 3 additions & 3 deletions src/spork.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CSporkMessage

bool Sign(std::string strSignKey);
bool CheckSignature();
void Relay();
void Relay(CConnman& connman);
};


Expand All @@ -106,9 +106,9 @@ class CSporkManager

CSporkManager() {}

void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv, CConnman& connman);
void ExecuteSpork(int nSporkID, int nValue);
bool UpdateSpork(int nSporkID, int64_t nValue);
bool UpdateSpork(int nSporkID, int64_t nValue, CConnman& connman);

bool IsSporkActive(int nSporkID);
int64_t GetSporkValue(int nSporkID);
Expand Down

0 comments on commit 8da26da

Please sign in to comment.