6 #include <boost/algorithm/string/classification.hpp>
7 #include <boost/algorithm/string/replace.hpp>
8 #include <boost/foreach.hpp>
22 static const char* pszMainKey =
"043c19a29fe8f763369aea68107e82854af7b072fc7d2d2adb87d2a3b40b51ab0d0e77805096e255a87388b175fd4a49d93d9b6c878004975e41222a3b85086eef";
23 static const char* pszTestKey =
"04e7b36458cb1db28567a99391109bc55a0c55623836d93d8794db6549dcc590012d1f5e23c786b752650dadce34fe5504dd7332450392eeb8292e62b211920c78";
25 void CUnsignedAlert::SetNull()
45 std::string strSetCancel;
46 BOOST_FOREACH(
int n, setCancel)
48 std::string strSetSubVer;
49 BOOST_FOREACH(std::string str, setSubVer)
50 strSetSubVer +=
"\"" + str +
"\" ";
54 " nRelayUntil = %"PRI64d"\n"
55 " nExpiration = %"PRI64d"\n"
63 " strComment = \"%s\"\n"
64 " strStatusBar = \"%s\"\n"
77 strStatusBar.c_str());
82 printf(
"%s", ToString().c_str());
85 void CAlert::SetNull()
87 CUnsignedAlert::SetNull();
94 return (nExpiration == 0);
99 return Hash(this->vchMsg.begin(), this->vchMsg.end());
111 return (alert.
nID <= nCancel || setCancel.count(alert.
nID));
117 return (IsInEffect() &&
118 nMinVer <= nVersion && nVersion <= nMaxVer &&
119 (setSubVer.empty() || setSubVer.count(strSubVerIn)));
132 if (pnode->
setKnown.insert(GetHash()).second)
148 if (!key.
Verify(
Hash(vchMsg.begin(), vchMsg.end()), vchSig))
149 return error(
"CAlert::CheckSignature() : verify signature failed");
162 map<uint256, CAlert>::iterator mi =
mapAlerts.find(hash);
171 if (!CheckSignature())
183 int maxInt = std::numeric_limits<int>::max();
187 nExpiration == maxInt &&
188 nCancel == (maxInt-1) &&
192 nPriority == maxInt &&
193 strStatusBar ==
"URGENT: Alert key compromised, upgrade required"
203 const CAlert& alert = (*mi).second;
206 printf(
"cancelling alert %d\n", alert.
nID);
212 printf(
"expiring alert %d\n", alert.
nID);
223 const CAlert& alert = item.second;
226 printf(
"alert already cancelled by %d\n", alert.
nID);
232 mapAlerts.insert(make_pair(GetHash(), *
this));
237 std::string strCmd =
GetArg(
"-alertnotify",
"");
243 std::string singleQuote(
"'");
245 safeStatus = singleQuote+safeStatus+singleQuote;
246 boost::replace_all(strCmd,
"%s", safeStatus);
256 printf(
"accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
bool error(const char *format,...)
void PushMessage(const char *pszCommand)
#define strprintf(format,...)
const std::string CLIENT_NAME
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
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
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.
CClientUIInterface uiInterface
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.
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
vector< unsigned char > ParseHex(const char *psz)
void runCommand(std::string strCommand)