21 #include <boost/algorithm/string/classification.hpp>
22 #include <boost/algorithm/string/replace.hpp>
23 #include <boost/foreach.hpp>
24 #include <boost/thread.hpp>
51 std::string strSetCancel;
52 BOOST_FOREACH(
int n, setCancel)
54 std::string strSetSubVer;
55 BOOST_FOREACH(
const std::string& str, setSubVer)
56 strSetSubVer +=
"\"" + str +
"\" ";
69 " strComment = \"%s\"\n"
70 " strStatusBar = \"%s\"\n"
95 return (nExpiration == 0);
100 return Hash(this->vchMsg.begin(), this->vchMsg.end());
112 return (alert.
nID <= nCancel || setCancel.count(alert.
nID));
118 return (IsInEffect() &&
119 nMinVer <= nVersion && nVersion <= nMaxVer &&
120 (setSubVer.empty() || setSubVer.count(strSubVerIn)));
131 if (!key.
Verify(
Hash(vchMsg.begin(), vchMsg.end()), vchSig))
132 return error(
"CAlert::CheckSignature(): verify signature failed");
145 map<uint256, CAlert>::iterator mi =
mapAlerts.find(hash);
154 if (!CheckSignature(alertKey))
166 int maxInt = std::numeric_limits<int>::max();
170 nExpiration == maxInt &&
171 nCancel == (maxInt-1) &&
175 nPriority == maxInt &&
176 strStatusBar ==
"URGENT: Alert key compromised, upgrade required"
186 const CAlert& alert = (*mi).second;
189 LogPrint(
"alert",
"cancelling alert %d\n", alert.
nID);
195 LogPrint(
"alert",
"expiring alert %d\n", alert.
nID);
206 const CAlert& alert = item.second;
209 LogPrint(
"alert",
"alert already cancelled by %d\n", alert.
nID);
215 mapAlerts.insert(make_pair(GetHash(), *
this));
220 Notify(strStatusBar, fThread);
224 LogPrint(
"alert",
"accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
231 std::string strCmd =
GetArg(
"-alertnotify",
"");
232 if (strCmd.empty())
return;
237 std::string singleQuote(
"'");
239 safeStatus = singleQuote+safeStatus+singleQuote;
240 boost::replace_all(strCmd,
"%s", safeStatus);
CCriticalSection cs_mapAlerts
map< uint256, CAlert > mapAlerts
An alert is a combination of a serialized CUnsignedAlert and a signature.
bool CheckSignature(const std::vector< unsigned char > &alertKey) const
bool Cancels(const CAlert &alert) const
bool AppliesTo(int nVersion, const std::string &strSubVerIn) const
static CAlert getAlertByHash(const uint256 &hash)
static void Notify(const std::string &strMessage, bool fThread=true)
bool ProcessAlert(const std::vector< unsigned char > &alertKey, bool fThread=true)
boost::signals2::signal< void(const uint256 &hash, ChangeType status)> NotifyAlertChanged
New, updated or cancelled alert.
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
Double ended buffer combining vector and stream-like interfaces.
An encapsulated public key.
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
Verify a DER signature (~72 bytes).
Alerts are for notifying old versions if they become too obsolete and need to upgrade.
std::string ToString() const
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip...
const std::string CLIENT_NAME
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
int64_t GetAdjustedTime()
CClientUIInterface uiInterface
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
void runCommand(const std::string &strCommand)
#define LogPrint(category,...)
bool error(const char *fmt, const Args &... args)
string SanitizeString(const string &str, int rule)
#define PAIRTYPE(t1, t2)
This is needed because the foreach macro can't get over the comma in pair<t1, t2>