dash/src/masternodeman.h
crowning- 072fd72ca3 Merge #930: [UI] IPv4, IPv6 and TOR stats added to Information tab
d07ca0c [UI] IPV4, IPv6 and TOR stats added to Information tab

aaa320e [UI] IPv4, IPv6 and TOR stats added to Information tab
2016-08-06 22:52:01 +02:00

136 lines
4.3 KiB
C++

// Copyright (c) 2014-2016 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef MASTERNODEMAN_H
#define MASTERNODEMAN_H
#include "sync.h"
#include "net.h"
#include "key.h"
#include "util.h"
#include "base58.h"
#include "main.h"
#include "masternode.h"
#define MASTERNODES_DUMP_SECONDS (15*60)
#define MASTERNODES_DSEG_SECONDS (3*60*60)
using namespace std;
class CMasternodeMan;
extern CMasternodeMan mnodeman;
class CMasternodeMan
{
private:
// critical section to protect the inner data structures
mutable CCriticalSection cs;
// critical section to protect the inner data structures specifically on messaging
mutable CCriticalSection cs_process_message;
// map to hold all MNs
std::vector<CMasternode> vMasternodes;
// who's asked for the Masternode list and the last time
std::map<CNetAddr, int64_t> mAskedUsForMasternodeList;
// who we asked for the Masternode list and the last time
std::map<CNetAddr, int64_t> mWeAskedForMasternodeList;
// which Masternodes we've asked for
std::map<COutPoint, int64_t> mWeAskedForMasternodeListEntry;
public:
// Keep track of all broadcasts I've seen
map<uint256, CMasternodeBroadcast> mapSeenMasternodeBroadcast;
// Keep track of all pings I've seen
map<uint256, CMasternodePing> mapSeenMasternodePing;
// keep track of dsq count to prevent masternodes from gaming darksend queue
int64_t nDsqCount;
// dummy script pubkey to test masternodes' vins against mempool
CScript dummyScriptPubkey;
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
LOCK(cs);
READWRITE(vMasternodes);
READWRITE(mAskedUsForMasternodeList);
READWRITE(mWeAskedForMasternodeList);
READWRITE(mWeAskedForMasternodeListEntry);
READWRITE(nDsqCount);
READWRITE(mapSeenMasternodeBroadcast);
READWRITE(mapSeenMasternodePing);
}
CMasternodeMan();
CMasternodeMan(CMasternodeMan& other);
/// Add an entry
bool Add(CMasternode &mn);
/// Ask (source) node for mnb
void AskForMN(CNode *pnode, CTxIn &vin);
/// Check all Masternodes
void Check();
/// Check all Masternodes and remove inactive
void CheckAndRemove(bool forceExpiredRemoval = false);
/// Clear Masternode vector
void Clear();
int CountEnabled(int protocolVersion = -1);
int CountByIP(int nodeType);
void DsegUpdate(CNode* pnode);
/// Find an entry
CMasternode* Find(const CScript &payee);
CMasternode* Find(const CTxIn& vin);
CMasternode* Find(const CPubKey& pubKeyMasternode);
/// Find an entry in the masternode list that is next to be paid
CMasternode* GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCount);
/// Find a random entry
CMasternode* FindRandomNotInVec(std::vector<CTxIn> &vecToExclude, int nProtocolVersion = -1);
/// Get the current winner for this block
CMasternode* GetCurrentMasterNode(int mod=1, int64_t nBlockHeight=0, int minProtocol=0);
std::vector<CMasternode> GetFullMasternodeVector() { Check(); return vMasternodes; }
std::vector<pair<int, CMasternode> > GetMasternodeRanks(int64_t nBlockHeight, int minProtocol=0);
int GetMasternodeRank(const CTxIn &vin, int64_t nBlockHeight, int minProtocol=0, bool fOnlyActive=true);
CMasternode* GetMasternodeByRank(int nRank, int64_t nBlockHeight, int minProtocol=0, bool fOnlyActive=true);
void InitDummyScriptPubkey();
void ProcessMasternodeConnections();
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
/// Return the number of (unique) Masternodes
int size() { return vMasternodes.size(); }
std::string ToString() const;
void Remove(CTxIn vin);
int GetEstimatedMasternodes(int nBlock);
/// Update masternode list and maps using provided CMasternodeBroadcast
void UpdateMasternodeList(CMasternodeBroadcast mnb);
/// Perform complete check and only then update list and maps
bool CheckMnbAndUpdateMasternodeList(CMasternodeBroadcast mnb, int& nDos);
};
#endif