Skip to content

Commit fac2f5e

Browse files
author
MarcoFalke
committed
Use C++11 default member initializers
1 parent 3f12515 commit fac2f5e

File tree

2 files changed

+45
-87
lines changed

2 files changed

+45
-87
lines changed

src/net.cpp

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,8 +2796,8 @@ int CConnman::GetBestHeight() const
27962796

27972797
unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; }
27982798

2799-
CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string& addrNameIn, bool fInboundIn) :
2800-
nTimeConnected(GetSystemTimeInSeconds()),
2799+
CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, bool fInboundIn)
2800+
: nTimeConnected(GetSystemTimeInSeconds()),
28012801
addr(addrIn),
28022802
addrBind(addrBindIn),
28032803
fInbound(fInboundIn),
@@ -2807,56 +2807,14 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
28072807
id(idIn),
28082808
nLocalHostNonce(nLocalHostNonceIn),
28092809
nLocalServices(nLocalServicesIn),
2810-
nMyStartingHeight(nMyStartingHeightIn),
2811-
nSendVersion(0)
2810+
nMyStartingHeight(nMyStartingHeightIn)
28122811
{
2813-
nServices = NODE_NONE;
28142812
hSocket = hSocketIn;
2815-
nRecvVersion = INIT_PROTO_VERSION;
2816-
nLastSend = 0;
2817-
nLastRecv = 0;
2818-
nSendBytes = 0;
2819-
nRecvBytes = 0;
2820-
nTimeOffset = 0;
28212813
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
2822-
nVersion = 0;
28232814
strSubVer = "";
2824-
fWhitelisted = false;
2825-
fOneShot = false;
2826-
m_manual_connection = false;
2827-
fClient = false; // set by version message
2828-
m_limited_node = false; // set by version message
2829-
fFeeler = false;
2830-
fSuccessfullyConnected = false;
2831-
fDisconnect = false;
2832-
nRefCount = 0;
2833-
nSendSize = 0;
2834-
nSendOffset = 0;
28352815
hashContinue = uint256();
2836-
nStartingHeight = -1;
28372816
filterInventoryKnown.reset();
2838-
fSendMempool = false;
2839-
fGetAddr = false;
2840-
nNextLocalAddrSend = 0;
2841-
nNextAddrSend = 0;
2842-
nNextInvSend = 0;
2843-
fRelayTxes = false;
2844-
fSentAddr = false;
28452817
pfilter = MakeUnique<CBloomFilter>();
2846-
timeLastMempoolReq = 0;
2847-
nLastBlockTime = 0;
2848-
nLastTXTime = 0;
2849-
nPingNonceSent = 0;
2850-
nPingUsecStart = 0;
2851-
nPingUsecTime = 0;
2852-
fPingQueued = false;
2853-
nMinPingUsecTime = std::numeric_limits<int64_t>::max();
2854-
minFeeFilter = 0;
2855-
lastSentFeeFilter = 0;
2856-
nextSendTimeFeeFilter = 0;
2857-
fPauseRecv = false;
2858-
fPauseSend = false;
2859-
nProcessQueueSize = 0;
28602818

28612819
for (const std::string &msg : getAllNetMessageTypes())
28622820
mapRecvBytesPerMsgCmd[msg] = 0;

src/net.h

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -640,80 +640,80 @@ class CNode
640640
friend class CConnman;
641641
public:
642642
// socket
643-
std::atomic<ServiceFlags> nServices;
643+
std::atomic<ServiceFlags> nServices{NODE_NONE};
644644
SOCKET hSocket GUARDED_BY(cs_hSocket);
645-
size_t nSendSize; // total size of all vSendMsg entries
646-
size_t nSendOffset; // offset inside the first vSendMsg already sent
647-
uint64_t nSendBytes GUARDED_BY(cs_vSend);
645+
size_t nSendSize{0}; // total size of all vSendMsg entries
646+
size_t nSendOffset{0}; // offset inside the first vSendMsg already sent
647+
uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
648648
std::deque<std::vector<unsigned char>> vSendMsg GUARDED_BY(cs_vSend);
649649
CCriticalSection cs_vSend;
650650
CCriticalSection cs_hSocket;
651651
CCriticalSection cs_vRecv;
652652

653653
CCriticalSection cs_vProcessMsg;
654654
std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
655-
size_t nProcessQueueSize;
655+
size_t nProcessQueueSize{0};
656656

657657
CCriticalSection cs_sendProcessing;
658658

659659
std::deque<CInv> vRecvGetData;
660-
uint64_t nRecvBytes GUARDED_BY(cs_vRecv);
661-
std::atomic<int> nRecvVersion;
660+
uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
661+
std::atomic<int> nRecvVersion{INIT_PROTO_VERSION};
662662

663-
std::atomic<int64_t> nLastSend;
664-
std::atomic<int64_t> nLastRecv;
663+
std::atomic<int64_t> nLastSend{0};
664+
std::atomic<int64_t> nLastRecv{0};
665665
const int64_t nTimeConnected;
666-
std::atomic<int64_t> nTimeOffset;
666+
std::atomic<int64_t> nTimeOffset{0};
667667
// Address of this peer
668668
const CAddress addr;
669669
// Bind address of our side of the connection
670670
const CAddress addrBind;
671-
std::atomic<int> nVersion;
671+
std::atomic<int> nVersion{0};
672672
// strSubVer is whatever byte array we read from the wire. However, this field is intended
673673
// to be printed out, displayed to humans in various forms and so on. So we sanitize it and
674674
// store the sanitized version in cleanSubVer. The original should be used when dealing with
675675
// the network or wire types and the cleaned string used when displayed or logged.
676676
std::string strSubVer GUARDED_BY(cs_SubVer), cleanSubVer GUARDED_BY(cs_SubVer);
677677
CCriticalSection cs_SubVer; // used for both cleanSubVer and strSubVer
678-
bool fWhitelisted; // This peer can bypass DoS banning.
679-
bool fFeeler; // If true this node is being used as a short lived feeler.
680-
bool fOneShot;
681-
bool m_manual_connection;
682-
bool fClient;
683-
bool m_limited_node; //after BIP159
678+
bool fWhitelisted{false}; // This peer can bypass DoS banning.
679+
bool fFeeler{false}; // If true this node is being used as a short lived feeler.
680+
bool fOneShot{false};
681+
bool m_manual_connection{false};
682+
bool fClient{false}; // set by version message
683+
bool m_limited_node{false}; //after BIP159, set by version message
684684
const bool fInbound;
685-
std::atomic_bool fSuccessfullyConnected;
686-
std::atomic_bool fDisconnect;
685+
std::atomic_bool fSuccessfullyConnected{false};
686+
std::atomic_bool fDisconnect{false};
687687
// We use fRelayTxes for two purposes -
688688
// a) it allows us to not relay tx invs before receiving the peer's version message
689689
// b) the peer may tell us in its version message that we should not relay tx invs
690690
// unless it loads a bloom filter.
691-
bool fRelayTxes GUARDED_BY(cs_filter);
692-
bool fSentAddr;
691+
bool fRelayTxes GUARDED_BY(cs_filter){false};
692+
bool fSentAddr{false};
693693
CSemaphoreGrant grantOutbound;
694694
mutable CCriticalSection cs_filter;
695695
std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter);
696-
std::atomic<int> nRefCount;
696+
std::atomic<int> nRefCount{0};
697697

