aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorRoss Nicoll <[email protected]>2018-04-22 17:19:03 +0100
committerRoss Nicoll <[email protected]>2018-09-19 22:11:47 +0100
commit41c868f47e671dc5009cd47496c39c13ae36306b (patch)
treee48b4f07bce4ff5aac8369551032dc46c46a8bf1 /src/net_processing.cpp
parentUpdate or eliminate remaining tests (#1483) (diff)
downloaddiscoin-41c868f47e671dc5009cd47496c39c13ae36306b.tar.xz
discoin-41c868f47e671dc5009cd47496c39c13ae36306b.zip
Re-introduce alert functionality (#1470)
Re-introduce alert functionality removed from Bitcoin upstream
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp65
1 files changed, 58 insertions, 7 deletions
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<bool>& 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;
}