diff options
| author | Ross Nicoll <[email protected]> | 2018-04-22 17:19:03 +0100 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2018-09-19 22:11:47 +0100 |
| commit | 41c868f47e671dc5009cd47496c39c13ae36306b (patch) | |
| tree | e48b4f07bce4ff5aac8369551032dc46c46a8bf1 /src/alert.h | |
| parent | Update or eliminate remaining tests (#1483) (diff) | |
| download | discoin-41c868f47e671dc5009cd47496c39c13ae36306b.tar.xz discoin-41c868f47e671dc5009cd47496c39c13ae36306b.zip | |
Re-introduce alert functionality (#1470)
Re-introduce alert functionality removed from Bitcoin upstream
Diffstat (limited to 'src/alert.h')
| -rw-r--r-- | src/alert.h | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/alert.h b/src/alert.h new file mode 100644 index 000000000..7963fac11 --- /dev/null +++ b/src/alert.h @@ -0,0 +1,112 @@ +// Copyright (c) 2010 Satoshi Nakamoto +// Copyright (c) 2009-2015 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_ALERT_H +#define BITCOIN_ALERT_H + +#include "serialize.h" +#include "sync.h" + +#include <map> +#include <set> +#include <stdint.h> +#include <string> + +class CAlert; +class CNode; +class uint256; + +extern std::map<uint256, CAlert> mapAlerts; +extern CCriticalSection cs_mapAlerts; + +/** Alerts are for notifying old versions if they become too obsolete and + * need to upgrade. The message is displayed in the status bar. + * Alert messages are broadcast as a vector of signed data. Unserializing may + * not read the entire buffer if the alert is for a newer version, but older + * versions can still relay the original data. + */ +class CUnsignedAlert +{ +public: + int nVersion; + int64_t nRelayUntil; // when newer nodes stop relaying to newer nodes + int64_t nExpiration; + int nID; + int nCancel; + std::set<int> setCancel; + int nMinVer; // lowest version inclusive + int nMaxVer; // highest version inclusive + std::set<std::string> setSubVer; // empty matches all + int nPriority; + + // Actions + std::string strComment; + std::string strStatusBar; + std::string strReserved; + + ADD_SERIALIZE_METHODS; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action) { + 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(); + + std::string ToString() const; +}; + +/** An alert is a combination of a serialized CUnsignedAlert and a signature. */ +class CAlert : public CUnsignedAlert +{ +public: + std::vector<unsigned char> vchMsg; + std::vector<unsigned char> vchSig; + + CAlert() + { + SetNull(); + } + + ADD_SERIALIZE_METHODS; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action) { + READWRITE(vchMsg); + READWRITE(vchSig); + } + + void SetNull(); + bool IsNull() const; + uint256 GetHash() const; + bool IsInEffect() const; + bool Cancels(const CAlert& alert) const; + bool AppliesTo(int nVersion, const std::string& strSubVerIn) const; + bool AppliesToMe() const; + bool CheckSignature(const std::vector<unsigned char>& alertKey) const; + bool ProcessAlert(const std::vector<unsigned char>& alertKey, bool fThread = true); + static void Notify(const std::string& strMessage, bool fThread = true); + + /* + * Get copy of (active) alert object by hash. Returns a null alert if it is not found. + */ + static CAlert getAlertByHash(const uint256 &hash); +}; + +#endif // BITCOIN_ALERT_H |