19 #include <boost/algorithm/string/classification.hpp>
20 #include <boost/algorithm/string/replace.hpp>
21 #include <boost/foreach.hpp>
28 void CUnsignedAlert::SetNull()
48 std::string strSetCancel;
49 BOOST_FOREACH(
int n, setCancel)
51 std::string strSetSubVer;
52 BOOST_FOREACH(std::string str, setSubVer)
53 strSetSubVer +=
"\"" + str +
"\" ";
66 " strComment = \"%s\"\n"
67 " strStatusBar = \"%s\"\n"
88 void CAlert::SetNull()
90 CUnsignedAlert::SetNull();
97 return (nExpiration == 0);
102 return Hash(this->vchMsg.begin(), this->vchMsg.end());
114 return (alert.
nID <= nCancel || setCancel.count(alert.
nID));
120 return (IsInEffect() &&
121 nMinVer <= nVersion && nVersion <= nMaxVer &&
122 (setSubVer.empty() || setSubVer.count(strSubVerIn)));
135 if (pnode->
setKnown.insert(GetHash()).second)
151 if (!key.
Verify(
Hash(vchMsg.begin(), vchMsg.end()), vchSig))
152 return error(
"CAlert::CheckSignature() : verify signature failed");
165 map<uint256, CAlert>::iterator mi =
mapAlerts.find(hash);
174 if (!CheckSignature())
186 int maxInt = std::numeric_limits<int>::max();
190 nExpiration == maxInt &&
191 nCancel == (maxInt-1) &&
195 nPriority == maxInt &&
196 strStatusBar ==
"URGENT: Alert key compromised, upgrade required"
206 const CAlert& alert = (*mi).second;
209 LogPrint(
"alert",
"cancelling alert %d\n", alert.
nID);
215 LogPrint(
"alert",
"expiring alert %d\n", alert.
nID);
226 const CAlert& alert = item.second;
229 LogPrint(
"alert",
"alert already cancelled by %d\n", alert.
nID);
235 mapAlerts.insert(make_pair(GetHash(), *
this));
240 std::string strCmd =
GetArg(
"-alertnotify",
"");
246 std::string singleQuote(
"'");
248 safeStatus = singleQuote+safeStatus+singleQuote;
249 boost::replace_all(strCmd,
"%s", safeStatus);
259 LogPrint(
"alert",
"accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
CClientUIInterface uiInterface
void PushMessage(const char *pszCommand)
bool AppliesTo(int nVersion, std::string strSubVerIn) const
bool ProcessAlert(bool fThread=true)
Double ended buffer combining vector and stream-like interfaces.
std::set< uint256 > setKnown
int64_t GetAdjustedTime()
string SanitizeString(const string &str)
An alert is a combination of a serialized CUnsignedAlert and a signature.
std::string ToString() const
Alerts are for notifying old versions if they become too obsolete and need to upgrade.
An encapsulated public key.
map< uint256, CAlert > mapAlerts
CCriticalSection cs_mapAlerts
uint256 Hash(const T1 pbegin, const T1 pend)
const std::string CLIENT_NAME
bool RelayTo(CNode *pnode) const
boost::signals2::signal< void(const uint256 &hash, ChangeType status)> NotifyAlertChanged
New, updated or cancelled alert.
const CChainParams & Params()
Return the currently selected parameters.
static CAlert getAlertByHash(const uint256 &hash)
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...
bool CheckSignature() const
bool Cancels(const CAlert &alert) const
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Information about a peer.
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
void runCommand(std::string strCommand)