You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

alert.h 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #ifndef _BITCOINALERT_H_
  6. #define _BITCOINALERT_H_ 1
  7. #include "serialize.h"
  8. #include "sync.h"
  9. #include <map>
  10. #include <set>
  11. #include <stdint.h>
  12. #include <string>
  13. class CAlert;
  14. class CNode;
  15. class uint256;
  16. extern std::map<uint256, CAlert> mapAlerts;
  17. extern CCriticalSection cs_mapAlerts;
  18. /** Alerts are for notifying old versions if they become too obsolete and
  19. * need to upgrade. The message is displayed in the status bar.
  20. * Alert messages are broadcast as a vector of signed data. Unserializing may
  21. * not read the entire buffer if the alert is for a newer version, but older
  22. * versions can still relay the original data.
  23. */
  24. class CUnsignedAlert
  25. {
  26. public:
  27. int nVersion;
  28. int64_t nRelayUntil; // when newer nodes stop relaying to newer nodes
  29. int64_t nExpiration;
  30. int nID;
  31. int nCancel;
  32. std::set<int> setCancel;
  33. int nMinVer; // lowest version inclusive
  34. int nMaxVer; // highest version inclusive
  35. std::set<std::string> setSubVer; // empty matches all
  36. int nPriority;
  37. // Actions
  38. std::string strComment;
  39. std::string strStatusBar;
  40. std::string strReserved;
  41. IMPLEMENT_SERIALIZE
  42. (
  43. READWRITE(this->nVersion);
  44. nVersion = this->nVersion;
  45. READWRITE(nRelayUntil);
  46. READWRITE(nExpiration);
  47. READWRITE(nID);
  48. READWRITE(nCancel);
  49. READWRITE(setCancel);
  50. READWRITE(nMinVer);
  51. READWRITE(nMaxVer);
  52. READWRITE(setSubVer);
  53. READWRITE(nPriority);
  54. READWRITE(strComment);
  55. READWRITE(strStatusBar);
  56. READWRITE(strReserved);
  57. )
  58. void SetNull();
  59. std::string ToString() const;
  60. void print() const;
  61. };
  62. /** An alert is a combination of a serialized CUnsignedAlert and a signature. */
  63. class CAlert : public CUnsignedAlert
  64. {
  65. public:
  66. std::vector<unsigned char> vchMsg;
  67. std::vector<unsigned char> vchSig;
  68. CAlert()
  69. {
  70. SetNull();
  71. }
  72. IMPLEMENT_SERIALIZE
  73. (
  74. READWRITE(vchMsg);
  75. READWRITE(vchSig);
  76. )
  77. void SetNull();
  78. bool IsNull() const;
  79. uint256 GetHash() const;
  80. bool IsInEffect() const;
  81. bool Cancels(const CAlert& alert) const;
  82. bool AppliesTo(int nVersion, std::string strSubVerIn) const;
  83. bool AppliesToMe() const;
  84. bool RelayTo(CNode* pnode) const;
  85. bool CheckSignature() const;
  86. bool ProcessAlert(bool fThread = true);
  87. /*
  88. * Get copy of (active) alert object by hash. Returns a null alert if it is not found.
  89. */
  90. static CAlert getAlertByHash(const uint256 &hash);
  91. };
  92. #endif