Skip to content

Commit

Permalink
net: constify a few CNode vars to indicate that they're threadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
theuni authored and Fuzzbawls committed Sep 2, 2020
1 parent 34050a3 commit de1ad13
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2467,9 +2467,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 @@ -2488,7 +2492,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 All @@ -2509,9 +2512,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
nPingUsecTime = 0;
fPingQueued = false;
nMinPingUsecTime = std::numeric_limits<int64_t>::max();
id = idIn;
nOptimisticBytesWritten = 0;
nLocalServices = nLocalServicesIn;
fPauseRecv = false;
nProcessQueueSize = 0;

Expand All @@ -2520,7 +2521,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0;

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

if (fLogIPs)
LogPrint(BCLog::NET, "Added connection to %s peer=%d\n", addrName, id);
Expand Down
9 changes: 5 additions & 4 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,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;
std::atomic_bool fDisconnect;
Expand All @@ -603,7 +603,7 @@ class CNode
RecursiveMutex cs_filter;
CBloomFilter* pfilter;
int nRefCount;
NodeId id;
const NodeId id;

const uint64_t nKeyedNetGroup;
std::atomic_bool fPauseRecv;
Expand Down Expand Up @@ -657,8 +657,9 @@ class CNode


uint64_t nLocalHostNonce;
ServiceFlags nLocalServices;
int nMyStartingHeight;
// Services offered to this peer
const ServiceFlags nLocalServices;
const int nMyStartingHeight;
public:
NodeId GetId() const
{
Expand Down

0 comments on commit de1ad13

Please sign in to comment.