diff --git a/src/net.cpp b/src/net.cpp index 3e1cd850dad4c..d39a891f8b07b 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -588,9 +588,9 @@ bool CNode::IsBlockRelayOnly() const { return (ignores_incoming_txs && !HasPermission(NetPermissionFlags::Relay)) || IsBlockOnlyConn(); } -std::string CNode::ConnectionTypeAsString() const +std::string ConnectionTypeAsString(ConnectionType conn_type) { - switch (m_conn_type) { + switch (conn_type) { case ConnectionType::INBOUND: return "inbound"; case ConnectionType::MANUAL: @@ -700,7 +700,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector &m_asmap) X(verifiedPubKeyHash); } X(m_masternode_connection); - stats.m_conn_type_string = ConnectionTypeAsString(); + X(m_conn_type); } #undef X diff --git a/src/net.h b/src/net.h index 75bfe72bac35e..a2a11b346c20e 100644 --- a/src/net.h +++ b/src/net.h @@ -213,6 +213,8 @@ enum class ConnectionType { ADDR_FETCH, }; +/** Convert ConnectionType enum to a string value */ +std::string ConnectionTypeAsString(ConnectionType conn_type); void Discover(); uint16_t GetListenPort(); @@ -307,7 +309,7 @@ class CNodeStats // In case this is a verified MN, this value is the hashed operator pubkey of the MN uint256 verifiedPubKeyHash; bool m_masternode_connection; - std::string m_conn_type_string; + ConnectionType m_conn_type; }; @@ -733,7 +735,7 @@ class CNode void MaybeSetAddrName(const std::string& addrNameIn); - std::string ConnectionTypeAsString() const; + std::string ConnectionTypeAsString() const { return ::ConnectionTypeAsString(m_conn_type); } /** A ping-pong round trip has completed successfully. Update latest and minimum ping times. */ void PongReceived(std::chrono::microseconds ping_time) { diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index ef2222bb6924d..720dc95a65b74 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -282,7 +282,7 @@ static RPCHelpMan getpeerinfo() recvPerMsgCmd.pushKV(i.first, i.second); } 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); }