Skip to content

Commit 0d080a1

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#24141: Rename message_command variables in src/net* and src/rpc/net.cpp
e71c51b refactor: rename command -> message type in comments in the src/net* files (Shashwat) 2b09593 scripted-diff: Rename message command to message type (Shashwat) Pull request description: This PR is a follow-up to #24078. > a message is not a command, but simply a message of some type The first commit covers the message_command variable name and comments not addressed in the original PR in `src/net*` files. The second commit goes beyond the original `src/net*` limit of #24078 and does similar changes in the `src/rpc/net.cpp` file. ACKs for top commit: MarcoFalke: review ACK e71c51b 💥 Tree-SHA512: 24015d132c00f15239e5d3dc7aedae904ae3103a90920bb09e984ff57723402763f697d886322f78e42a0cb46808cb6bc9d4905561dc6ddee9961168f8324b05
2 parents d4475ea + e71c51b commit 0d080a1

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

src/net.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ enum BindFlags {
103103
// The sleep time needs to be small to avoid new sockets stalling
104104
static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50;
105105

106-
const std::string NET_MESSAGE_COMMAND_OTHER = "*other*";
106+
const std::string NET_MESSAGE_TYPE_OTHER = "*other*";
107107

108108
static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL; // SHA256("netgroup")[0:8]
109109
static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL; // SHA256("localhostnonce")[0:8]
@@ -643,12 +643,12 @@ void CNode::CopyStats(CNodeStats& stats)
643643
X(m_bip152_highbandwidth_from);
644644
{
645645
LOCK(cs_vSend);
646-
X(mapSendBytesPerMsgCmd);
646+
X(mapSendBytesPerMsgType);
647647
X(nSendBytes);
648648
}
649649
{
650650
LOCK(cs_vRecv);
651-
X(mapRecvBytesPerMsgCmd);
651+
X(mapRecvBytesPerMsgType);
652652
X(nRecvBytes);
653653
}
654654
X(m_permissionFlags);
@@ -684,19 +684,19 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
684684
bool reject_message{false};
685685
CNetMessage msg = m_deserializer->GetMessage(time, reject_message);
686686
if (reject_message) {
687-
// Message deserialization failed. Drop the message but don't disconnect the peer.
687+
// Message deserialization failed. Drop the message but don't disconnect the peer.
688688
// store the size of the corrupt message
689-
mapRecvBytesPerMsgCmd.at(NET_MESSAGE_COMMAND_OTHER) += msg.m_raw_message_size;
689+
mapRecvBytesPerMsgType.at(NET_MESSAGE_TYPE_OTHER) += msg.m_raw_message_size;
690690
continue;
691691
}
692692

693-
// Store received bytes per message command
694-
// to prevent a memory DOS, only allow valid commands
695-
auto i = mapRecvBytesPerMsgCmd.find(msg.m_type);
696-
if (i == mapRecvBytesPerMsgCmd.end()) {
697-
i = mapRecvBytesPerMsgCmd.find(NET_MESSAGE_COMMAND_OTHER);
693+
// Store received bytes per message type.
694+
// To prevent a memory DOS, only allow known message types.
695+
auto i = mapRecvBytesPerMsgType.find(msg.m_type);
696+
if (i == mapRecvBytesPerMsgType.end()) {
697+
i = mapRecvBytesPerMsgType.find(NET_MESSAGE_TYPE_OTHER);
698698
}
699-
assert(i != mapRecvBytesPerMsgCmd.end());
699+
assert(i != mapRecvBytesPerMsgType.end());
700700
i->second += msg.m_raw_message_size;
701701

702702
// push the message to the process queue,
@@ -781,7 +781,7 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds
781781
// decompose a single CNetMessage from the TransportDeserializer
782782
CNetMessage msg(std::move(vRecv));
783783

784-
// store command string, time, and sizes
784+
// store message type string, time, and sizes
785785
msg.m_type = hdr.GetCommand();
786786
msg.m_time = time;
787787
msg.m_message_size = hdr.nMessageSize;
@@ -792,7 +792,7 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds
792792
// We just received a message off the wire, harvest entropy from the time (and the message checksum)
793793
RandAddEvent(ReadLE32(hash.begin()));
794794

795-
// Check checksum and header command string
795+
// Check checksum and header message type string
796796
if (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) {
797797
LogPrint(BCLog::NET, "Header error: Wrong checksum (%s, %u bytes), expected %s was %s, peer=%d\n",
798798
SanitizeString(msg.m_type), msg.m_message_size,
@@ -3053,8 +3053,8 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, std::shared_ptr<Sock> s
30533053
if (inbound_onion) assert(conn_type_in == ConnectionType::INBOUND);
30543054

30553055
for (const std::string &msg : getAllNetMessageTypes())
3056-
mapRecvBytesPerMsgCmd[msg] = 0;
3057-
mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0;
3056+
mapRecvBytesPerMsgType[msg] = 0;
3057+
mapRecvBytesPerMsgType[NET_MESSAGE_TYPE_OTHER] = 0;
30583058

30593059
if (fLogIPs) {
30603060
LogPrint(BCLog::NET, "Added connection to %s peer=%d\n", m_addr_name, id);
@@ -3100,7 +3100,7 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
31003100
bool optimisticSend(pnode->vSendMsg.empty());
31013101

31023102
//log total amount of bytes per message type
3103-
pnode->mapSendBytesPerMsgCmd[msg.m_type] += nTotalSize;
3103+
pnode->mapSendBytesPerMsgType[msg.m_type] += nTotalSize;
31043104
pnode->nSendSize += nTotalSize;
31053105

31063106
if (pnode->nSendSize > nSendBufferMaxSize) pnode->fPauseSend = true;

src/net.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ struct LocalServiceInfo {
252252
extern Mutex g_maplocalhost_mutex;
253253
extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(g_maplocalhost_mutex);
254254

255-
extern const std::string NET_MESSAGE_COMMAND_OTHER;
256-
typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
255+
extern const std::string NET_MESSAGE_TYPE_OTHER;
256+
using mapMsgTypeSize = std::map</* message type */ std::string, /* total bytes */ uint64_t>;
257257

258258
class CNodeStats
259259
{
@@ -274,9 +274,9 @@ class CNodeStats
274274
bool m_bip152_highbandwidth_from;
275275
int m_starting_height;
276276
uint64_t nSendBytes;
277-
mapMsgCmdSize mapSendBytesPerMsgCmd;
277+
mapMsgTypeSize mapSendBytesPerMsgType;
278278
uint64_t nRecvBytes;
279-
mapMsgCmdSize mapRecvBytesPerMsgCmd;
279+
mapMsgTypeSize mapRecvBytesPerMsgType;
280280
NetPermissionFlags m_permissionFlags;
281281
std::chrono::microseconds m_last_ping_time;
282282
std::chrono::microseconds m_min_ping_time;
@@ -315,7 +315,7 @@ class CNetMessage {
315315

316316
/** The TransportDeserializer takes care of holding and deserializing the
317317
* network receive buffer. It can deserialize the network buffer into a
318-
* transport protocol agnostic CNetMessage (command & payload)
318+
* transport protocol agnostic CNetMessage (message type & payload)
319319
*/
320320
class TransportDeserializer {
321321
public:
@@ -686,8 +686,8 @@ class CNode
686686
CService addrLocal GUARDED_BY(m_addr_local_mutex);
687687
mutable Mutex m_addr_local_mutex;
688688

689-
mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend);
690-
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
689+
mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend);
690+
mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv);
691691
};
692692

693693
/**

src/rpc/net.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static RPCHelpMan getpeerinfo()
156156
{RPCResult::Type::NUM, "msg", "The total bytes received aggregated by message type\n"
157157
"When a message type is not listed in this json object, the bytes received are 0.\n"
158158
"Only known message types can appear as keys in the object and all bytes received\n"
159-
"of unknown message types are listed under '"+NET_MESSAGE_COMMAND_OTHER+"'."}
159+
"of unknown message types are listed under '"+NET_MESSAGE_TYPE_OTHER+"'."}
160160
}},
161161
{RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + ".\n"
162162
"Please note this output is unlikely to be stable in upcoming releases as we iterate to\n"
@@ -243,19 +243,19 @@ static RPCHelpMan getpeerinfo()
243243
}
244244
obj.pushKV("permissions", permissions);
245245

246-
UniValue sendPerMsgCmd(UniValue::VOBJ);
247-
for (const auto& i : stats.mapSendBytesPerMsgCmd) {
246+
UniValue sendPerMsgType(UniValue::VOBJ);
247+
for (const auto& i : stats.mapSendBytesPerMsgType) {
248248
if (i.second > 0)
249-
sendPerMsgCmd.pushKV(i.first, i.second);
249+
sendPerMsgType.pushKV(i.first, i.second);
250250
}
251-
obj.pushKV("bytessent_per_msg", sendPerMsgCmd);
251+
obj.pushKV("bytessent_per_msg", sendPerMsgType);
252252

253-
UniValue recvPerMsgCmd(UniValue::VOBJ);
254-
for (const auto& i : stats.mapRecvBytesPerMsgCmd) {
253+
UniValue recvPerMsgType(UniValue::VOBJ);
254+
for (const auto& i : stats.mapRecvBytesPerMsgType) {
255255
if (i.second > 0)
256-
recvPerMsgCmd.pushKV(i.first, i.second);
256+
recvPerMsgType.pushKV(i.first, i.second);
257257
}
258-
obj.pushKV("bytesrecv_per_msg", recvPerMsgCmd);
258+
obj.pushKV("bytesrecv_per_msg", recvPerMsgType);
259259
obj.pushKV("connection_type", ConnectionTypeAsString(stats.m_conn_type));
260260

261261
ret.push_back(obj);

0 commit comments

Comments
 (0)