17 #include <boost/algorithm/string/classification.hpp>
18 #include <boost/algorithm/string/replace.hpp>
19 #include <boost/foreach.hpp>
26 void CUnsignedAlert::SetNull()
46 std::string strSetCancel;
47 BOOST_FOREACH(
int n, setCancel)
49 std::string strSetSubVer;
50 BOOST_FOREACH(std::string str, setSubVer)
51 strSetSubVer +=
"\"" + str +
"\" ";
64 " strComment = \"%s\"\n"
65 " strStatusBar = \"%s\"\n"
86 void CAlert::SetNull()
88 CUnsignedAlert::SetNull();
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)));
133 if (pnode->
setKnown.insert(GetHash()).second)
149 if (!key.
Verify(
Hash(vchMsg.begin(), vchMsg.end()), vchSig))
150 return error(
"CAlert::CheckSignature() : verify signature failed");
163 map<uint256, CAlert>::iterator mi = mapAlerts.find(hash);
164 if(mi != mapAlerts.end())
172 if (!CheckSignature())
184 int maxInt = std::numeric_limits<int>::max();
188 nExpiration == maxInt &&
189 nCancel == (maxInt-1) &&
193 nPriority == maxInt &&
194 strStatusBar ==
"URGENT: Alert key compromised, upgrade required"
202 for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();)
204 const CAlert& alert = (*mi).second;
207 LogPrint(
"alert",
"cancelling alert %d\n", alert.
nID);
209 mapAlerts.erase(mi++);
213 LogPrint(
"alert",
"expiring alert %d\n", alert.
nID);
215 mapAlerts.erase(mi++);
224 const CAlert& alert = item.second;
227 LogPrint(
"alert",
"alert already cancelled by %d\n", alert.
nID);
233 mapAlerts.insert(make_pair(GetHash(), *
this));
238 std::string strCmd =
GetArg(
"-alertnotify",
"");
244 std::string singleQuote(
"'");
246 safeStatus = singleQuote+safeStatus+singleQuote;
247 boost::replace_all(strCmd,
"%s", safeStatus);
257 LogPrint(
"alert",
"accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
CClientUIInterface uiInterface
void PushMessage(const char *pszCommand)
const std::string CLIENT_NAME
static const int CLIENT_VERSION
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()
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
string SanitizeString(const string &str)
static int LogPrint(const char *category, const char *format)
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.
static bool error(const char *format)
map< uint256, CAlert > mapAlerts
CCriticalSection cs_mapAlerts
uint256 Hash(const T1 pbegin, const T1 pend)
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 const int PROTOCOL_VERSION
static CAlert getAlertByHash(const uint256 &hash)
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)