Remove p2p alert system #7692
Merged
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9206634
Update alert notification and GUI
btcdrak 01fdfef
Remove `-alerts` option
btcdrak bbb9d1d
Remove p2p alert handling
btcdrak 1b77471
Remove alert keys
btcdrak ad72104
Formatting
btcdrak 6601ce5
protocol.h/cpp: Removes NetMsgType::ALERT
afk11 cfd519e
Add release note documentation
btcdrak
Jump to file
No files found.
+2
−0
release-notes.md
doc/release-notes.md
+0
−2
Makefile.am
src/Makefile.am
+1
−1
Makefile.test.include
src/Makefile.test.include
+0
−266
alert.cpp
src/alert.cpp
+0
−113
alert.h
src/alert.h
+0
−2
chainparams.cpp
src/chainparams.cpp
+0
−3
chainparams.h
src/chainparams.h
+0
−3
init.cpp
src/init.cpp
+24
−67
main.cpp
src/main.cpp
+0
−3
main.h
src/main.h
+0
−2
protocol.cpp
src/protocol.cpp
+0
−7
protocol.h
src/protocol.h
+6
−21
clientmodel.cpp
src/qt/clientmodel.cpp
+1
−1
clientmodel.h
src/qt/clientmodel.h
+2
−179
alert_tests.cpp
src/test/alert_tests.cpp
BIN
alertTests.raw
src/test/data/alertTests.raw
+2
−3
ui_interface.h
src/ui_interface.h
| @@ -29,7 +29,7 @@ JSON_TEST_FILES = \ | ||
| test/data/tx_valid.json \ | ||
| test/data/sighash.json | ||
| -RAW_TEST_FILES = test/data/alertTests.raw | ||
laanwj
Owner
|
||
| +RAW_TEST_FILES = | ||
| GENERATED_TEST_FILES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.raw.h) | ||
266
src/alert.cpp
| @@ -1,266 +0,0 @@ | ||
| -// Copyright (c) 2010 Satoshi Nakamoto | ||
| -// Copyright (c) 2009-2015 The Bitcoin Core developers | ||
| -// Distributed under the MIT software license, see the accompanying | ||
| -// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
| - | ||
| -#include "alert.h" | ||
| - | ||
| -#include "clientversion.h" | ||
| -#include "net.h" | ||
| -#include "pubkey.h" | ||
| -#include "timedata.h" | ||
| -#include "ui_interface.h" | ||
| -#include "util.h" | ||
| -#include "utilstrencodings.h" | ||
| - | ||
| -#include <stdint.h> | ||
| -#include <algorithm> | ||
| -#include <map> | ||
| - | ||
| -#include <boost/algorithm/string/classification.hpp> | ||
| -#include <boost/algorithm/string/replace.hpp> | ||
| -#include <boost/foreach.hpp> | ||
| -#include <boost/thread.hpp> | ||
| - | ||
| -using namespace std; | ||
| - | ||
| -map<uint256, CAlert> mapAlerts; | ||
| -CCriticalSection cs_mapAlerts; | ||
| - | ||
| -void CUnsignedAlert::SetNull() | ||
| -{ | ||
| - nVersion = 1; | ||
| - nRelayUntil = 0; | ||
| - nExpiration = 0; | ||
| - nID = 0; | ||
| - nCancel = 0; | ||
| - setCancel.clear(); | ||
| - nMinVer = 0; | ||
| - nMaxVer = 0; | ||
| - setSubVer.clear(); | ||
| - nPriority = 0; | ||
| - | ||
| - strComment.clear(); | ||
| - strStatusBar.clear(); | ||
| - strReserved.clear(); | ||
| -} | ||
| - | ||
| -std::string CUnsignedAlert::ToString() const | ||
| -{ | ||
| - std::string strSetCancel; | ||
| - BOOST_FOREACH(int n, setCancel) | ||
| - strSetCancel += strprintf("%d ", n); | ||
| - std::string strSetSubVer; | ||
| - BOOST_FOREACH(const std::string& str, setSubVer) | ||
| - strSetSubVer += "\"" + str + "\" "; | ||
| - return strprintf( | ||
| - "CAlert(\n" | ||
| - " nVersion = %d\n" | ||
| - " nRelayUntil = %d\n" | ||
| - " nExpiration = %d\n" | ||
| - " nID = %d\n" | ||
| - " nCancel = %d\n" | ||
| - " setCancel = %s\n" | ||
| - " nMinVer = %d\n" | ||
| - " nMaxVer = %d\n" | ||
| - " setSubVer = %s\n" | ||
| - " nPriority = %d\n" | ||
| - " strComment = \"%s\"\n" | ||
| - " strStatusBar = \"%s\"\n" | ||
| - ")\n", | ||
| - nVersion, | ||
| - nRelayUntil, | ||
| - nExpiration, | ||
| - nID, | ||
| - nCancel, | ||
| - strSetCancel, | ||
| - nMinVer, | ||
| - nMaxVer, | ||
| - strSetSubVer, | ||
| - nPriority, | ||
| - strComment, | ||
| - strStatusBar); | ||
| -} | ||
| - | ||
| -void CAlert::SetNull() | ||
| -{ | ||
| - CUnsignedAlert::SetNull(); | ||
| - vchMsg.clear(); | ||
| - vchSig.clear(); | ||
| -} | ||
| - | ||
| -bool CAlert::IsNull() const | ||
| -{ | ||
| - return (nExpiration == 0); | ||
| -} | ||
| - | ||
| -uint256 CAlert::GetHash() const | ||
| -{ | ||
| - return Hash(this->vchMsg.begin(), this->vchMsg.end()); | ||
| -} | ||
| - | ||
| -bool CAlert::IsInEffect() const | ||
| -{ | ||
| - return (GetAdjustedTime() < nExpiration); | ||
| -} | ||
| - | ||
| -bool CAlert::Cancels(const CAlert& alert) const | ||
| -{ | ||
| - if (!IsInEffect()) | ||
| - return false; // this was a no-op before 31403 | ||
| - return (alert.nID <= nCancel || setCancel.count(alert.nID)); | ||
| -} | ||
| - | ||
| -bool CAlert::AppliesTo(int nVersion, const std::string& strSubVerIn) const | ||
| -{ | ||
| - // TODO: rework for client-version-embedded-in-strSubVer ? | ||
| - return (IsInEffect() && | ||
| - nMinVer <= nVersion && nVersion <= nMaxVer && | ||
| - (setSubVer.empty() || setSubVer.count(strSubVerIn))); | ||
| -} | ||
| - | ||
| -bool CAlert::AppliesToMe() const | ||
| -{ | ||
| - return AppliesTo(PROTOCOL_VERSION, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<std::string>())); | ||
| -} | ||
| - | ||
| -bool CAlert::RelayTo(CNode* pnode) const | ||
| -{ | ||
| - if (!IsInEffect()) | ||
| - return false; | ||
| - // don't relay to nodes which haven't sent their version message | ||
| - if (pnode->nVersion == 0) | ||
| - return false; | ||
| - // returns true if wasn't already contained in the set | ||
| - if (pnode->setKnown.insert(GetHash()).second) | ||
| - { | ||
| - if (AppliesTo(pnode->nVersion, pnode->strSubVer) || | ||
| - AppliesToMe() || | ||
| - GetAdjustedTime() < nRelayUntil) | ||
| - { | ||
| - pnode->PushMessage(NetMsgType::ALERT, *this); | ||
| - return true; | ||
| - } | ||
| - } | ||
| - return false; | ||
| -} | ||
| - | ||
| -bool CAlert::CheckSignature(const std::vector<unsigned char>& alertKey) const | ||
| -{ | ||
| - CPubKey key(alertKey); | ||
| - if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig)) | ||
| - return error("CAlert::CheckSignature(): verify signature failed"); | ||
| - | ||
| - // Now unserialize the data | ||
| - CDataStream sMsg(vchMsg, SER_NETWORK, PROTOCOL_VERSION); | ||
| - sMsg >> *(CUnsignedAlert*)this; | ||
| - return true; | ||
| -} | ||
| - | ||
| -CAlert CAlert::getAlertByHash(const uint256 &hash) | ||
| -{ | ||
| - CAlert retval; | ||
| - { | ||
| - LOCK(cs_mapAlerts); | ||
| - map<uint256, CAlert>::iterator mi = mapAlerts.find(hash); | ||
| - if(mi != mapAlerts.end()) | ||
| - retval = mi->second; | ||
| - } | ||
| - return retval; | ||
| -} | ||
| - | ||
| -bool CAlert::ProcessAlert(const std::vector<unsigned char>& alertKey, bool fThread) | ||
| -{ | ||
| - if (!CheckSignature(alertKey)) | ||
| - return false; | ||
| - if (!IsInEffect()) | ||
| - return false; | ||
| - | ||
| - // alert.nID=max is reserved for if the alert key is | ||
| - // compromised. It must have a pre-defined message, | ||
| - // must never expire, must apply to all versions, | ||
| - // and must cancel all previous | ||
| - // alerts or it will be ignored (so an attacker can't | ||
| - // send an "everything is OK, don't panic" version that | ||
| - // cannot be overridden): | ||
| - int maxInt = std::numeric_limits<int>::max(); | ||
| - if (nID == maxInt) | ||
| - { | ||
| - if (!( | ||
| - nExpiration == maxInt && | ||
| - nCancel == (maxInt-1) && | ||
| - nMinVer == 0 && | ||
| - nMaxVer == maxInt && | ||
| - setSubVer.empty() && | ||
| - nPriority == maxInt && | ||
| - strStatusBar == "URGENT: Alert key compromised, upgrade required" | ||
| - )) | ||
| - return false; | ||
| - } | ||
| - | ||
| - { | ||
| - LOCK(cs_mapAlerts); | ||
| - // Cancel previous alerts | ||
| - for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();) | ||
| - { | ||
| - const CAlert& alert = (*mi).second; | ||
| - if (Cancels(alert)) | ||
| - { | ||
| - LogPrint("alert", "cancelling alert %d\n", alert.nID); | ||
| - uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED); | ||
| - mapAlerts.erase(mi++); | ||
| - } | ||
| - else if (!alert.IsInEffect()) | ||
| - { | ||
| - LogPrint("alert", "expiring alert %d\n", alert.nID); | ||
| - uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED); | ||
| - mapAlerts.erase(mi++); | ||
| - } | ||
| - else | ||
| - mi++; | ||
| - } | ||
| - | ||
| - // Check if this alert has been cancelled | ||
| - BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts) | ||
| - { | ||
| - const CAlert& alert = item.second; | ||
| - if (alert.Cancels(*this)) | ||
| - { | ||
| - LogPrint("alert", "alert already cancelled by %d\n", alert.nID); | ||
| - return false; | ||
| - } | ||
| - } | ||
| - | ||
| - // Add to mapAlerts | ||
| - mapAlerts.insert(make_pair(GetHash(), *this)); | ||
| - // Notify UI and -alertnotify if it applies to me | ||
| - if(AppliesToMe()) | ||
| - { | ||
| - uiInterface.NotifyAlertChanged(GetHash(), CT_NEW); | ||
| - Notify(strStatusBar, fThread); | ||
| - } | ||
| - } | ||
| - | ||
| - LogPrint("alert", "accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe()); | ||
| - return true; | ||
| -} | ||
| - | ||
| -void | ||
| -CAlert::Notify(const std::string& strMessage, bool fThread) | ||
| -{ | ||
| - std::string strCmd = GetArg("-alertnotify", ""); | ||
| - if (strCmd.empty()) return; | ||
| - | ||
| - // Alert text should be plain ascii coming from a trusted source, but to | ||
| - // be safe we first strip anything not in safeChars, then add single quotes around | ||
| - // the whole string before passing it to the shell: | ||
| - std::string singleQuote("'"); | ||
| - std::string safeStatus = SanitizeString(strMessage); | ||
| - safeStatus = singleQuote+safeStatus+singleQuote; | ||
| - boost::replace_all(strCmd, "%s", safeStatus); | ||
| - | ||
| - if (fThread) | ||
| - boost::thread t(runCommand, strCmd); // thread runs free | ||
| - else | ||
| - runCommand(strCmd); | ||
| -} |
Oops, something went wrong.
Here you are deleting the only
RAW_TEST_FILEdefinition - please remove it in the rest of the file or leave this variable empty here to not cause confusion (and keep it for the future).