2012-08-28 23:04:54 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2015-12-13 17:58:29 +01:00
|
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-08-28 23:04:54 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#ifndef BITCOIN_ALERT_H
|
|
|
|
#define BITCOIN_ALERT_H
|
2012-08-28 23:04:54 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "serialize.h"
|
|
|
|
#include "sync.h"
|
|
|
|
|
|
|
|
#include <map>
|
2012-08-28 23:04:54 +02:00
|
|
|
#include <set>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <stdint.h>
|
2012-08-28 23:04:54 +02:00
|
|
|
#include <string>
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
class CAlert;
|
2012-08-28 23:04:54 +02:00
|
|
|
class CNode;
|
2013-04-13 07:13:08 +02:00
|
|
|
class uint256;
|
|
|
|
|
|
|
|
extern std::map<uint256, CAlert> mapAlerts;
|
|
|
|
extern CCriticalSection cs_mapAlerts;
|
2012-08-28 23:04:54 +02:00
|
|
|
|
|
|
|
/** 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;
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nRelayUntil; // when newer nodes stop relaying to newer nodes
|
|
|
|
int64_t nExpiration;
|
2012-08-28 23:04:54 +02:00
|
|
|
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;
|
|
|
|
|
2014-09-02 09:58:09 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
overhaul serialization code
The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:
template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0;
/* CODE */
return nSerSize;
}
In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.
2014-08-20 08:42:31 +02:00
|
|
|
|
2014-08-20 22:44:38 +02:00
|
|
|
template <typename Stream, typename Operation>
|
2014-08-21 00:49:32 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
2012-08-28 23:04:54 +02:00
|
|
|
READWRITE(this->nVersion);
|
|
|
|
nVersion = this->nVersion;
|
|
|
|
READWRITE(nRelayUntil);
|
|
|
|
READWRITE(nExpiration);
|
|
|
|
READWRITE(nID);
|
|
|
|
READWRITE(nCancel);
|
|
|
|
READWRITE(setCancel);
|
|
|
|
READWRITE(nMinVer);
|
|
|
|
READWRITE(nMaxVer);
|
|
|
|
READWRITE(setSubVer);
|
|
|
|
READWRITE(nPriority);
|
|
|
|
|
2014-08-07 23:00:01 +02:00
|
|
|
READWRITE(LIMITED_STRING(strComment, 65536));
|
|
|
|
READWRITE(LIMITED_STRING(strStatusBar, 256));
|
|
|
|
READWRITE(LIMITED_STRING(strReserved, 256));
|
overhaul serialization code
The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:
template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0;
/* CODE */
return nSerSize;
}
In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.
2014-08-20 08:42:31 +02:00
|
|
|
}
|
2012-08-28 23:04:54 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-09-02 09:58:09 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
overhaul serialization code
The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:
template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0;
/* CODE */
return nSerSize;
}
In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.
2014-08-20 08:42:31 +02:00
|
|
|
|
2014-08-20 22:44:38 +02:00
|
|
|
template <typename Stream, typename Operation>
|
2014-08-21 00:49:32 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
2012-08-28 23:04:54 +02:00
|
|
|
READWRITE(vchMsg);
|
|
|
|
READWRITE(vchSig);
|
overhaul serialization code
The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:
template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0;
/* CODE */
return nSerSize;
}
In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.
2014-08-20 08:42:31 +02:00
|
|
|
}
|
2012-08-28 23:04:54 +02:00
|
|
|
|
|
|
|
void SetNull();
|
|
|
|
bool IsNull() const;
|
|
|
|
uint256 GetHash() const;
|
|
|
|
bool IsInEffect() const;
|
|
|
|
bool Cancels(const CAlert& alert) const;
|
2015-05-31 15:36:44 +02:00
|
|
|
bool AppliesTo(int nVersion, const std::string& strSubVerIn) const;
|
2012-08-28 23:04:54 +02:00
|
|
|
bool AppliesToMe() const;
|
|
|
|
bool RelayTo(CNode* pnode) const;
|
2015-04-03 17:42:06 +02:00
|
|
|
bool CheckSignature(const std::vector<unsigned char>& alertKey) const;
|
|
|
|
bool ProcessAlert(const std::vector<unsigned char>& alertKey, bool fThread = true); // fThread means run -alertnotify in a free-running thread
|
2014-10-07 19:11:48 +02:00
|
|
|
static void Notify(const std::string& strMessage, bool fThread);
|
2012-08-28 23:04:54 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get copy of (active) alert object by hash. Returns a null alert if it is not found.
|
|
|
|
*/
|
|
|
|
static CAlert getAlertByHash(const uint256 &hash);
|
|
|
|
};
|
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#endif // BITCOIN_ALERT_H
|