merge bitcoin#24141: Rename message_command variables in src/net* and src/rpc/net.cpp

This commit is contained in:
Kittywhiskers Van Gogh 2022-04-07 17:13:52 +05:30
parent a6aa3735be
commit b9b13bd8ec
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
3 changed files with 38 additions and 38 deletions

View File

@ -125,7 +125,7 @@ static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50;
static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 500;
#endif /* USE_WAKEUP_PIPE */
const std::string NET_MESSAGE_COMMAND_OTHER = "*other*";
const std::string NET_MESSAGE_TYPE_OTHER = "*other*";
constexpr const CConnman::CFullyConnectedOnly CConnman::FullyConnectedOnly;
constexpr const CConnman::CAllNodes CConnman::AllNodes;
@ -755,12 +755,12 @@ void CNode::CopyStats(CNodeStats& stats)
X(m_bip152_highbandwidth_from);
{
LOCK(cs_vSend);
X(mapSendBytesPerMsgCmd);
X(mapSendBytesPerMsgType);
X(nSendBytes);
}
{
LOCK(cs_vRecv);
X(mapRecvBytesPerMsgCmd);
X(mapRecvBytesPerMsgType);
X(nRecvBytes);
}
X(m_legacyWhitelisted);
@ -804,19 +804,19 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
bool reject_message{false};
CNetMessage msg = m_deserializer->GetMessage(time, 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
mapRecvBytesPerMsgCmd.at(NET_MESSAGE_COMMAND_OTHER) += msg.m_raw_message_size;
mapRecvBytesPerMsgType.at(NET_MESSAGE_TYPE_OTHER) += msg.m_raw_message_size;
continue;
}
// Store received bytes per message command
// to prevent a memory DOS, only allow valid commands
auto i = mapRecvBytesPerMsgCmd.find(msg.m_type);
if (i == mapRecvBytesPerMsgCmd.end()) {
i = mapRecvBytesPerMsgCmd.find(NET_MESSAGE_COMMAND_OTHER);
// Store received bytes per message type.
// To prevent a memory DOS, only allow known message types.
auto i = mapRecvBytesPerMsgType.find(msg.m_type);
if (i == mapRecvBytesPerMsgType.end()) {
i = mapRecvBytesPerMsgType.find(NET_MESSAGE_TYPE_OTHER);
}
assert(i != mapRecvBytesPerMsgCmd.end());
assert(i != mapRecvBytesPerMsgType.end());
i->second += msg.m_raw_message_size;
statsClient.count("bandwidth.message." + std::string(msg.m_type) + ".bytesReceived", msg.m_raw_message_size, 1.0f);
@ -902,7 +902,7 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds
// decompose a single CNetMessage from the TransportDeserializer
CNetMessage msg(std::move(vRecv));
// store command string, time, and sizes
// store message type string, time, and sizes
msg.m_type = hdr.GetCommand();
msg.m_time = time;
msg.m_message_size = hdr.nMessageSize;
@ -913,7 +913,7 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds
// We just received a message off the wire, harvest entropy from the time (and the message checksum)
RandAddEvent(ReadLE32(hash.begin()));
// Check checksum and header command string
// Check checksum and header message type string
if (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) {
LogPrint(BCLog::NET, "Header error: Wrong checksum (%s, %u bytes), expected %s was %s, peer=%d\n",
SanitizeString(msg.m_type), msg.m_message_size,
@ -1625,24 +1625,24 @@ void CConnman::CalculateNumConnectionsChangedStats()
int ipv4Nodes = 0;
int ipv6Nodes = 0;
int torNodes = 0;
mapMsgCmdSize mapRecvBytesMsgStats;
mapMsgCmdSize mapSentBytesMsgStats;
mapMsgTypeSize mapRecvBytesMsgStats;
mapMsgTypeSize mapSentBytesMsgStats;
for (const std::string &msg : getAllNetMessageTypes()) {
mapRecvBytesMsgStats[msg] = 0;
mapSentBytesMsgStats[msg] = 0;
}
mapRecvBytesMsgStats[NET_MESSAGE_COMMAND_OTHER] = 0;
mapSentBytesMsgStats[NET_MESSAGE_COMMAND_OTHER] = 0;
mapRecvBytesMsgStats[NET_MESSAGE_TYPE_OTHER] = 0;
mapSentBytesMsgStats[NET_MESSAGE_TYPE_OTHER] = 0;
const NodesSnapshot snap{*this, /* filter = */ CConnman::FullyConnectedOnly};
for (auto pnode : snap.Nodes()) {
{
LOCK(pnode->cs_vRecv);
for (const mapMsgCmdSize::value_type &i : pnode->mapRecvBytesPerMsgCmd)
for (const mapMsgTypeSize::value_type &i : pnode->mapRecvBytesPerMsgType)
mapRecvBytesMsgStats[i.first] += i.second;
}
{
LOCK(pnode->cs_vSend);
for (const mapMsgCmdSize::value_type &i : pnode->mapSendBytesPerMsgCmd)
for (const mapMsgTypeSize::value_type &i : pnode->mapSendBytesPerMsgType)
mapSentBytesMsgStats[i.first] += i.second;
}
if(pnode->fClient)
@ -4142,8 +4142,8 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, std::shared_ptr<Sock> s
if (inbound_onion) assert(conn_type_in == ConnectionType::INBOUND);
for (const std::string &msg : getAllNetMessageTypes())
mapRecvBytesPerMsgCmd[msg] = 0;
mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0;
mapRecvBytesPerMsgType[msg] = 0;
mapRecvBytesPerMsgType[NET_MESSAGE_TYPE_OTHER] = 0;
if (fLogIPs) {
LogPrint(BCLog::NET, "Added connection to %s peer=%d\n", m_addr_name, id);
@ -4182,7 +4182,7 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
bool hasPendingData = !pnode->vSendMsg.empty();
//log total amount of bytes per message type
pnode->mapSendBytesPerMsgCmd[msg.m_type] += nTotalSize;
pnode->mapSendBytesPerMsgType[msg.m_type] += nTotalSize;
pnode->nSendSize += nTotalSize;
if (pnode->nSendSize > nSendBufferMaxSize) pnode->fPauseSend = true;

View File

@ -274,8 +274,8 @@ struct LocalServiceInfo {
extern Mutex g_maplocalhost_mutex;
extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(g_maplocalhost_mutex);
extern const std::string NET_MESSAGE_COMMAND_OTHER;
typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
extern const std::string NET_MESSAGE_TYPE_OTHER;
using mapMsgTypeSize = std::map</* message type */ std::string, /* total bytes */ uint64_t>;
class CNodeStats
{
@ -297,9 +297,9 @@ public:
bool m_bip152_highbandwidth_from;
int m_starting_height;
uint64_t nSendBytes;
mapMsgCmdSize mapSendBytesPerMsgCmd;
mapMsgTypeSize mapSendBytesPerMsgType;
uint64_t nRecvBytes;
mapMsgCmdSize mapRecvBytesPerMsgCmd;
mapMsgTypeSize mapRecvBytesPerMsgType;
NetPermissionFlags m_permissionFlags;
bool m_legacyWhitelisted;
std::chrono::microseconds m_last_ping_time;
@ -344,7 +344,7 @@ public:
/** The TransportDeserializer takes care of holding and deserializing the
* network receive buffer. It can deserialize the network buffer into a
* transport protocol agnostic CNetMessage (command & payload)
* transport protocol agnostic CNetMessage (message type & payload)
*/
class TransportDeserializer {
public:
@ -799,8 +799,8 @@ private:
uint256 verifiedProRegTxHash GUARDED_BY(cs_mnauth);
uint256 verifiedPubKeyHash GUARDED_BY(cs_mnauth);
mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend);
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend);
mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv);
/**
* If an I2P session is created per connection (for outbound transient I2P

View File

@ -177,7 +177,7 @@ static RPCHelpMan getpeerinfo()
{
{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"
"Only known message types can appear as keys in the object and all bytes received of unknown message types are listed under '"+NET_MESSAGE_COMMAND_OTHER+"'."}
"Only known message types can appear as keys in the object and all bytes received 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"
"Please note this output is unlikely to be stable in upcoming releases as we iterate to\n"
@ -281,19 +281,19 @@ static RPCHelpMan getpeerinfo()
}
obj.pushKV("permissions", permissions);
UniValue sendPerMsgCmd(UniValue::VOBJ);
for (const auto& i : stats.mapSendBytesPerMsgCmd) {
UniValue sendPerMsgType(UniValue::VOBJ);
for (const auto& i : stats.mapSendBytesPerMsgType) {
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);
for (const auto& i : stats.mapRecvBytesPerMsgCmd) {
UniValue recvPerMsgType(UniValue::VOBJ);
for (const auto& i : stats.mapRecvBytesPerMsgType) {
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));
ret.push_back(obj);