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-
This commit is contained in:
Shashwat committed 2022-04-07 17:22:36 +05:30
1 parent e3de7cb903
commit 2b09593bdd
3 files changed
+26 -26

No files matched your search

+11 -11
View File
@@ -102,7 +102,7 @@ enum BindFlags {
// The sleep time needs to be small to avoid new sockets stalling // The sleep time needs to be small to avoid new sockets stalling
static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50; static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50;
const std::string NET_MESSAGE_COMMAND_OTHER = "*other*"; const std::string NET_MESSAGE_TYPE_OTHER = "*other*";
static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL; // SHA256("netgroup")[0:8] static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL; // SHA256("netgroup")[0:8]
static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL; // SHA256("localhostnonce")[0:8] static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL; // SHA256("localhostnonce")[0:8]
@@ -605,12 +605,12 @@ void CNode::CopyStats(CNodeStats& stats)
X(m_bip152_highbandwidth_from); X(m_bip152_highbandwidth_from);
{ {
LOCK(cs_vSend); LOCK(cs_vSend);
X(mapSendBytesPerMsgCmd); X(mapSendBytesPerMsgType);
X(nSendBytes); X(nSendBytes);
} }
{ {
LOCK(cs_vRecv); LOCK(cs_vRecv);
X(mapRecvBytesPerMsgCmd); X(mapRecvBytesPerMsgType);
X(nRecvBytes); X(nRecvBytes);
} }
X(m_permissionFlags); X(m_permissionFlags);
@@ -653,17 +653,17 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
if (reject_message) { if (reject_message) {
// Message deserialization failed. Drop the message but don't disconnect the peer. // Message deserialization failed. Drop the message but don't disconnect the peer.
// store the size of the corrupt message // store the size of the corrupt message
mapRecvBytesPerMsgCmd.at(NET_MESSAGE_COMMAND_OTHER) += msg.m_raw_message_size; mapRecvBytesPerMsgType.at(NET_MESSAGE_TYPE_OTHER) += msg.m_raw_message_size;
continue; continue;
} }
// Store received bytes per message command // Store received bytes per message command
// to prevent a memory DOS, only allow valid commands // to prevent a memory DOS, only allow valid commands
auto i = mapRecvBytesPerMsgCmd.find(msg.m_type); auto i = mapRecvBytesPerMsgType.find(msg.m_type);
if (i == mapRecvBytesPerMsgCmd.end()) { if (i == mapRecvBytesPerMsgType.end()) {
i = mapRecvBytesPerMsgCmd.find(NET_MESSAGE_COMMAND_OTHER); i = mapRecvBytesPerMsgType.find(NET_MESSAGE_TYPE_OTHER);
} }
assert(i != mapRecvBytesPerMsgCmd.end()); assert(i != mapRecvBytesPerMsgType.end());
i->second += msg.m_raw_message_size; i->second += msg.m_raw_message_size;
// push the message to the process queue, // push the message to the process queue,
@@ -2983,8 +2983,8 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
} }
for (const std::string &msg : getAllNetMessageTypes()) for (const std::string &msg : getAllNetMessageTypes())
mapRecvBytesPerMsgCmd[msg] = 0; mapRecvBytesPerMsgType[msg] = 0;
mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0; mapRecvBytesPerMsgType[NET_MESSAGE_TYPE_OTHER] = 0;
if (fLogIPs) { if (fLogIPs) {
LogPrint(BCLog::NET, "Added connection to %s peer=%d\n", m_addr_name, id); 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)
bool optimisticSend(pnode->vSendMsg.empty()); bool optimisticSend(pnode->vSendMsg.empty());
//log total amount of bytes per message type //log total amount of bytes per message type
pnode->mapSendBytesPerMsgCmd[msg.m_type] += nTotalSize; pnode->mapSendBytesPerMsgType[msg.m_type] += nTotalSize;
pnode->nSendSize += nTotalSize; pnode->nSendSize += nTotalSize;
if (pnode->nSendSize > nSendBufferMaxSize) pnode->fPauseSend = true; if (pnode->nSendSize > nSendBufferMaxSize) pnode->fPauseSend = true;
+6 -6
View File
@@ -233,8 +233,8 @@ struct LocalServiceInfo {
extern Mutex g_maplocalhost_mutex; extern Mutex g_maplocalhost_mutex;
extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(g_maplocalhost_mutex); extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(g_maplocalhost_mutex);
extern const std::string NET_MESSAGE_COMMAND_OTHER; extern const std::string NET_MESSAGE_TYPE_OTHER;
typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes typedef std::map<std::string, uint64_t> mapMsgTypeSize; //command, total bytes
class CNodeStats class CNodeStats
{ {
@@ -256,9 +256,9 @@ public:
bool m_bip152_highbandwidth_from; bool m_bip152_highbandwidth_from;
int m_starting_height; int m_starting_height;
uint64_t nSendBytes; uint64_t nSendBytes;
mapMsgCmdSize mapSendBytesPerMsgCmd; mapMsgTypeSize mapSendBytesPerMsgType;
uint64_t nRecvBytes; uint64_t nRecvBytes;
mapMsgCmdSize mapRecvBytesPerMsgCmd; mapMsgTypeSize mapRecvBytesPerMsgType;
NetPermissionFlags m_permissionFlags; NetPermissionFlags m_permissionFlags;
std::chrono::microseconds m_last_ping_time; std::chrono::microseconds m_last_ping_time;
std::chrono::microseconds m_min_ping_time; std::chrono::microseconds m_min_ping_time;
@@ -696,8 +696,8 @@ private:
CService addrLocal GUARDED_BY(m_addr_local_mutex); CService addrLocal GUARDED_BY(m_addr_local_mutex);
mutable Mutex m_addr_local_mutex; mutable Mutex m_addr_local_mutex;
mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend); mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend);
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv); mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv);
}; };
/** /**
+9 -9
View File
@@ -156,7 +156,7 @@ static RPCHelpMan getpeerinfo()
{RPCResult::Type::NUM, "msg", "The total bytes received aggregated by message type\n" {RPCResult::Type::NUM, "msg", "The total bytes received aggregated by message type\n"
"When a message type is not listed in this json object, the bytes received are 0.\n" "When a message type is not listed in this json object, the bytes received are 0.\n"
"Only known message types can appear as keys in the object and all bytes received\n" "Only known message types can appear as keys in the object and all bytes received\n"
"of unknown message types are listed under '"+NET_MESSAGE_COMMAND_OTHER+"'."} "of unknown message types are listed under '"+NET_MESSAGE_TYPE_OTHER+"'."}
}}, }},
{RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + ".\n" {RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + ".\n"
"Please note this output is unlikely to be stable in upcoming releases as we iterate to\n" "Please note this output is unlikely to be stable in upcoming releases as we iterate to\n"
@@ -243,19 +243,19 @@ static RPCHelpMan getpeerinfo()
obj.pushKV("permissions", permissions); obj.pushKV("permissions", permissions);
obj.pushKV("minfeefilter", ValueFromAmount(stats.minFeeFilter)); obj.pushKV("minfeefilter", ValueFromAmount(stats.minFeeFilter));
UniValue sendPerMsgCmd(UniValue::VOBJ); UniValue sendPerMsgType(UniValue::VOBJ);
for (const auto& i : stats.mapSendBytesPerMsgCmd) { for (const auto& i : stats.mapSendBytesPerMsgType) {
if (i.second > 0) if (i.second > 0)
sendPerMsgCmd.pushKV(i.first, i.second); sendPerMsgType.pushKV(i.first, i.second);
} }
obj.pushKV("bytessent_per_msg", sendPerMsgCmd); obj.pushKV("bytessent_per_msg", sendPerMsgType);
UniValue recvPerMsgCmd(UniValue::VOBJ); UniValue recvPerMsgType(UniValue::VOBJ);
for (const auto& i : stats.mapRecvBytesPerMsgCmd) { for (const auto& i : stats.mapRecvBytesPerMsgType) {
if (i.second > 0) if (i.second > 0)
recvPerMsgCmd.pushKV(i.first, i.second); recvPerMsgType.pushKV(i.first, i.second);
} }
obj.pushKV("bytesrecv_per_msg", recvPerMsgCmd); obj.pushKV("bytesrecv_per_msg", recvPerMsgType);
obj.pushKV("connection_type", ConnectionTypeAsString(stats.m_conn_type)); obj.pushKV("connection_type", ConnectionTypeAsString(stats.m_conn_type));
ret.push_back(obj); ret.push_back(obj);