diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -637,13 +637,13 @@ public: // socket - std::atomic nServices; + std::atomic nServices{NODE_NONE}; SOCKET hSocket GUARDED_BY(cs_hSocket); // Total size of all vSendMsg entries. - size_t nSendSize; + size_t nSendSize{0}; // Offset inside the first vSendMsg already sent. - size_t nSendOffset; - uint64_t nSendBytes GUARDED_BY(cs_vSend); + size_t nSendOffset{0}; + uint64_t nSendBytes GUARDED_BY(cs_vSend){0}; std::deque> vSendMsg GUARDED_BY(cs_vSend); CCriticalSection cs_vSend; CCriticalSection cs_hSocket; @@ -651,23 +651,23 @@ CCriticalSection cs_vProcessMsg; std::list vProcessMsg GUARDED_BY(cs_vProcessMsg); - size_t nProcessQueueSize; + size_t nProcessQueueSize{0}; CCriticalSection cs_sendProcessing; std::deque vRecvGetData; - uint64_t nRecvBytes GUARDED_BY(cs_vRecv); - std::atomic nRecvVersion; + uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0}; + std::atomic nRecvVersion{INIT_PROTO_VERSION}; - std::atomic nLastSend; - std::atomic nLastRecv; + std::atomic nLastSend{0}; + std::atomic nLastRecv{0}; const int64_t nTimeConnected; - std::atomic nTimeOffset; + std::atomic nTimeOffset{0}; // Address of this peer const CAddress addr; // Bind address of our side of the connection const CAddress addrBind; - std::atomic nVersion; + std::atomic nVersion{0}; // strSubVer is whatever byte array we read from the wire. However, this // field is intended to be printed out, displayed to humans in various forms // and so on. So we sanitize it and store the sanitized version in @@ -678,33 +678,33 @@ // Used for both cleanSubVer and strSubVer. CCriticalSection cs_SubVer; // This peer can bypass DoS banning. - bool fWhitelisted; + bool fWhitelisted{false}; // If true this node is being used as a short lived feeler. - bool fFeeler; - bool fOneShot; - bool m_manual_connection; - bool fClient; - // after BIP159 - bool m_limited_node; + bool fFeeler{false}; + bool fOneShot{false}; + bool m_manual_connection{false}; + // set by version message + bool fClient{false}; + // after BIP159, set by version message + bool m_limited_node{false}; const bool fInbound; - std::atomic_bool fSuccessfullyConnected; - std::atomic_bool fDisconnect; + std::atomic_bool fSuccessfullyConnected{false}; + std::atomic_bool fDisconnect{false}; // We use fRelayTxes for two purposes - // a) it allows us to not relay tx invs before receiving the peer's version // message. // b) the peer may tell us in its version message that we should not relay // tx invs unless it loads a bloom filter. - - bool fRelayTxes GUARDED_BY(cs_filter); - bool fSentAddr; + bool fRelayTxes GUARDED_BY(cs_filter){false}; + bool fSentAddr{false}; CSemaphoreGrant grantOutbound; mutable CCriticalSection cs_filter; std::unique_ptr pfilter PT_GUARDED_BY(cs_filter); - std::atomic nRefCount; + std::atomic nRefCount{0}; const uint64_t nKeyedNetGroup; - std::atomic_bool fPauseRecv; - std::atomic_bool fPauseSend; + std::atomic_bool fPauseRecv{false}; + std::atomic_bool fPauseSend{false}; protected: mapMsgCmdSize mapSendBytesPerMsgCmd; @@ -712,15 +712,15 @@ public: uint256 hashContinue; - std::atomic nStartingHeight; + std::atomic nStartingHeight{-1}; // flood relay std::vector vAddrToSend; CRollingBloomFilter addrKnown; - bool fGetAddr; + bool fGetAddr{false}; std::set setKnown; - int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing); - int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing); + int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing){0}; + int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing){0}; // Inventory based relay. CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_inventory); @@ -734,35 +734,35 @@ CCriticalSection cs_inventory; std::set setAskFor; std::multimap mapAskFor; - int64_t nNextInvSend; + int64_t nNextInvSend{0}; // Used for headers announcements - unfiltered blocks to relay. std::vector vBlockHashesToAnnounce GUARDED_BY(cs_inventory); // Used for BIP35 mempool sending. - bool fSendMempool GUARDED_BY(cs_inventory); + bool fSendMempool GUARDED_BY(cs_inventory){false}; // Last time a "MEMPOOL" request was serviced. - std::atomic timeLastMempoolReq; + std::atomic timeLastMempoolReq{0}; // Block and TXN accept times - std::atomic nLastBlockTime; - std::atomic nLastTXTime; + std::atomic nLastBlockTime{0}; + std::atomic nLastTXTime{0}; // Ping time measurement: // The pong reply we're expecting, or 0 if no pong expected. - std::atomic nPingNonceSent; + std::atomic nPingNonceSent{0}; // Time (in usec) the last ping was sent, or 0 if no ping was ever sent. - std::atomic nPingUsecStart; + std::atomic nPingUsecStart{0}; // Last measured round-trip time. - std::atomic nPingUsecTime; + std::atomic nPingUsecTime{0}; // Best measured round-trip time. - std::atomic nMinPingUsecTime; + std::atomic nMinPingUsecTime{std::numeric_limits::max()}; // Whether a ping is requested. - std::atomic fPingQueued; + std::atomic fPingQueued{false}; // Minimum fee rate with which to filter inv's to this node - Amount minFeeFilter GUARDED_BY(cs_feeFilter); + Amount minFeeFilter GUARDED_BY(cs_feeFilter){Amount::zero()}; CCriticalSection cs_feeFilter; - Amount lastSentFeeFilter; - int64_t nextSendTimeFeeFilter; + Amount lastSentFeeFilter{Amount::zero()}; + int64_t nextSendTimeFeeFilter{0}; CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, @@ -778,7 +778,7 @@ // Services offered to this peer const ServiceFlags nLocalServices; const int nMyStartingHeight; - int nSendVersion; + int nSendVersion{0}; // Used only by SocketHandler thread. std::list vRecvMsg; diff --git a/src/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -2889,56 +2889,13 @@ nKeyedNetGroup(nKeyedNetGroupIn), addrKnown(5000, 0.001), filterInventoryKnown(50000, 0.000001), id(idIn), nLocalHostNonce(nLocalHostNonceIn), nLocalServices(nLocalServicesIn), - nMyStartingHeight(nMyStartingHeightIn), nSendVersion(0) { - nServices = NODE_NONE; + nMyStartingHeight(nMyStartingHeightIn) { hSocket = hSocketIn; - nRecvVersion = INIT_PROTO_VERSION; - nLastSend = 0; - nLastRecv = 0; - nSendBytes = 0; - nRecvBytes = 0; - nTimeOffset = 0; addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn; - nVersion = 0; strSubVer = ""; - fWhitelisted = false; - fOneShot = false; - m_manual_connection = false; - // set by version message - fClient = false; - // set by version message - m_limited_node = false; - fFeeler = false; - fSuccessfullyConnected = false; - fDisconnect = false; - nRefCount = 0; - nSendSize = 0; - nSendOffset = 0; hashContinue = uint256(); - nStartingHeight = -1; filterInventoryKnown.reset(); - fSendMempool = false; - fGetAddr = false; - nNextLocalAddrSend = 0; - nNextAddrSend = 0; - nNextInvSend = 0; - fRelayTxes = false; - fSentAddr = false; pfilter = std::make_unique(); - timeLastMempoolReq = 0; - nLastBlockTime = 0; - nLastTXTime = 0; - nPingNonceSent = 0; - nPingUsecStart = 0; - nPingUsecTime = 0; - fPingQueued = false; - nMinPingUsecTime = std::numeric_limits::max(); - minFeeFilter = Amount::zero(); - lastSentFeeFilter = Amount::zero(); - nextSendTimeFeeFilter = 0; - fPauseRecv = false; - fPauseSend = false; - nProcessQueueSize = 0; for (const std::string &msg : getAllNetMessageTypes()) { mapRecvBytesPerMsgCmd[msg] = 0;