Dogecoin Core  1.14.2
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 uint256;
20 
21 extern std::map<uint256, CAlert> mapAlerts;
23 
31 {
32 public:
33  int nVersion;
34  int64_t nRelayUntil; // when newer nodes stop relaying to newer nodes
35  int64_t nExpiration;
36  int nID;
37  int nCancel;
38  std::set<int> setCancel;
39  int nMinVer; // lowest version inclusive
40  int nMaxVer; // highest version inclusive
41  std::set<std::string> setSubVer; // empty matches all
42  int nPriority;
43 
44  // Actions
45  std::string strComment;
46  std::string strStatusBar;
47  std::string strReserved;
48 
50 
51  template <typename Stream, typename Operation>
52  inline void SerializationOp(Stream& s, Operation ser_action) {
53  READWRITE(this->nVersion);
54  nVersion = this->nVersion;
55  READWRITE(nRelayUntil);
57  READWRITE(nID);
64 
68  }
69 
70  void SetNull();
71 
72  std::string ToString() const;
73 };
74 
76 class CAlert : public CUnsignedAlert
77 {
78 public:
79  std::vector<unsigned char> vchMsg;
80  std::vector<unsigned char> vchSig;
81 
83  {
84  SetNull();
85  }
86 
88 
89  template <typename Stream, typename Operation>
90  inline void SerializationOp(Stream& s, Operation ser_action) {
93  }
94 
95  void SetNull();
96  bool IsNull() const;
97  uint256 GetHash() const;
98  bool IsInEffect() const;
99  bool Cancels(const CAlert& alert) const;
100  bool AppliesTo(int nVersion, const std::string& strSubVerIn) const;
101  bool AppliesToMe() const;
102  bool CheckSignature(const std::vector<unsigned char>& alertKey) const;
103  bool ProcessAlert(const std::vector<unsigned char>& alertKey, bool fThread = true);
104  static void Notify(const std::string& strMessage, bool fThread = true);
105 
106  /*
107  * Get copy of (active) alert object by hash. Returns a null alert if it is not found.
108  */
109  static CAlert getAlertByHash(const uint256 &hash);
110 };
111 
112 #endif // BITCOIN_ALERT_H
CCriticalSection cs_mapAlerts
Definition: alert.cpp:29
std::map< uint256, CAlert > mapAlerts
Definition: alert.cpp:28
An alert is a combination of a serialized CUnsignedAlert and a signature.
Definition: alert.h:77
bool IsInEffect() const
Definition: alert.cpp:103
uint256 GetHash() const
Definition: alert.cpp:98
bool CheckSignature(const std::vector< unsigned char > &alertKey) const
Definition: alert.cpp:128
CAlert()
Definition: alert.h:82
std::vector< unsigned char > vchSig
Definition: alert.h:80
bool Cancels(const CAlert &alert) const
Definition: alert.cpp:108
void SetNull()
Definition: alert.cpp:86
void SerializationOp(Stream &s, Operation ser_action)
Definition: alert.h:90
bool IsNull() const
Definition: alert.cpp:93
bool AppliesTo(int nVersion, const std::string &strSubVerIn) const
Definition: alert.cpp:115
static CAlert getAlertByHash(const uint256 &hash)
Definition: alert.cpp:140
static void Notify(const std::string &strMessage, bool fThread=true)
Definition: alert.cpp:229
bool AppliesToMe() const
Definition: alert.cpp:123
std::vector< unsigned char > vchMsg
Definition: alert.h:79
ADD_SERIALIZE_METHODS
Definition: alert.h:87
bool ProcessAlert(const std::vector< unsigned char > &alertKey, bool fThread=true)
Definition: alert.cpp:152
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
Definition: sync.h:93
Information about a peer.
Definition: net.h:564
Alerts are for notifying old versions if they become too obsolete and need to upgrade.
Definition: alert.h:31
void SerializationOp(Stream &s, Operation ser_action)
Definition: alert.h:52
std::string strReserved
Definition: alert.h:47
int nMaxVer
Definition: alert.h:40
int64_t nRelayUntil
Definition: alert.h:34
std::set< std::string > setSubVer
Definition: alert.h:41
std::string ToString() const
Definition: alert.cpp:49
ADD_SERIALIZE_METHODS
Definition: alert.h:49
int nCancel
Definition: alert.h:37
std::string strComment
Definition: alert.h:45
std::string strStatusBar
Definition: alert.h:46
void SetNull()
Definition: alert.cpp:31
std::set< int > setCancel
Definition: alert.h:38
int nPriority
Definition: alert.h:42
int nVersion
Definition: alert.h:33
int64_t nExpiration
Definition: alert.h:35
int nMinVer
Definition: alert.h:39
256-bit opaque blob.
Definition: uint256.h:123
#define READWRITE(obj)
Definition: serialize.h:151
#define LIMITED_STRING(obj, n)
Definition: serialize.h:350