2017-03-15 12:54:34 +01:00
|
|
|
#include "alert.h"
|
|
|
|
#include "clientversion.h"
|
|
|
|
#include "chainparams.h"
|
|
|
|
#include "init.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "utilstrencodings.h"
|
|
|
|
#include "utiltime.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
If you need to broadcast an alert, here's what to do:
|
|
|
|
|
|
|
|
1. Modify alert parameters below, see alert.* and comments in the code
|
|
|
|
for what does what.
|
|
|
|
|
|
|
|
2. run dashd with -printalert or -sendalert like this:
|
|
|
|
/path/to/dashd -printalert
|
|
|
|
|
|
|
|
One minute after starting up the alert will be broadcast. It is then
|
|
|
|
flooded through the network until the nRelayUntil time, and will be
|
|
|
|
active until nExpiration OR the alert is cancelled.
|
|
|
|
|
|
|
|
If you screw up something, send another alert with nCancel set to cancel
|
|
|
|
the bad alert.
|
|
|
|
*/
|
|
|
|
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
void ThreadSendAlert(CConnman& connman)
|
2017-03-15 12:54:34 +01:00
|
|
|
{
|
2016-12-27 19:11:21 +01:00
|
|
|
if (!IsArgSet("-sendalert") && !IsArgSet("-printalert"))
|
2017-03-15 12:54:34 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Wait one minute so we get well connected. If we only need to print
|
|
|
|
// but not to broadcast - do this right away.
|
2016-12-27 19:11:21 +01:00
|
|
|
if (IsArgSet("-sendalert"))
|
2017-03-15 12:54:34 +01:00
|
|
|
MilliSleep(60*1000);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Alerts are relayed around the network until nRelayUntil, flood
|
|
|
|
// filling to every node.
|
|
|
|
// After the relay time is past, new nodes are told about alerts
|
|
|
|
// when they connect to peers, until either nExpiration or
|
|
|
|
// the alert is cancelled by a newer alert.
|
|
|
|
// Nodes never save alerts to disk, they are in-memory-only.
|
|
|
|
//
|
|
|
|
CAlert alert;
|
2017-08-29 01:51:44 +02:00
|
|
|
alert.nRelayUntil = GetAdjustedTime() + 15 * 60;
|
|
|
|
alert.nExpiration = GetAdjustedTime() + 30 * 60 * 60;
|
2017-03-15 12:54:34 +01:00
|
|
|
alert.nID = 1; // keep track of alert IDs somewhere
|
|
|
|
alert.nCancel = 0; // cancels previous messages up to this ID number
|
|
|
|
|
|
|
|
// These versions are protocol versions
|
|
|
|
alert.nMinVer = 70000;
|
|
|
|
alert.nMaxVer = 70103;
|
|
|
|
|
|
|
|
//
|
|
|
|
// 1000 for Misc warnings like out of disk space and clock is wrong
|
|
|
|
// 2000 for longer invalid proof-of-work chain
|
|
|
|
// Higher numbers mean higher priority
|
|
|
|
alert.nPriority = 5000;
|
|
|
|
alert.strComment = "";
|
|
|
|
alert.strStatusBar = "URGENT: Upgrade required: see https://www.dash.org";
|
|
|
|
|
|
|
|
// Set specific client version/versions here. If setSubVer is empty, no filtering on subver is done:
|
|
|
|
// alert.setSubVer.insert(std::string("/Dash Core:0.12.0.58/"));
|
|
|
|
|
|
|
|
// Sign
|
|
|
|
if(!alert.Sign())
|
|
|
|
{
|
|
|
|
LogPrintf("ThreadSendAlert() : could not sign alert\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test
|
|
|
|
CDataStream sBuffer(SER_NETWORK, CLIENT_VERSION);
|
|
|
|
sBuffer << alert;
|
|
|
|
CAlert alert2;
|
|
|
|
sBuffer >> alert2;
|
|
|
|
if (!alert2.CheckSignature(Params().AlertKey()))
|
|
|
|
{
|
|
|
|
printf("ThreadSendAlert() : CheckSignature failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(alert2.vchMsg == alert.vchMsg);
|
|
|
|
assert(alert2.vchSig == alert.vchSig);
|
|
|
|
alert.SetNull();
|
|
|
|
printf("\nThreadSendAlert:\n");
|
|
|
|
printf("hash=%s\n", alert2.GetHash().ToString().c_str());
|
|
|
|
printf("%s", alert2.ToString().c_str());
|
|
|
|
printf("vchMsg=%s\n", HexStr(alert2.vchMsg).c_str());
|
|
|
|
printf("vchSig=%s\n", HexStr(alert2.vchSig).c_str());
|
|
|
|
|
|
|
|
// Confirm
|
2016-12-27 19:11:21 +01:00
|
|
|
if (!IsArgSet("-sendalert"))
|
2017-03-15 12:54:34 +01:00
|
|
|
return;
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
while (connman.GetNodeCount(CConnman::CONNECTIONS_ALL) == 0 && !ShutdownRequested())
|
2017-03-15 12:54:34 +01:00
|
|
|
MilliSleep(500);
|
|
|
|
if (ShutdownRequested())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Send
|
|
|
|
printf("ThreadSendAlert() : Sending alert\n");
|
|
|
|
int nSent = 0;
|
|
|
|
{
|
2017-09-05 12:53:28 +02:00
|
|
|
connman.ForEachNode([&alert2, &connman, &nSent](CNode* pnode) {
|
|
|
|
if (alert2.RelayTo(pnode, connman))
|
2017-03-15 12:54:34 +01:00
|
|
|
{
|
|
|
|
printf("ThreadSendAlert() : Sent alert to %s\n", pnode->addr.ToString().c_str());
|
|
|
|
nSent++;
|
|
|
|
}
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
});
|
2017-03-15 12:54:34 +01:00
|
|
|
}
|
|
|
|
printf("ThreadSendAlert() : Alert sent to %d nodes\n", nSent);
|
|
|
|
}
|