Skip to content

Commit 1ab49b8

Browse files
committed
Add in/out connections to rpc getnetworkinfo
1 parent 7f609f6 commit 1ab49b8

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

doc/release-notes-19405.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Updated RPCs
2+
3+
- `getnetworkinfo` now returns two new fields, `connections_in` and
4+
`connections_out`, that provide the number of inbound and outbound peer
5+
connections. These new fields are in addition to the existing `connections`
6+
field, which returns the total number of peer connections. (#19405)

src/rpc/net.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,9 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
490490
}},
491491
{RPCResult::Type::BOOL, "localrelay", "true if transaction relay is requested from peers"},
492492
{RPCResult::Type::NUM, "timeoffset", "the time offset"},
493-
{RPCResult::Type::NUM, "connections", "the number of connections"},
493+
{RPCResult::Type::NUM, "connections", "the total number of connections"},
494+
{RPCResult::Type::NUM, "connections_in", "the number of inbound connections"},
495+
{RPCResult::Type::NUM, "connections_out", "the number of outbound connections"},
494496
{RPCResult::Type::BOOL, "networkactive", "whether p2p networking is enabled"},
495497
{RPCResult::Type::ARR, "networks", "information per network",
496498
{
@@ -538,7 +540,9 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
538540
obj.pushKV("timeoffset", GetTimeOffset());
539541
if (node.connman) {
540542
obj.pushKV("networkactive", node.connman->GetNetworkActive());
541-
obj.pushKV("connections", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL));
543+
obj.pushKV("connections", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL));
544+
obj.pushKV("connections_in", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_IN));
545+
obj.pushKV("connections_out", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_OUT));
542546
}
543547
obj.pushKV("networks", GetNetworksInfo());
544548
obj.pushKV("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()));

test/functional/rpc_net.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ def test_getnettotals(self):
103103

104104
def test_getnetworkinfo(self):
105105
self.log.info("Test getnetworkinfo")
106-
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
107-
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
106+
info = self.nodes[0].getnetworkinfo()
107+
assert_equal(info['networkactive'], True)
108+
assert_equal(info['connections'], 2)
109+
assert_equal(info['connections_in'], 1)
110+
assert_equal(info['connections_out'], 1)
108111

109112
with self.nodes[0].assert_debug_log(expected_msgs=['SetNetworkActive: false\n']):
110113
self.nodes[0].setnetworkactive(state=False)
@@ -118,8 +121,11 @@ def test_getnetworkinfo(self):
118121
connect_nodes(self.nodes[0], 1)
119122
connect_nodes(self.nodes[1], 0)
120123

121-
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
122-
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
124+
info = self.nodes[0].getnetworkinfo()
125+
assert_equal(info['networkactive'], True)
126+
assert_equal(info['connections'], 2)
127+
assert_equal(info['connections_in'], 1)
128+
assert_equal(info['connections_out'], 1)
123129

124130
# check the `servicesnames` field
125131
network_info = [node.getnetworkinfo() for node in self.nodes]

0 commit comments

Comments
 (0)