Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: make a few values immutable, and use deterministic randomness for the localnonce #9050

Merged
merged 2 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
net: constify a few CNode vars to indicate that they're threadsafe
  • Loading branch information
theuni committed Oct 31, 2016
commit aff6584e09938768838a768b67722db553cf8ef4
11 changes: 5 additions & 6 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2512,9 +2512,13 @@ unsigned int CConnman::GetSendBufferSize() const{ return nSendBufferMaxSize; }
CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, const std::string& addrNameIn, bool fInboundIn) :
ssSend(SER_NETWORK, INIT_PROTO_VERSION),
addr(addrIn),
fInbound(fInboundIn),
id(idIn),
nKeyedNetGroup(nKeyedNetGroupIn),
addrKnown(5000, 0.001),
filterInventoryKnown(50000, 0.000001)
filterInventoryKnown(50000, 0.000001),
nLocalServices(nLocalServicesIn),
nMyStartingHeight(nMyStartingHeightIn)
{
nServices = NODE_NONE;
nServicesExpected = NODE_NONE;
Expand All @@ -2533,7 +2537,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
fOneShot = false;
fClient = false; // set by version message
fFeeler = false;
fInbound = fInboundIn;
fNetworkNode = false;
fSuccessfullyConnected = false;
fDisconnect = false;
Expand Down Expand Up @@ -2562,12 +2565,8 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
minFeeFilter = 0;
lastSentFeeFilter = 0;
nextSendTimeFeeFilter = 0;
id = idIn;
nOptimisticBytesWritten = 0;
nLocalServices = nLocalServicesIn;

GetRandBytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce));
nMyStartingHeight = nMyStartingHeightIn;

BOOST_FOREACH(const std::string &msg, getAllNetMessageTypes())
mapRecvBytesPerMsgCmd[msg] = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ class CNode
bool fFeeler; // If true this node is being used as a short lived feeler.
bool fOneShot;
bool fClient;
bool fInbound;
const bool fInbound;
bool fNetworkNode;
bool fSuccessfullyConnected;
bool fDisconnect;
Expand All @@ -603,7 +603,7 @@ class CNode
CCriticalSection cs_filter;
CBloomFilter* pfilter;
int nRefCount;
NodeId id;
const NodeId id;

const uint64_t nKeyedNetGroup;
protected:
Expand Down Expand Up @@ -679,8 +679,8 @@ class CNode

uint64_t nLocalHostNonce;
// Services offered to this peer
ServiceFlags nLocalServices;
int nMyStartingHeight;
const ServiceFlags nLocalServices;
const int nMyStartingHeight;
public:

NodeId GetId() const {
Expand Down