Skip to content

Commit 09e0c28

Browse files
committed
Merge #9659: Net: Turn some methods and params/variables const
0729102 Net: pass interruptMsgProc as const where possible (Jorge Timón) fc7f2ff Net: Make CNetMsgMaker more const (Jorge Timón) d45955f Net: CConnman: Make some methods const (Jorge Timón)
2 parents 986ba00 + 0729102 commit 09e0c28

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

src/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ const uint256& CNetMessage::GetMessageHash() const
781781

782782

783783
// requires LOCK(cs_vSend)
784-
size_t CConnman::SocketSendData(CNode *pnode)
784+
size_t CConnman::SocketSendData(CNode *pnode) const
785785
{
786786
auto it = pnode->vSendMsg.begin();
787787
size_t nSentSize = 0;
@@ -2719,12 +2719,12 @@ int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) {
27192719
return nNow + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5);
27202720
}
27212721

2722-
CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id)
2722+
CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const
27232723
{
27242724
return CSipHasher(nSeed0, nSeed1).Write(id);
27252725
}
27262726

2727-
uint64_t CConnman::CalculateKeyedNetGroup(const CAddress& ad)
2727+
uint64_t CConnman::CalculateKeyedNetGroup(const CAddress& ad) const
27282728
{
27292729
std::vector<unsigned char> vchNetGroup(ad.GetGroup());
27302730

src/net.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class CConnman
281281
int GetBestHeight() const;
282282

283283
/** Get a unique deterministic randomizer. */
284-
CSipHasher GetDeterministicRandomizer(uint64_t id);
284+
CSipHasher GetDeterministicRandomizer(uint64_t id) const;
285285

286286
unsigned int GetReceiveFloodSize() const;
287287

@@ -302,7 +302,7 @@ class CConnman
302302
void ThreadSocketHandler();
303303
void ThreadDNSAddressSeed();
304304

305-
uint64_t CalculateKeyedNetGroup(const CAddress& ad);
305+
uint64_t CalculateKeyedNetGroup(const CAddress& ad) const;
306306

307307
CNode* FindNode(const CNetAddr& ip);
308308
CNode* FindNode(const CSubNet& subNet);
@@ -317,7 +317,7 @@ class CConnman
317317

318318
NodeId GetNewNodeId();
319319

320-
size_t SocketSendData(CNode *pnode);
320+
size_t SocketSendData(CNode *pnode) const;
321321
//!check is the banlist has unwritten changes
322322
bool BannedSetIsDirty();
323323
//!set the "dirty" flag for the banlist

src/net_processing.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ static uint256 most_recent_block_hash;
778778

779779
void PeerLogicValidation::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) {
780780
std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock, true);
781-
CNetMsgMaker msgMaker(PROTOCOL_VERSION);
781+
const CNetMsgMaker msgMaker(PROTOCOL_VERSION);
782782

783783
LOCK(cs_main);
784784

@@ -956,11 +956,11 @@ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman& connma
956956
connman.ForEachNodeThen(std::move(sortfunc), std::move(pushfunc));
957957
}
958958

959-
void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParams, CConnman& connman, std::atomic<bool>& interruptMsgProc)
959+
void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParams, CConnman& connman, const std::atomic<bool>& interruptMsgProc)
960960
{
961961
std::deque<CInv>::iterator it = pfrom->vRecvGetData.begin();
962962
std::vector<CInv> vNotFound;
963-
CNetMsgMaker msgMaker(pfrom->GetSendVersion());
963+
const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
964964
LOCK(cs_main);
965965

966966
while (it != pfrom->vRecvGetData.end()) {
@@ -1153,12 +1153,12 @@ inline void static SendBlockTransactions(const CBlock& block, const BlockTransac
11531153
resp.txn[i] = block.vtx[req.indexes[i]];
11541154
}
11551155
LOCK(cs_main);
1156-
CNetMsgMaker msgMaker(pfrom->GetSendVersion());
1156+
const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
11571157
int nSendFlags = State(pfrom->GetId())->fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
11581158
connman.PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::BLOCKTXN, resp));
11591159
}
11601160

1161-
bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman& connman, std::atomic<bool>& interruptMsgProc)
1161+
bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman& connman, const std::atomic<bool>& interruptMsgProc)
11621162
{
11631163
LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id);
11641164
if (IsArgSet("-dropmessagestest") && GetRand(GetArg("-dropmessagestest", 0)) == 0)
@@ -1354,7 +1354,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
13541354
}
13551355

13561356
// At this point, the outgoing message serialization version can't change.
1357-
CNetMsgMaker msgMaker(pfrom->GetSendVersion());
1357+
const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
13581358

13591359
if (strCommand == NetMsgType::VERACK)
13601360
{
@@ -2588,7 +2588,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
25882588
return true;
25892589
}
25902590

2591-
bool ProcessMessages(CNode* pfrom, CConnman& connman, std::atomic<bool>& interruptMsgProc)
2591+
bool ProcessMessages(CNode* pfrom, CConnman& connman, const std::atomic<bool>& interruptMsgProc)
25922592
{
25932593
const CChainParams& chainparams = Params();
25942594
//
@@ -2721,7 +2721,7 @@ class CompareInvMempoolOrder
27212721
}
27222722
};
27232723

2724-
bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsgProc)
2724+
bool SendMessages(CNode* pto, CConnman& connman, const std::atomic<bool>& interruptMsgProc)
27252725
{
27262726
const Consensus::Params& consensusParams = Params().GetConsensus();
27272727
{
@@ -2730,7 +2730,7 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsg
27302730
return true;
27312731

27322732
// If we get here, the outgoing message serialization version is set and can't change.
2733-
CNetMsgMaker msgMaker(pto->GetSendVersion());
2733+
const CNetMsgMaker msgMaker(pto->GetSendVersion());
27342734

27352735
//
27362736
// Message: ping

src/net_processing.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
4949
void Misbehaving(NodeId nodeid, int howmuch);
5050

5151
/** Process protocol messages received from a given node */
52-
bool ProcessMessages(CNode* pfrom, CConnman& connman, std::atomic<bool>& interrupt);
52+
bool ProcessMessages(CNode* pfrom, CConnman& connman, const std::atomic<bool>& interrupt);
5353
/**
5454
* Send queued protocol messages to be sent to a give node.
5555
*
@@ -58,6 +58,6 @@ bool ProcessMessages(CNode* pfrom, CConnman& connman, std::atomic<bool>& interru
5858
* @param[in] interrupt Interrupt condition for processing threads
5959
* @return True if there is more work to be done
6060
*/
61-
bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interrupt);
61+
bool SendMessages(CNode* pto, CConnman& connman, const std::atomic<bool>& interrupt);
6262

6363
#endif // BITCOIN_NET_PROCESSING_H

src/netmessagemaker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CNetMsgMaker
1515
CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn){}
1616

1717
template <typename... Args>
18-
CSerializedNetMsg Make(int nFlags, std::string sCommand, Args&&... args)
18+
CSerializedNetMsg Make(int nFlags, std::string sCommand, Args&&... args) const
1919
{
2020
CSerializedNetMsg msg;
2121
msg.command = std::move(sCommand);
@@ -24,7 +24,7 @@ class CNetMsgMaker
2424
}
2525

2626
template <typename... Args>
27-
CSerializedNetMsg Make(std::string sCommand, Args&&... args)
27+
CSerializedNetMsg Make(std::string sCommand, Args&&... args) const
2828
{
2929
return Make(0, std::move(sCommand), std::forward<Args>(args)...);
3030
}

0 commit comments

Comments
 (0)