aboutsummaryrefslogtreecommitdiff
path: root/src/net.h
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2016-05-24 16:42:17 -0400
committerCory Fields <cory-nospam-@coryfields.com>2016-09-08 12:24:06 -0400
commitf60b9059e4958245bda82e9656c52a31d5268ad9 (patch)
treeebe2791c74d053d270d9057a5237dc85b9c5fb2e /src/net.h
parentfdf69ff21aef8ed8071a757979f4239537f7afba (diff)
downloadbitcoin-f60b9059e4958245bda82e9656c52a31d5268ad9.tar.xz
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.
Diffstat (limited to 'src/net.h')
-rw-r--r--src/net.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/net.h b/src/net.h
index 0859190d36..852822d85b 100644
--- a/src/net.h
+++ b/src/net.h
@@ -109,7 +109,7 @@ public:
CConnman();
~CConnman();
- bool Start(boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServicesIn, ServiceFlags nRelevantServicesIn, int nMaxConnectionsIn, int nMaxOutboundIn, std::string& strNodeError);
+ bool Start(boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServicesIn, ServiceFlags nRelevantServicesIn, int nMaxConnectionsIn, int nMaxOutboundIn, int nBestHeightIn, std::string& strNodeError);
void Stop();
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);
@@ -199,6 +199,10 @@ public:
uint64_t GetTotalBytesRecv();
uint64_t GetTotalBytesSent();
+ void SetBestHeight(int height);
+ int GetBestHeight() const;
+
+
private:
struct ListenSocket {
SOCKET socket;
@@ -288,12 +292,13 @@ private:
CSemaphore *semOutbound;
int nMaxConnections;
int nMaxOutbound;
+ std::atomic<int> nBestHeight;
};
extern std::unique_ptr<CConnman> g_connman;
void MapPort(bool fUseUPnP);
unsigned short GetListenPort();
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
-bool StartNode(CConnman& connman, boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServices, ServiceFlags nRelevantServices, int nMaxConnections, int nMaxOutbound, std::string& strNodeError);
+bool StartNode(CConnman& connman, boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServices, ServiceFlags nRelevantServices, int nMaxConnections, int nMaxOutbound, int nBestHeightIn, std::string& strNodeError);
bool StopNode(CConnman& connman);
size_t SocketSendData(CNode *pnode);
@@ -315,7 +320,6 @@ struct CombinerAll
// Signals for message handling
struct CNodeSignals
{
- boost::signals2::signal<int ()> GetHeight;
boost::signals2::signal<bool (CNode*, CConnman&), CombinerAll> ProcessMessages;
boost::signals2::signal<bool (CNode*, CConnman&), CombinerAll> SendMessages;
boost::signals2::signal<void (NodeId, const CNode*)> InitializeNode;
@@ -558,7 +562,7 @@ public:
CAmount lastSentFeeFilter;
int64_t nextSendTimeFeeFilter;
- CNode(NodeId id, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const CAddress &addrIn, const std::string &addrNameIn = "", bool fInboundIn = false);
+ CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, const std::string &addrNameIn = "", bool fInboundIn = false);
~CNode();
private:
@@ -569,6 +573,7 @@ private:
uint64_t nLocalHostNonce;
ServiceFlags nLocalServices;
+ int nMyStartingHeight;
public:
NodeId GetId() const {