Dash Core  0.12.2.1
P2P Digital Currency
alert.h
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_ALERT_H
7 #define BITCOIN_ALERT_H
8 
9 #include "serialize.h"
10 #include "sync.h"
11 
12 #include <map>
13 #include <set>
14 #include <stdint.h>
15 #include <string>
16 
17 class CAlert;
18 class CNode;
19 class CConnman;
20 class uint256;
21 
22 extern std::map<uint256, CAlert> mapAlerts;
24 
32 {
33 public:
34  int nVersion;
35  int64_t nRelayUntil; // when newer nodes stop relaying to newer nodes
36  int64_t nExpiration;
37  int nID;
38  int nCancel;
39  std::set<int> setCancel;
40  int nMinVer; // lowest version inclusive
41  int nMaxVer; // highest version inclusive
42  std::set<std::string> setSubVer; // empty matches all
43  int nPriority;
44 
45  // Actions
46  std::string strComment;
47  std::string strStatusBar;
48  std::string strReserved;
49 
51 
52  template <typename Stream, typename Operation>
53  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
54  READWRITE(this->nVersion);
55  nVersion = this->nVersion;
56  READWRITE(nRelayUntil);
58  READWRITE(nID);
65 
69  }
70 
71  void SetNull();
72 
73  std::string ToString() const;
74 };
75 
77 class CAlert : public CUnsignedAlert
78 {
79 public:
80  std::vector<unsigned char> vchMsg;
81  std::vector<unsigned char> vchSig;
82 
84  {
85  SetNull();
86  }
87 
89 
90  template <typename Stream, typename Operation>
91  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
94  }
95 
96  void SetNull();
97  bool IsNull() const;
98  uint256 GetHash() const;
99  bool IsInEffect() const;
100  bool Cancels(const CAlert& alert) const;
101  bool AppliesTo(int nVersion, const std::string& strSubVerIn) const;
102  bool AppliesToMe() const;
103  bool RelayTo(CNode* pnode, CConnman& connman) const;
104  bool Sign();
105  bool CheckSignature(const std::vector<unsigned char>& alertKey) const;
106  bool ProcessAlert(const std::vector<unsigned char>& alertKey, bool fThread = true); // fThread means run -alertnotify in a free-running thread
107  static void Notify(const std::string& strMessage, bool fThread);
108 
109  /*
110  * Get copy of (active) alert object by hash. Returns a null alert if it is not found.
111  */
112  static CAlert getAlertByHash(const uint256 &hash);
113 };
114 
115 #endif // BITCOIN_ALERT_H
bool IsInEffect() const
Definition: alert.cpp:103
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: alert.h:91
std::map< uint256, CAlert > mapAlerts
Definition: alert.cpp:28
uint256 GetHash() const
Definition: alert.cpp:98
#define READWRITE(obj)
Definition: serialize.h:175
void SetNull()
Definition: alert.cpp:31
std::string ToString() const
Definition: alert.cpp:49
bool AppliesToMe() const
Definition: alert.cpp:123
Definition: net.h:108
std::string strReserved
Definition: alert.h:48
bool AppliesTo(int nVersion, const std::string &strSubVerIn) const
Definition: alert.cpp:115
Definition: alert.h:77
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: alert.h:53
int64_t nRelayUntil
Definition: alert.h:35
bool Sign()
Definition: alert.cpp:149
int64_t nExpiration
Definition: alert.h:36
ADD_SERIALIZE_METHODS
Definition: alert.h:50
std::vector< unsigned char > vchMsg
Definition: alert.h:80
std::string strComment
Definition: alert.h:46
Definition: net.h:661
CAlert()
Definition: alert.h:83
static CAlert getAlertByHash(const uint256 &hash)
Definition: alert.cpp:182
std::set< std::string > setSubVer
Definition: alert.h:42
int nMaxVer
Definition: alert.h:41
int nMinVer
Definition: alert.h:40
std::vector< unsigned char > vchSig
Definition: alert.h:81
void SetNull()
Definition: alert.cpp:86
int nCancel
Definition: alert.h:38
CCriticalSection cs_mapAlerts
Definition: alert.cpp:29
static void Notify(const std::string &strMessage, bool fThread)
Definition: alert.cpp:271
#define LIMITED_STRING(obj, n)
Definition: serialize.h:389
std::string strStatusBar
Definition: alert.h:47
std::set< int > setCancel
Definition: alert.h:39
ADD_SERIALIZE_METHODS
Definition: alert.h:88
bool Cancels(const CAlert &alert) const
Definition: alert.cpp:108
bool IsNull() const
Definition: alert.cpp:93
bool RelayTo(CNode *pnode, CConnman &connman) const
Definition: alert.cpp:128
bool ProcessAlert(const std::vector< unsigned char > &alertKey, bool fThread=true)
Definition: alert.cpp:194
int nVersion
Definition: alert.h:34
int nPriority
Definition: alert.h:43
bool CheckSignature(const std::vector< unsigned char > &alertKey) const
Definition: alert.cpp:170