Master Core  v0.0.9 - 49a5c0d97abf09ef2911ddfe8d9551df59f9efd3-dirty
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
alert.h
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef _BITCOINALERT_H_
7 #define _BITCOINALERT_H_ 1
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  READWRITE(this->nVersion);
52  nVersion = this->nVersion;
53  READWRITE(nRelayUntil);
54  READWRITE(nExpiration);
55  READWRITE(nID);
56  READWRITE(nCancel);
57  READWRITE(setCancel);
58  READWRITE(nMinVer);
59  READWRITE(nMaxVer);
60  READWRITE(setSubVer);
61  READWRITE(nPriority);
62 
63  READWRITE(LIMITED_STRING(strComment, 65536));
64  READWRITE(LIMITED_STRING(strStatusBar, 256));
65  READWRITE(LIMITED_STRING(strReserved, 256));
66  )
67 
68  void SetNull();
69 
70  std::string ToString() const;
71  void print() const;
72 };
73 
75 class CAlert : public CUnsignedAlert
76 {
77 public:
78  std::vector<unsigned char> vchMsg;
79  std::vector<unsigned char> vchSig;
80 
82  {
83  SetNull();
84  }
85 
87  (
88  READWRITE(vchMsg);
89  READWRITE(vchSig);
90  )
91 
92  void SetNull();
93  bool IsNull() const;
94  uint256 GetHash() const;
95  bool IsInEffect() const;
96  bool Cancels(const CAlert& alert) const;
97  bool AppliesTo(int nVersion, std::string strSubVerIn) const;
98  bool AppliesToMe() const;
99  bool RelayTo(CNode* pnode) const;
100  bool CheckSignature() const;
101  bool ProcessAlert(bool fThread = true);
102 
103  /*
104  * Get copy of (active) alert object by hash. Returns a null alert if it is not found.
105  */
106  static CAlert getAlertByHash(const uint256 &hash);
107 };
108 
109 #endif
std::set< std::string > setSubVer
Definition: alert.h:41
std::string strReserved
Definition: alert.h:47
std::map< uint256, CAlert > mapAlerts
Definition: alert.cpp:23
#define READWRITE(obj)
Definition: serialize.h:92
std::vector< unsigned char > vchMsg
Definition: alert.h:78
bool AppliesTo(int nVersion, std::string strSubVerIn) const
Definition: alert.cpp:115
bool ProcessAlert(bool fThread=true)
Definition: alert.cpp:170
int nVersion
Definition: alert.h:33
IMPLEMENT_SERIALIZE(READWRITE(vchMsg);READWRITE(vchSig);) void SetNull()
std::string strStatusBar
Definition: alert.h:46
bool IsInEffect() const
Definition: alert.cpp:103
void print() const
Definition: alert.cpp:81
bool IsNull() const
Definition: alert.cpp:93
An alert is a combination of a serialized CUnsignedAlert and a signature.
Definition: alert.h:75
uint256 GetHash() const
Definition: alert.cpp:98
std::string ToString() const
Definition: alert.cpp:44
Alerts are for notifying old versions if they become too obsolete and need to upgrade.
Definition: alert.h:30
int nMaxVer
Definition: alert.h:40
int64_t nExpiration
Definition: alert.h:35
std::vector< unsigned char > vchSig
Definition: alert.h:79
int64_t nRelayUntil
Definition: alert.h:34
256-bit unsigned integer
Definition: uint256.h:531
CAlert()
Definition: alert.h:81
bool RelayTo(CNode *pnode) const
Definition: alert.cpp:128
std::set< int > setCancel
Definition: alert.h:38
CCriticalSection cs_mapAlerts
Definition: alert.cpp:24
static CAlert getAlertByHash(const uint256 &hash)
Definition: alert.cpp:158
int nMinVer
Definition: alert.h:39
#define LIMITED_STRING(obj, n)
Definition: serialize.h:311
bool CheckSignature() const
Definition: alert.cpp:146
std::string strComment
Definition: alert.h:45
bool Cancels(const CAlert &alert) const
Definition: alert.cpp:108
int nCancel
Definition: alert.h:37
Information about a peer.
Definition: net.h:193
bool AppliesToMe() const
Definition: alert.cpp:123
IMPLEMENT_SERIALIZE(READWRITE(this->nVersion);nVersion=this->nVersion;READWRITE(nRelayUntil);READWRITE(nExpiration);READWRITE(nID);READWRITE(nCancel);READWRITE(setCancel);READWRITE(nMinVer);READWRITE(nMaxVer);READWRITE(setSubVer);READWRITE(nPriority);READWRITE(LIMITED_STRING(strComment, 65536));READWRITE(LIMITED_STRING(strStatusBar, 256));READWRITE(LIMITED_STRING(strReserved, 256));) void SetNull()
int nPriority
Definition: alert.h:42