]>
Commit | Line | Data |
---|---|---|
f35c6c4f | 1 | // Copyright (c) 2010 Satoshi Nakamoto |
f914f1a7 | 2 | // Copyright (c) 2009-2013 The Bitcoin Core developers |
78253fcb | 3 | // Distributed under the MIT software license, see the accompanying |
f35c6c4f GA |
4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | ||
84738627 PJ |
6 | #ifndef BITCOIN_ALERT_H |
7 | #define BITCOIN_ALERT_H | |
f35c6c4f | 8 | |
51ed9ec9 BD |
9 | #include "serialize.h" |
10 | #include "sync.h" | |
11 | ||
12 | #include <map> | |
f35c6c4f | 13 | #include <set> |
51ed9ec9 | 14 | #include <stdint.h> |
f35c6c4f GA |
15 | #include <string> |
16 | ||
51ed9ec9 | 17 | class CAlert; |
f35c6c4f | 18 | class CNode; |
51ed9ec9 BD |
19 | class uint256; |
20 | ||
21 | extern std::map<uint256, CAlert> mapAlerts; | |
22 | extern CCriticalSection cs_mapAlerts; | |
f35c6c4f GA |
23 | |
24 | /** Alerts are for notifying old versions if they become too obsolete and | |
25 | * need to upgrade. The message is displayed in the status bar. | |
26 | * Alert messages are broadcast as a vector of signed data. Unserializing may | |
27 | * not read the entire buffer if the alert is for a newer version, but older | |
28 | * versions can still relay the original data. | |
29 | */ | |
30 | class CUnsignedAlert | |
31 | { | |
32 | public: | |
33 | int nVersion; | |
51ed9ec9 BD |
34 | int64_t nRelayUntil; // when newer nodes stop relaying to newer nodes |
35 | int64_t nExpiration; | |
f35c6c4f GA |
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 | ||
3f6540ad | 49 | ADD_SERIALIZE_METHODS; |
3d796f89 | 50 | |
84881f8c | 51 | template <typename Stream, typename Operation> |
31e9a838 | 52 | inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { |
f35c6c4f GA |
53 | READWRITE(this->nVersion); |
54 | nVersion = this->nVersion; | |
55 | READWRITE(nRelayUntil); | |
56 | READWRITE(nExpiration); | |
57 | READWRITE(nID); | |
58 | READWRITE(nCancel); | |
59 | READWRITE(setCancel); | |
60 | READWRITE(nMinVer); | |
61 | READWRITE(nMaxVer); | |
62 | READWRITE(setSubVer); | |
63 | READWRITE(nPriority); | |
64 | ||
216e9a44 PW |
65 | READWRITE(LIMITED_STRING(strComment, 65536)); |
66 | READWRITE(LIMITED_STRING(strStatusBar, 256)); | |
67 | READWRITE(LIMITED_STRING(strReserved, 256)); | |
3d796f89 | 68 | } |
f35c6c4f GA |
69 | |
70 | void SetNull(); | |
71 | ||
72 | std::string ToString() const; | |
f35c6c4f GA |
73 | }; |
74 | ||
75 | /** An alert is a combination of a serialized CUnsignedAlert and a signature. */ | |
76 | class CAlert : public CUnsignedAlert | |
77 | { | |
78 | public: | |
79 | std::vector<unsigned char> vchMsg; | |
80 | std::vector<unsigned char> vchSig; | |
81 | ||
82 | CAlert() | |
83 | { | |
84 | SetNull(); | |
85 | } | |
86 | ||
3f6540ad | 87 | ADD_SERIALIZE_METHODS; |
3d796f89 | 88 | |
84881f8c | 89 | template <typename Stream, typename Operation> |
31e9a838 | 90 | inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { |
f35c6c4f GA |
91 | READWRITE(vchMsg); |
92 | READWRITE(vchSig); | |
3d796f89 | 93 | } |
f35c6c4f GA |
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, std::string strSubVerIn) const; | |
101 | bool AppliesToMe() const; | |
102 | bool RelayTo(CNode* pnode) const; | |
103 | bool CheckSignature() const; | |
e01a7939 GA |
104 | bool ProcessAlert(bool fThread = true); // fThread means run -alertnotify in a free-running thread |
105 | static void Notify(const std::string& strMessage, bool fThread); | |
f35c6c4f GA |
106 | |
107 | /* | |
108 | * Get copy of (active) alert object by hash. Returns a null alert if it is not found. | |
109 | */ | |
110 | static CAlert getAlertByHash(const uint256 &hash); | |
111 | }; | |
112 | ||
84738627 | 113 | #endif // BITCOIN_ALERT_H |