Anoncoin  0.9.4
P2P Digital Currency
alert.h
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 The Bitcoin developers
3 // Copyright (c) 2013-2014 The Anoncoin Core developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef _ANONCOINALERT_H_
8 #define _ANONCOINALERT_H_ 1
9 
10 #include "serialize.h"
11 #include "sync.h"
12 
13 #include <map>
14 #include <set>
15 #include <stdint.h>
16 #include <string>
17 
18 class CAlert;
19 class CNode;
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  READWRITE(this->nVersion);
53  nVersion = this->nVersion;
54  READWRITE(nRelayUntil);
55  READWRITE(nExpiration);
56  READWRITE(nID);
57  READWRITE(nCancel);
58  READWRITE(setCancel);
59  READWRITE(nMinVer);
60  READWRITE(nMaxVer);
61  READWRITE(setSubVer);
62  READWRITE(nPriority);
63 
64  READWRITE(LIMITED_STRING(strComment, 65536));
65  READWRITE(LIMITED_STRING(strStatusBar, 256));
66  READWRITE(LIMITED_STRING(strReserved, 256));
67  )
68 
69  void SetNull();
70 
71  std::string ToString() const;
72  void print() 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  READWRITE(vchMsg);
90  READWRITE(vchSig);
91  )
92 
93  void SetNull();
94  bool IsNull() const;
95  uint256 GetHash() const;
96  bool IsInEffect() const;
97  bool Cancels(const CAlert& alert) const;
98  bool AppliesTo(int nVersion, std::string strSubVerIn) const;
99  bool AppliesToMe() const;
100  bool RelayTo(CNode* pnode) const;
101  bool CheckSignature() const;
102  bool ProcessAlert(bool fThread = true);
103 
104  /*
105  * Get copy of (active) alert object by hash. Returns a null alert if it is not found.
106  */
107  static CAlert getAlertByHash(const uint256 &hash);
108 };
109 
110 #endif
std::set< std::string > setSubVer
Definition: alert.h:42
std::string strReserved
Definition: alert.h:48
std::map< uint256, CAlert > mapAlerts
Definition: alert.cpp:25
#define READWRITE(obj)
Definition: serialize.h:101
std::vector< unsigned char > vchMsg
Definition: alert.h:79
bool AppliesTo(int nVersion, std::string strSubVerIn) const
Definition: alert.cpp:117
bool ProcessAlert(bool fThread=true)
Definition: alert.cpp:172
int nVersion
Definition: alert.h:34
IMPLEMENT_SERIALIZE(READWRITE(vchMsg);READWRITE(vchSig);) void SetNull()
std::string strStatusBar
Definition: alert.h:47
bool IsInEffect() const
Definition: alert.cpp:105
void print() const
Definition: alert.cpp:83
bool IsNull() const
Definition: alert.cpp:95
An alert is a combination of a serialized CUnsignedAlert and a signature.
Definition: alert.h:76
uint256 GetHash() const
Definition: alert.cpp:100
std::string ToString() const
Definition: alert.cpp:46
Alerts are for notifying old versions if they become too obsolete and need to upgrade.
Definition: alert.h:31
int nMaxVer
Definition: alert.h:41
int64_t nExpiration
Definition: alert.h:36
std::vector< unsigned char > vchSig
Definition: alert.h:80
int64_t nRelayUntil
Definition: alert.h:35
256-bit unsigned integer
Definition: uint256.h:532
CAlert()
Definition: alert.h:82
bool RelayTo(CNode *pnode) const
Definition: alert.cpp:130
std::set< int > setCancel
Definition: alert.h:39
CCriticalSection cs_mapAlerts
Definition: alert.cpp:26
static CAlert getAlertByHash(const uint256 &hash)
Definition: alert.cpp:160
int nMinVer
Definition: alert.h:40
#define LIMITED_STRING(obj, n)
Definition: serialize.h:320
bool CheckSignature() const
Definition: alert.cpp:148
std::string strComment
Definition: alert.h:46
bool Cancels(const CAlert &alert) const
Definition: alert.cpp:110
int nCancel
Definition: alert.h:38
Information about a peer.
Definition: net.h:223
bool AppliesToMe() const
Definition: alert.cpp:125
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:43