| 276 | } |
| 277 | |
| 278 | void ThreadSendAlert() |
| 279 | { |
| 280 | if (!mapArgs.count("-sendalert") && !mapArgs.count("-printalert")) |
| 281 | return; |
| 282 | |
| 283 | // Wait one minute so we get well connected. If we only need to print |
| 284 | // but not to broadcast - do this right away. |
| 285 | if (mapArgs.count("-sendalert")) |
| 286 | MilliSleep(60*1000); |
| 287 | |
| 288 | // |
| 289 | // Alerts are relayed around the network until nRelayUntil, flood |
| 290 | // filling to every node. |
| 291 | // After the relay time is past, new nodes are told about alerts |
| 292 | // when they connect to peers, until either nExpiration or |
| 293 | // the alert is cancelled by a newer alert. |
| 294 | // Nodes never save alerts to disk, they are in-memory-only. |
| 295 | // |
| 296 | CAlert alert; |
| 297 | alert.nRelayUntil = GetTime() + 15 * 60; |
| 298 | alert.nExpiration = GetTime() + 30 * 60 * 60; |
| 299 | alert.nID = 1; // keep track of alert IDs somewhere |
| 300 | alert.nCancel = 0; // cancels previous messages up to this ID number |
| 301 | |
| 302 | // These versions are protocol versions |
| 303 | alert.nMinVer = 65000; |
| 304 | alert.nMaxVer = PROTOCOL_VERSION; |
| 305 | |
| 306 | // |
| 307 | // 1000 for Misc warnings like out of disk space and clock is wrong |
| 308 | // 2000 for longer invalid proof-of-work chain |
| 309 | // Higher numbers mean higher priority |
| 310 | alert.nPriority = 5000; |
| 311 | alert.strComment = ""; |
| 312 | alert.strStatusBar = "UPGRADE REQUIRED: https://github.com/lux-core/lux"; |
| 313 | |
| 314 | // Sign |
| 315 | if(!alert.Sign()){ |
| 316 | LogPrintf("ThreadSendAlert() : could not sign alert\n"); |
| 317 | return; |
| 318 | } |
| 319 | |
| 320 | // Test |
| 321 | CDataStream sBuffer(SER_NETWORK, CLIENT_VERSION); |
| 322 | sBuffer << alert; |
| 323 | CAlert alert2; |
| 324 | sBuffer >> alert2; |
| 325 | if (!alert2.CheckSignature(Params().AlertKey())){ |
| 326 | printf("ThreadSendAlert() : CheckSignature failed\n"); |
| 327 | return; |
| 328 | } |
| 329 | assert(alert2.vchMsg == alert.vchMsg); |
| 330 | assert(alert2.vchSig == alert.vchSig); |
| 331 | alert.SetNull(); |
| 332 | printf("\nThreadSendAlert:\n"); |
| 333 | printf("hash=%s\n", alert2.GetHash().ToString().c_str()); |
| 334 | printf("%s", alert2.ToString().c_str()); |
| 335 | printf("vchMsg=%s\n", HexStr(alert2.vchMsg).c_str()); |
nothing calls this directly
no test coverage detected