Skip to content

Commit be8294f

Browse files
committed
p2p, rpc, refactor: remove CNodeStats::m_conn_type_string
and move getpeerinfo connection_type help to the correct place per review feedback
1 parent cbfb5c9 commit be8294f

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/net.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,9 @@ void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNet
507507
}
508508
}
509509

510-
std::string CNode::ConnectionTypeAsString() const
510+
std::string ConnectionTypeAsString(ConnectionType conn_type)
511511
{
512-
switch (m_conn_type) {
512+
switch (conn_type) {
513513
case ConnectionType::INBOUND:
514514
return "inbound";
515515
case ConnectionType::MANUAL:
@@ -628,7 +628,6 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
628628
stats.addrLocal = addrLocalUnlocked.IsValid() ? addrLocalUnlocked.ToString() : "";
629629

630630
X(m_conn_type);
631-
stats.m_conn_type_string = ConnectionTypeAsString();
632631
}
633632
#undef X
634633

src/net.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ enum class ConnectionType {
180180
ADDR_FETCH,
181181
};
182182

183+
/** Convert enum ConnectionType to a string value */
184+
std::string ConnectionTypeAsString(ConnectionType conn_type);
185+
183186
class NetEventsInterface;
184187
class CConnman
185188
{
@@ -724,7 +727,6 @@ class CNodeStats
724727
Network m_network;
725728
uint32_t m_mapped_as;
726729
ConnectionType m_conn_type;
727-
std::string m_conn_type_string;
728730
};
729731

730732

@@ -1219,7 +1221,7 @@ class CNode
12191221
//! Sets the addrName only if it was not previously set
12201222
void MaybeSetAddrName(const std::string& addrNameIn);
12211223

1222-
std::string ConnectionTypeAsString() const;
1224+
std::string ConnectionTypeAsString() const { return ::ConnectionTypeAsString(m_conn_type); }
12231225

12241226
/** Whether this peer is an inbound onion, e.g. connected via our Tor onion service. */
12251227
bool IsInboundOnion() const { return m_inbound_onion; }

src/rpc/net.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ static RPCHelpMan getpeerinfo()
128128
{RPCResult::Type::BOOL, "inbound", "Inbound (true) or Outbound (false)"},
129129
{RPCResult::Type::BOOL, "bip152_hb_to", "Whether we selected peer as (compact blocks) high-bandwidth peer"},
130130
{RPCResult::Type::BOOL, "bip152_hb_from", "Whether peer selected us as (compact blocks) high-bandwidth peer"},
131-
{RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + ".\n"
132-
"Please note this output is unlikely to be stable in upcoming releases as we iterate to\n"
133-
"best capture connection behaviors."},
134131
{RPCResult::Type::NUM, "startingheight", "The starting height (block) of the peer"},
135132
{RPCResult::Type::NUM, "synced_headers", "The last header we have in common with this peer"},
136133
{RPCResult::Type::NUM, "synced_blocks", "The last block we have in common with this peer"},
@@ -156,6 +153,9 @@ static RPCHelpMan getpeerinfo()
156153
"Only known message types can appear as keys in the object and all bytes received\n"
157154
"of unknown message types are listed under '"+NET_MESSAGE_COMMAND_OTHER+"'."}
158155
}},
156+
{RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + ".\n"
157+
"Please note this output is unlikely to be stable in upcoming releases as we iterate to\n"
158+
"best capture connection behaviors."},
159159
}},
160160
}},
161161
},
@@ -249,7 +249,7 @@ static RPCHelpMan getpeerinfo()
249249
recvPerMsgCmd.pushKV(i.first, i.second);
250250
}
251251
obj.pushKV("bytesrecv_per_msg", recvPerMsgCmd);
252-
obj.pushKV("connection_type", stats.m_conn_type_string);
252+
obj.pushKV("connection_type", ConnectionTypeAsString(stats.m_conn_type));
253253

254254
ret.push_back(obj);
255255
}

0 commit comments

Comments
 (0)