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)));
136 if (pnode->
setKnown.insert(GetHash()).second)
153 vchMsg = std::vector<unsigned char>(sMsg.
begin(), sMsg.
end());
155 if (!vchSecret.SetString(
GetArg(
"-alertkey",
"")))
157 printf(
"CAlert::SignAlert() : vchSecret.SetString failed\n");
161 if (!
key.Sign(
Hash(vchMsg.begin(), vchMsg.end()), vchSig))
163 printf(
"CAlert::SignAlert() : key.Sign failed\n");
173 if (!
key.Verify(
Hash(vchMsg.begin(), vchMsg.end()), vchSig))
174 return error(
"CAlert::CheckSignature(): verify signature failed");
187 map<uint256, CAlert>::iterator mi =
mapAlerts.find(hash);
196 if (!CheckSignature(alertKey))
208 int maxInt = std::numeric_limits<int>::max();
212 nExpiration == maxInt &&
213 nCancel == (maxInt-1) &&
217 nPriority == maxInt &&
218 strStatusBar ==
"URGENT: Alert key compromised, upgrade required" 228 const CAlert& alert = (*mi).second;
231 LogPrint(
"alert",
"cancelling alert %d\n", alert.
nID);
237 LogPrint(
"alert",
"expiring alert %d\n", alert.
nID);
248 const CAlert& alert = item.second;
251 LogPrint(
"alert",
"alert already cancelled by %d\n", alert.
nID);
257 mapAlerts.insert(make_pair(GetHash(), *
this));
262 Notify(strStatusBar, fThread);
266 LogPrint(
"alert",
"accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
273 std::string strCmd =
GetArg(
"-alertnotify",
"");
274 if (strCmd.empty())
return;
279 std::string singleQuote(
"'");
281 safeStatus = singleQuote+safeStatus+singleQuote;
282 boost::replace_all(strCmd,
"%s", safeStatus);
boost::signals2::signal< void(const uint256 &hash, ChangeType status)> NotifyAlertChanged
std::string ToString() const
const_iterator end() const
bool AppliesTo(int nVersion, const std::string &strSubVerIn) const
static int LogPrint(const char *category, const char *format)
const_iterator begin() const
CClientUIInterface uiInterface
static bool error(const char *format)
map< uint256, CAlert > mapAlerts
CCriticalSection cs_mapAlerts
uint256 Hash(const T1 pbegin, const T1 pend)
static CAlert getAlertByHash(const uint256 &hash)
const std::string CLIENT_NAME
std::set< uint256 > setKnown
static const int PROTOCOL_VERSION
static void Notify(const std::string &strMessage, bool fThread)
int64_t GetAdjustedTime()
void runCommand(const std::string &strCommand)
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
std::string GetArg(const std::string &strArg, const std::string &strDefault)
bool Cancels(const CAlert &alert) const
bool RelayTo(CNode *pnode, CConnman &connman) const
bool ProcessAlert(const std::vector< unsigned char > &alertKey, bool fThread=true)
static const int CLIENT_VERSION
void PushMessage(CNode *pnode, const std::string &sCommand, Args &&... args)
string SanitizeString(const string &str, int rule)
std::atomic< int > nVersion
bool CheckSignature(const std::vector< unsigned char > &alertKey) const