698698
const uint64_t nKeyedNetGroup;
699-
std::atomic_bool fPauseRecv;
700-
std::atomic_bool fPauseSend;
699+
std::atomic_bool fPauseRecv{false};
700+
std::atomic_bool fPauseSend{false};
701701

702702
protected:
703703
mapMsgCmdSize mapSendBytesPerMsgCmd;
704704
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
705705

706706
public:
707707
uint256 hashContinue;
708-
std::atomic<int> nStartingHeight;
708+
std::atomic<int> nStartingHeight{-1};
709709

710710
// flood relay
711711
std::vector<CAddress> vAddrToSend;
712712
CRollingBloomFilter addrKnown;
713-
bool fGetAddr;
713+
bool fGetAddr{false};
714714
std::set<uint256> setKnown;
715-
int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing);
716-
int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing);
715+
int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing){0};
716+
int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing){0};
717717

718718
// inventory based relay
719719
CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_inventory);
@@ -727,35 +727,35 @@ class CNode
727727
CCriticalSection cs_inventory;
728728
std::set<uint256> setAskFor;
729729
std::multimap<int64_t, CInv> mapAskFor;
730-
int64_t nNextInvSend;
730+
int64_t nNextInvSend{0};
731731
// Used for headers announcements - unfiltered blocks to relay
732732
std::vector<uint256> vBlockHashesToAnnounce GUARDED_BY(cs_inventory);
733733
// Used for BIP35 mempool sending
734-
bool fSendMempool GUARDED_BY(cs_inventory);
734+
bool fSendMempool GUARDED_BY(cs_inventory){false};
735735

736736
// Last time a "MEMPOOL" request was serviced.
737-
std::atomic<int64_t> timeLastMempoolReq;
737+
std::atomic<int64_t> timeLastMempoolReq{0};
738738

739739
// Block and TXN accept times
740-
std::atomic<int64_t> nLastBlockTime;
741-
std::atomic<int64_t> nLastTXTime;
740+
std::atomic<int64_t> nLastBlockTime{0};
741+
std::atomic<int64_t> nLastTXTime{0};
742742

743743
// Ping time measurement:
744744
// The pong reply we're expecting, or 0 if no pong expected.
745-
std::atomic<uint64_t> nPingNonceSent;
745+
std::atomic<uint64_t> nPingNonceSent{0};
746746
// Time (in usec) the last ping was sent, or 0 if no ping was ever sent.
747-
std::atomic<int64_t> nPingUsecStart;
747+
std::atomic<int64_t> nPingUsecStart{0};
748748
// Last measured round-trip time.
749-
std::atomic<int64_t> nPingUsecTime;
749+
std::atomic<int64_t> nPingUsecTime{0};
750750
// Best measured round-trip time.
751-
std::atomic<int64_t> nMinPingUsecTime;
751+
std::atomic<int64_t> nMinPingUsecTime{std::numeric_limits<int64_t>::max()};
752752
// Whether a ping is requested.
753-
std::atomic<bool> fPingQueued;
753+
std::atomic<bool> fPingQueued{false};
754754
// Minimum fee rate with which to filter inv's to this node
755-
CAmount minFeeFilter GUARDED_BY(cs_feeFilter);
755+
CAmount minFeeFilter GUARDED_BY(cs_feeFilter){0};
756756
CCriticalSection cs_feeFilter;
757-
CAmount lastSentFeeFilter;
758-
int64_t nextSendTimeFeeFilter;
757+
CAmount lastSentFeeFilter{0};
758+
int64_t nextSendTimeFeeFilter{0};
759759

760760
CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn = "", bool fInboundIn = false);
761761
~CNode();
@@ -768,7 +768,7 @@ class CNode
768768
// Services offered to this peer
769769
const ServiceFlags nLocalServices;
770770
const int nMyStartingHeight;
771-
int nSendVersion;
771+
int nSendVersion{0};
772772
std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
773773

774774
mutable CCriticalSection cs_addrName;

0 commit comments

Comments
 (0)