MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ProcessAlert

Method ProcessAlert

src/alert.cpp:150–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150bool CAlert::ProcessAlert(bool fThread) {
151 if (!CheckSignature())
152 return false;
153 if (!IsInEffect())
154 return false;
155
156 // alert.nID=max is reserved for if the alert key is
157 // compromised. It must have a pre-defined message,
158 // must never expire, must apply to all versions,
159 // and must cancel all previous
160 // alerts or it will be ignored (so an attacker can't
161 // send an "everything is OK, don't panic" version that
162 // cannot be overridden):
163 int maxInt = numeric_limits<int>::max();
164 if (nID == maxInt) {
165 if (!(
166 nExpiration == maxInt &&
167 nCancel == (maxInt-1) &&
168 nMinVer == 0 &&
169 nMaxVer == maxInt &&
170 setSubVer.empty() &&
171 nPriority == maxInt &&
172 strStatusBar == "URGENT: Alert key compromised, upgrade required"
173 ))
174 return false;
175 }
176
177 {
178 LOCK(cs_mapAlerts);
179 // Cancel previous alerts
180 for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();) {
181 const CAlert& alert = (*mi).second;
182 if (Cancels(alert)) {
183 LogPrint(BCLog::ALERT, "cancelling alert %d\n", alert.nID);
184 mapAlerts.erase(mi++);
185 } else if (!alert.IsInEffect()) {
186 LogPrint(BCLog::ALERT, "expiring alert %d\n", alert.nID);
187 mapAlerts.erase(mi++);
188 } else {
189 mi++;
190 }
191 }
192
193 // Check if this alert has been cancelled
194 for (const auto &item : mapAlerts) {
195 const CAlert& alert = item.second;
196 if (alert.Cancels(*this)) {
197 LogPrint(BCLog::ALERT, "alert already cancelled by %d\n", alert.nID);
198 return false;
199 }
200 }
201
202 // Add to mapAlerts
203 mapAlerts.insert(make_pair(GetHash(), *this));
204 // Notify UI and -alertnotify if it applies to me
205 if (AppliesToMe()) {
206 string strCmd = SysCfg().GetArg("-alertnotify", "");
207 if (!strCmd.empty()) {

Callers 1

ProcessAlertMessageFunction · 0.80

Calls 9

IsInEffectMethod · 0.80
CancelsMethod · 0.80
GetArgMethod · 0.80
SanitizeStringFunction · 0.50
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected