mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 13:32:47 +01:00
753b1e486b
This monstrous change eliminates all remaining uses of g_connman global variable in Dash-specific code. Unlike previous changes eliminating g_connman use that were isolated to particular modules, this one covers multiple modules simultaneously because they are so interdependent that change in one module was quickly spreading to others. This is mostly invariant change that was done by * changing all functions using g_connman to use connman argument, * changing all functions calling these functions to use connman argument, * repeating previous step until there's nothing to change. After multiple iterations, this process converged to final result, producing code that is mostly equivalent to original one, but passing CConnman instance through arguments instead of global variable. The only exception to equivalence of resulting code is that I had to create overload of CMasternodeMan::CheckAndRemove() method without arguments that does nothing just for use in CFlatDB<CMasternodeMan>::Dump() and CFlatDB<CMasternodeMan>::Load() methods. Normal CMasternodeMan::CheckAndRemove() overload now has argument of CConnman& type and is used everywhere else. The normal overload has this code in the beginning: if(!masternodeSync.IsMasternodeListSynced()) return; Masternode list is not synced yet when we load "mncache.dat" file, and we save "mncache.dat" file on shutdown, so I presume that it's OK to use overload that does nothing in both cases. Signed-off-by: Oleg Girko <ol@infoserver.lv>
86 lines
2.1 KiB
C++
86 lines
2.1 KiB
C++
// Copyright (c) 2014-2017 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 ACTIVEMASTERNODE_H
|
|
#define ACTIVEMASTERNODE_H
|
|
|
|
#include "net.h"
|
|
#include "key.h"
|
|
#include "wallet/wallet.h"
|
|
|
|
class CActiveMasternode;
|
|
|
|
static const int ACTIVE_MASTERNODE_INITIAL = 0; // initial state
|
|
static const int ACTIVE_MASTERNODE_SYNC_IN_PROCESS = 1;
|
|
static const int ACTIVE_MASTERNODE_INPUT_TOO_NEW = 2;
|
|
static const int ACTIVE_MASTERNODE_NOT_CAPABLE = 3;
|
|
static const int ACTIVE_MASTERNODE_STARTED = 4;
|
|
|
|
extern CActiveMasternode activeMasternode;
|
|
|
|
// Responsible for activating the Masternode and pinging the network
|
|
class CActiveMasternode
|
|
{
|
|
public:
|
|
enum masternode_type_enum_t {
|
|
MASTERNODE_UNKNOWN = 0,
|
|
MASTERNODE_REMOTE = 1,
|
|
MASTERNODE_LOCAL = 2
|
|
};
|
|
|
|
private:
|
|
// critical section to protect the inner data structures
|
|
mutable CCriticalSection cs;
|
|
|
|
masternode_type_enum_t eType;
|
|
|
|
bool fPingerEnabled;
|
|
|
|
/// Ping Masternode
|
|
bool SendMasternodePing(CConnman& connman);
|
|
|
|
// sentinel ping data
|
|
int64_t nSentinelPingTime;
|
|
uint32_t nSentinelVersion;
|
|
|
|
public:
|
|
// Keys for the active Masternode
|
|
CPubKey pubKeyMasternode;
|
|
CKey keyMasternode;
|
|
|
|
// Initialized while registering Masternode
|
|
COutPoint outpoint;
|
|
CService service;
|
|
|
|
int nState; // should be one of ACTIVE_MASTERNODE_XXXX
|
|
std::string strNotCapableReason;
|
|
|
|
|
|
CActiveMasternode()
|
|
: eType(MASTERNODE_UNKNOWN),
|
|
fPingerEnabled(false),
|
|
pubKeyMasternode(),
|
|
keyMasternode(),
|
|
outpoint(),
|
|
service(),
|
|
nState(ACTIVE_MASTERNODE_INITIAL)
|
|
{}
|
|
|
|
/// Manage state of active Masternode
|
|
void ManageState(CConnman& connman);
|
|
|
|
std::string GetStateString() const;
|
|
std::string GetStatus() const;
|
|
std::string GetTypeString() const;
|
|
|
|
bool UpdateSentinelPing(int version);
|
|
|
|
private:
|
|
void ManageStateInitial(CConnman& connman);
|
|
void ManageStateRemote();
|
|
void ManageStateLocal(CConnman& connman);
|
|
};
|
|
|
|
#endif
|