mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Merge #20786: net: [refactor] Prefer integral types in CNodeStats
faecb74562
Expose integral m_conn_type in CNodeStats, remove m_conn_type_string (Jon Atack) Pull request description: Currently, strings are stored for what are actually integral (strong) enum types. This is fine, because the strings are only used as-is for the debug log and RPC. However, it complicates using them in the GUI. User facing strings in the GUI should be translated and only string literals can be picked up for translation, not runtime `std::string`s. Fix that by removing the `std::string` members and replace them by strong enum integral types. ACKs for top commit: jonatack: Code review ACKfaecb74562
theStack: Code review ACKfaecb74562
🌲 Tree-SHA512: 24df2bd0645432060e393eb44b8abaf20fe296457d07a867b0e735c3e2e75af7b03fc6bfeca734ec33ab816a7c8e1f8591a5ec342f3afe3098a4e41f5c2cfebb
This commit is contained in:
commit
9158d6f341
3 changed files with 8 additions and 7 deletions
|
@ -498,9 +498,9 @@ void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CNode::ConnectionTypeAsString() const
|
std::string ConnectionTypeAsString(ConnectionType conn_type)
|
||||||
{
|
{
|
||||||
switch (m_conn_type) {
|
switch (conn_type) {
|
||||||
case ConnectionType::INBOUND:
|
case ConnectionType::INBOUND:
|
||||||
return "inbound";
|
return "inbound";
|
||||||
case ConnectionType::MANUAL:
|
case ConnectionType::MANUAL:
|
||||||
|
@ -618,7 +618,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
|
||||||
CService addrLocalUnlocked = GetAddrLocal();
|
CService addrLocalUnlocked = GetAddrLocal();
|
||||||
stats.addrLocal = addrLocalUnlocked.IsValid() ? addrLocalUnlocked.ToString() : "";
|
stats.addrLocal = addrLocalUnlocked.IsValid() ? addrLocalUnlocked.ToString() : "";
|
||||||
|
|
||||||
stats.m_conn_type_string = ConnectionTypeAsString();
|
X(m_conn_type);
|
||||||
}
|
}
|
||||||
#undef X
|
#undef X
|
||||||
|
|
||||||
|
|
|
@ -174,6 +174,8 @@ enum class ConnectionType {
|
||||||
ADDR_FETCH,
|
ADDR_FETCH,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Convert ConnectionType enum to a string value */
|
||||||
|
std::string ConnectionTypeAsString(ConnectionType conn_type);
|
||||||
void Discover();
|
void Discover();
|
||||||
uint16_t GetListenPort();
|
uint16_t GetListenPort();
|
||||||
|
|
||||||
|
@ -264,11 +266,10 @@ public:
|
||||||
// Network the peer connected through
|
// Network the peer connected through
|
||||||
Network m_network;
|
Network m_network;
|
||||||
uint32_t m_mapped_as;
|
uint32_t m_mapped_as;
|
||||||
std::string m_conn_type_string;
|
ConnectionType m_conn_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Transport protocol agnostic message container.
|
/** Transport protocol agnostic message container.
|
||||||
* Ideally it should only contain receive time, payload,
|
* Ideally it should only contain receive time, payload,
|
||||||
* command and size.
|
* command and size.
|
||||||
|
@ -756,7 +757,7 @@ public:
|
||||||
//! Sets the addrName only if it was not previously set
|
//! Sets the addrName only if it was not previously set
|
||||||
void MaybeSetAddrName(const std::string& addrNameIn);
|
void MaybeSetAddrName(const std::string& addrNameIn);
|
||||||
|
|
||||||
std::string ConnectionTypeAsString() const;
|
std::string ConnectionTypeAsString() const { return ::ConnectionTypeAsString(m_conn_type); }
|
||||||
|
|
||||||
/** Whether this peer is an inbound onion, e.g. connected via our Tor onion service. */
|
/** Whether this peer is an inbound onion, e.g. connected via our Tor onion service. */
|
||||||
bool IsInboundOnion() const { return m_inbound_onion; }
|
bool IsInboundOnion() const { return m_inbound_onion; }
|
||||||
|
|
|
@ -249,7 +249,7 @@ static RPCHelpMan getpeerinfo()
|
||||||
recvPerMsgCmd.pushKV(i.first, i.second);
|
recvPerMsgCmd.pushKV(i.first, i.second);
|
||||||
}
|
}
|
||||||
obj.pushKV("bytesrecv_per_msg", recvPerMsgCmd);
|
obj.pushKV("bytesrecv_per_msg", recvPerMsgCmd);
|
||||||
obj.pushKV("connection_type", stats.m_conn_type_string);
|
obj.pushKV("connection_type", ConnectionTypeAsString(stats.m_conn_type));
|
||||||
|
|
||||||
ret.push_back(obj);
|
ret.push_back(obj);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue