From 41c868f47e671dc5009cd47496c39c13ae36306b Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sun, 22 Apr 2018 17:19:03 +0100 Subject: Re-introduce alert functionality (#1470) Re-introduce alert functionality removed from Bitcoin upstream --- src/net_processing.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 7 deletions(-) (limited to 'src/net_processing.cpp') diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 706b4c68f..924fc5eb8 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -6,6 +6,7 @@ #include "net_processing.h" #include "addrman.h" +#include "alert.h" #include "arith_uint256.h" #include "blockencodings.h" #include "chainparams.h" @@ -1366,13 +1367,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr pfrom->nTimeOffset = nTimeOffset; AddTimeData(pfrom->addr, nTimeOffset); - // If the peer is old enough to have the old alert system, send it the final alert. - /* if (pfrom->nVersion <= 70012) { - // TODO: Replace this with a valid Dogecoin alert - // Disabled meantime as the remote client considers the nonsense alert a hack and drops the connection - CDataStream finalAlert(ParseHex("60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50"), SER_NETWORK, PROTOCOL_VERSION); - connman.PushMessage(pfrom, CNetMsgMaker(nSendVersion).Make("alert", finalAlert)); - } */ + // Relay alerts + { + LOCK(cs_mapAlerts); + BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts) + pfrom->PushAlert(item.second); + } // Feeler connections exist only to verify if address is online. if (pfrom->fFeeler) { @@ -2523,6 +2523,38 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr } } + else if (fAlerts && strCommand == NetMsgType::ALERT) + { + CAlert alert; + vRecv >> alert; + + uint256 alertHash = alert.GetHash(); + if (pfrom->setKnown.count(alertHash) == 0) + { + if (alert.ProcessAlert(chainparams.AlertKey())) + { + // Relay + pfrom->setKnown.insert(alertHash); + { + + connman.ForEachNode([&alert](CNode* pnode) + { + pnode->PushAlert(alert); + }); + } + } + else { + // Small DoS penalty so peers that send us lots of + // duplicate/expired/invalid-signature/whatever alerts + // eventually get banned. + // This isn't a Misbehaving(100) (immediate ban) because the + // peer might be an older or different implementation with + // a different signature key, etc. + Misbehaving(pfrom->GetId(), 10); + } + } + } + else if (strCommand == NetMsgType::FILTERLOAD) { @@ -3267,6 +3299,25 @@ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic& interr pto->nextSendTimeFeeFilter = timeNow + GetRandInt(MAX_FEEFILTER_CHANGE_DELAY) * 1000000; } } + + // + // Message: alert + // + BOOST_FOREACH(const CAlert &alert, pto->vAlertToSend) { + // returns true if wasn't already contained in the set + if (pto->setKnown.insert(alert.GetHash()).second) + { + if (alert.AppliesTo(pto->nVersion, pto->strSubVer) || + alert.AppliesToMe() || + GetAdjustedTime() < alert.nRelayUntil) + { + connman.PushMessage(pto, msgMaker.Make(NetMsgType::ALERT, alert)); + return true; + } + } + } + pto->vAlertToSend.clear(); + } return true; } -- cgit v1.2.3