Skip to content

Commit 2b09593

Browse files
committed
scripted-diff: Rename message command to message type
-BEGIN VERIFY SCRIPT- s1() { sed -i "s/$1/$2/g" $(git grep -l "$1" ./); } s1 'NET_MESSAGE_COMMAND_OTHER' 'NET_MESSAGE_TYPE_OTHER' s1 'mapMsgCmdSize' 'mapMsgTypeSize' s1 'mapRecvBytesPerMsgCmd' 'mapRecvBytesPerMsgType' s1 'mapSendBytesPerMsgCmd' 'mapSendBytesPerMsgType' s1 'recvPerMsgCmd' 'recvPerMsgType' s1 'sendPerMsgCmd' 'sendPerMsgType' -END VERIFY SCRIPT-
1 parent e3de7cb commit 2b09593

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

src/net.cpp

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

105-
const std::string NET_MESSAGE_COMMAND_OTHER = "*other*";
105+
const std::string NET_MESSAGE_TYPE_OTHER = "*other*";
106106

107107
static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL; // SHA256("netgroup")[0:8]
108108
static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL; // SHA256("localhostnonce")[0:8]
@@ -605,12 +605,12 @@ void CNode::CopyStats(CNodeStats& stats)
605605
X(m_bip152_highbandwidth_from);
606606
{
607607
LOCK(cs_vSend);
608-
X(mapSendBytesPerMsgCmd);
608+
X(mapSendBytesPerMsgType);
609609
X(nSendBytes);
610610
}
611611
{
612612
LOCK(cs_vRecv);
613-
X(mapRecvBytesPerMsgCmd);
613+
X(mapRecvBytesPerMsgType);
614614
X(nRecvBytes);
615615
}
616616
X(m_permissionFlags);
@@ -653,17 +653,17 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
653653
if (reject_message) {
654654
// Message deserialization failed. Drop the message but don't disconnect the peer.
655655
// store the size of the corrupt message
656-
mapRecvBytesPerMsgCmd.at(NET_MESSAGE_COMMAND_OTHER) += msg.m_raw_message_size;
656+
mapRecvBytesPerMsgType.at(NET_MESSAGE_TYPE_OTHER) += msg.m_raw_message_size;
657657
continue;
658658
}
659659

660660
// Store received bytes per message command
661661
// to prevent a memory DOS, only allow valid commands
662-
auto i = mapRecvBytesPerMsgCmd.find(msg.m_type);
663-
if (i == mapRecvBytesPerMsgCmd.end()) {
664-
i = mapRecvBytesPerMsgCmd.find(NET_MESSAGE_COMMAND_OTHER);
662+
auto i = mapRecvBytesPerMsgType.find(msg.m_type);
663+
if (i == mapRecvBytesPerMsgType.end()) {
664+
i = mapRecvBytesPerMsgType.find(NET_MESSAGE_TYPE_OTHER);
665665
}
666-
assert(i != mapRecvBytesPerMsgCmd.end());
666+
assert(i != mapRecvBytesPerMsgType.end());
667667
i->second += msg.m_raw_message_size;
668668

669669
// push the message to the process queue,
@@ -2983,8 +2983,8 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
29832983
}
29842984

29852985
for (const std::string &msg : getAllNetMessageTypes())
2986-
mapRecvBytesPerMsgCmd[msg] = 0;
2987-
mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0;
2986+
mapRecvBytesPerMsgType[msg] = 0;
2987+
mapRecvBytesPerMsgType[NET_MESSAGE_TYPE_OTHER] = 0;
29882988

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

30363036
//log total amount of bytes per message type
3037-
pnode->mapSendBytesPerMsgCmd[msg.m_type] += nTotalSize;
3037+
pnode->mapSendBytesPerMsgType[msg.m_type] += nTotalSize;
30383038
pnode->nSendSize += nTotalSize;
30393039

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

src/net.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ struct LocalServiceInfo {
233233
extern Mutex g_maplocalhost_mutex;
234234
extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(g_maplocalhost_mutex);
235235

236-
extern const std::string NET_MESSAGE_COMMAND_OTHER;
237-
typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
236+
extern const std::string NET_MESSAGE_TYPE_OTHER;
237+
typedef std::map<std::string, uint64_t> mapMsgTypeSize; //command, total bytes
238238

239239
class CNodeStats
240240
{
@@ -256,9 +256,9 @@ class CNodeStats
256256
bool m_bip152_highbandwidth_from;
257257
int m_starting_height;
258258
uint64_t nSendBytes;
259-
mapMsgCmdSize mapSendBytesPerMsgCmd;
259+
mapMsgTypeSize mapSendBytesPerMsgType;
260260
uint64_t nRecvBytes;
261-
mapMsgCmdSize mapRecvBytesPerMsgCmd;
261+
mapMsgTypeSize mapRecvBytesPerMsgType;
262262
NetPermissionFlags m_permissionFlags;
263263
std::chrono::microseconds m_last_ping_time;
264264
std::chrono::microseconds m_min_ping_time;
@@ -696,8 +696,8 @@ class CNode
696696
CService addrLocal GUARDED_BY(m_addr_local_mutex);
697697
mutable Mutex m_addr_local_mutex;
698698

699-
mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend);
700-
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
699+
mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend);
700+
mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv);
701701
};
702702

703703
/**

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
obj.pushKV("permissions", permissions);
244244
obj.pushKV("minfeefilter", ValueFromAmount(stats.minFeeFilter));
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)