Skip to content

Commit 18169f4

Browse files
MarcoFalkePastaPastaPasta
authored andcommitted
Merge bitcoin#20786: net: [refactor] Prefer integral types in CNodeStats
faecb74 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 ACK faecb74 theStack: Code review ACK faecb74 🌲 Tree-SHA512: 24df2bd0645432060e393eb44b8abaf20fe296457d07a867b0e735c3e2e75af7b03fc6bfeca734ec33ab816a7c8e1f8591a5ec342f3afe3098a4e41f5c2cfebb
1 parent 751c9e6 commit 18169f4

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,9 @@ bool CNode::IsBlockRelayOnly() const {
588588
return (ignores_incoming_txs && !HasPermission(NetPermissionFlags::Relay)) || IsBlockOnlyConn();
589589
}
590590

591-
std::string CNode::ConnectionTypeAsString() const
591+
std::string ConnectionTypeAsString(ConnectionType conn_type)
592592
{
593-
switch (m_conn_type) {
593+
switch (conn_type) {
594594
case ConnectionType::INBOUND:
595595
return "inbound";
596596
case ConnectionType::MANUAL:
@@ -700,7 +700,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
700700
X(verifiedPubKeyHash);
701701
}
702702
X(m_masternode_connection);
703-
stats.m_conn_type_string = ConnectionTypeAsString();
703+
X(m_conn_type);
704704
}
705705
#undef X
706706

src/net.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ enum class ConnectionType {
213213
ADDR_FETCH,
214214
};
215215

216+
/** Convert ConnectionType enum to a string value */
217+
std::string ConnectionTypeAsString(ConnectionType conn_type);
216218
void Discover();
217219
uint16_t GetListenPort();
218220

@@ -307,7 +309,7 @@ class CNodeStats
307309
// In case this is a verified MN, this value is the hashed operator pubkey of the MN
308310
uint256 verifiedPubKeyHash;
309311
bool m_masternode_connection;
310-
std::string m_conn_type_string;
312+
ConnectionType m_conn_type;
311313
};
312314

313315

@@ -733,7 +735,7 @@ class CNode
733735
void MaybeSetAddrName(const std::string& addrNameIn);
734736

735737

736-
std::string ConnectionTypeAsString() const;
738+
std::string ConnectionTypeAsString() const { return ::ConnectionTypeAsString(m_conn_type); }
737739

738740
/** A ping-pong round trip has completed successfully. Update latest and minimum ping times. */
739741
void PongReceived(std::chrono::microseconds ping_time) {

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static RPCHelpMan getpeerinfo()
282282
recvPerMsgCmd.pushKV(i.first, i.second);
283283
}
284284
obj.pushKV("bytesrecv_per_msg", recvPerMsgCmd);
285-
obj.pushKV("connection_type", stats.m_conn_type_string);
285+
obj.pushKV("connection_type", ConnectionTypeAsString(stats.m_conn_type));
286286

287287
ret.push_back(obj);
288288
}

0 commit comments

Comments
 (0)