From d45955fa0992639d6c9856a73c5f7599cc14f811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= Date: Tue, 24 Jan 2017 02:32:52 +0100 Subject: [PATCH 1/3] Net: CConnman: Make some methods const --- src/net.cpp | 6 +++--- src/net.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index df88b12c7..5a5d94cd1 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -754,7 +754,7 @@ const uint256& CNetMessage::GetMessageHash() const // requires LOCK(cs_vSend) -size_t CConnman::SocketSendData(CNode *pnode) +size_t CConnman::SocketSendData(CNode *pnode) const { auto it = pnode->vSendMsg.begin(); size_t nSentSize = 0; @@ -2687,12 +2687,12 @@ int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) { return nNow + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5); } -CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) +CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const { return CSipHasher(nSeed0, nSeed1).Write(id); } -uint64_t CConnman::CalculateKeyedNetGroup(const CAddress& ad) +uint64_t CConnman::CalculateKeyedNetGroup(const CAddress& ad) const { std::vector vchNetGroup(ad.GetGroup()); diff --git a/src/net.h b/src/net.h index 0b8efcc88..6228f7b50 100644 --- a/src/net.h +++ b/src/net.h @@ -321,7 +321,7 @@ public: int GetBestHeight() const; /** Get a unique deterministic randomizer. */ - CSipHasher GetDeterministicRandomizer(uint64_t id); + CSipHasher GetDeterministicRandomizer(uint64_t id) const; unsigned int GetReceiveFloodSize() const; @@ -342,7 +342,7 @@ private: void ThreadSocketHandler(); void ThreadDNSAddressSeed(); - uint64_t CalculateKeyedNetGroup(const CAddress& ad); + uint64_t CalculateKeyedNetGroup(const CAddress& ad) const; CNode* FindNode(const CNetAddr& ip); CNode* FindNode(const CSubNet& subNet); @@ -357,7 +357,7 @@ private: NodeId GetNewNodeId(); - size_t SocketSendData(CNode *pnode); + size_t SocketSendData(CNode *pnode) const; //!check is the banlist has unwritten changes bool BannedSetIsDirty(); //!set the "dirty" flag for the banlist From fc7f2ffad481870e62ab2f798f941577983c5a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= Date: Tue, 31 Jan 2017 22:57:40 +0100 Subject: [PATCH 2/3] Net: Make CNetMsgMaker more const --- src/net_processing.cpp | 10 +++++----- src/netmessagemaker.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index b9667eb6c..995779338 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -778,7 +778,7 @@ static uint256 most_recent_block_hash; void PeerLogicValidation::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr& pblock) { std::shared_ptr pcmpctblock = std::make_shared (*pblock, true); - CNetMsgMaker msgMaker(PROTOCOL_VERSION); + const CNetMsgMaker msgMaker(PROTOCOL_VERSION); LOCK(cs_main); @@ -960,7 +960,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam { std::deque::iterator it = pfrom->vRecvGetData.begin(); std::vector vNotFound; - CNetMsgMaker msgMaker(pfrom->GetSendVersion()); + const CNetMsgMaker msgMaker(pfrom->GetSendVersion()); LOCK(cs_main); while (it != pfrom->vRecvGetData.end()) { @@ -1153,7 +1153,7 @@ inline void static SendBlockTransactions(const CBlock& block, const BlockTransac resp.txn[i] = block.vtx[req.indexes[i]]; } LOCK(cs_main); - CNetMsgMaker msgMaker(pfrom->GetSendVersion()); + const CNetMsgMaker msgMaker(pfrom->GetSendVersion()); int nSendFlags = State(pfrom->GetId())->fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS; connman.PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::BLOCKTXN, resp)); } @@ -1346,7 +1346,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR } // At this point, the outgoing message serialization version can't change. - CNetMsgMaker msgMaker(pfrom->GetSendVersion()); + const CNetMsgMaker msgMaker(pfrom->GetSendVersion()); if (strCommand == NetMsgType::VERACK) { @@ -2721,7 +2721,7 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic& interruptMsg return true; // If we get here, the outgoing message serialization version is set and can't change. - CNetMsgMaker msgMaker(pto->GetSendVersion()); + const CNetMsgMaker msgMaker(pto->GetSendVersion()); // // Message: ping diff --git a/src/netmessagemaker.h b/src/netmessagemaker.h index 7167434a1..8e8a6e4a0 100644 --- a/src/netmessagemaker.h +++ b/src/netmessagemaker.h @@ -15,7 +15,7 @@ public: CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn){} template - CSerializedNetMsg Make(int nFlags, std::string sCommand, Args&&... args) + CSerializedNetMsg Make(int nFlags, std::string sCommand, Args&&... args) const { CSerializedNetMsg msg; msg.command = std::move(sCommand); @@ -24,7 +24,7 @@ public: } template - CSerializedNetMsg Make(std::string sCommand, Args&&... args) + CSerializedNetMsg Make(std::string sCommand, Args&&... args) const { return Make(0, std::move(sCommand), std::forward(args)...); } From 0729102f99241b9716456ad40bf778c09f650b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= Date: Tue, 31 Jan 2017 23:07:20 +0100 Subject: [PATCH 3/3] Net: pass interruptMsgProc as const where possible --- src/net_processing.cpp | 8 ++++---- src/net_processing.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 995779338..1cc86a662 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -956,7 +956,7 @@ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman& connma connman.ForEachNodeThen(std::move(sortfunc), std::move(pushfunc)); } -void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParams, CConnman& connman, std::atomic& interruptMsgProc) +void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParams, CConnman& connman, const std::atomic& interruptMsgProc) { std::deque::iterator it = pfrom->vRecvGetData.begin(); std::vector vNotFound; @@ -1158,7 +1158,7 @@ inline void static SendBlockTransactions(const CBlock& block, const BlockTransac connman.PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::BLOCKTXN, resp)); } -bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman& connman, std::atomic& interruptMsgProc) +bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman& connman, const std::atomic& interruptMsgProc) { LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); if (IsArgSet("-dropmessagestest") && GetRand(GetArg("-dropmessagestest", 0)) == 0) @@ -2579,7 +2579,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR return true; } -bool ProcessMessages(CNode* pfrom, CConnman& connman, std::atomic& interruptMsgProc) +bool ProcessMessages(CNode* pfrom, CConnman& connman, const std::atomic& interruptMsgProc) { const CChainParams& chainparams = Params(); // @@ -2712,7 +2712,7 @@ public: } }; -bool SendMessages(CNode* pto, CConnman& connman, std::atomic& interruptMsgProc) +bool SendMessages(CNode* pto, CConnman& connman, const std::atomic& interruptMsgProc) { const Consensus::Params& consensusParams = Params().GetConsensus(); { diff --git a/src/net_processing.h b/src/net_processing.h index 7351c0e99..9e3f1b715 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -49,7 +49,7 @@ bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats); void Misbehaving(NodeId nodeid, int howmuch); /** Process protocol messages received from a given node */ -bool ProcessMessages(CNode* pfrom, CConnman& connman, std::atomic& interrupt); +bool ProcessMessages(CNode* pfrom, CConnman& connman, const std::atomic& interrupt); /** * Send queued protocol messages to be sent to a give node. * @@ -58,6 +58,6 @@ bool ProcessMessages(CNode* pfrom, CConnman& connman, std::atomic& interru * @param[in] interrupt Interrupt condition for processing threads * @return True if there is more work to be done */ -bool SendMessages(CNode* pto, CConnman& connman, std::atomic& interrupt); +bool SendMessages(CNode* pto, CConnman& connman, const std::atomic& interrupt); #endif // BITCOIN_NET_PROCESSING_H