Skip to content

Commit 581b343

Browse files
committed
Add in/out connections to cli -getinfo
1 parent d9cc13e commit 581b343

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

doc/release-notes-19405.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
`connections_out`, that provide the number of inbound and outbound peer
55
connections. These new fields are in addition to the existing `connections`
66
field, which returns the total number of peer connections. (#19405)
7+
8+
## CLI
9+
10+
- The `connections` field of `bitcoin-cli -getinfo` is expanded to return a JSON
11+
object with `in`, `out` and `total` numbers of peer connections. It previously
12+
returned a single integer value for the total number of peer connections. (#19405)

src/bitcoin-cli.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,13 @@ class GetinfoRequestHandler: public BaseRequestHandler
271271
result.pushKV("headers", batch[ID_BLOCKCHAININFO]["result"]["headers"]);
272272
result.pushKV("verificationprogress", batch[ID_BLOCKCHAININFO]["result"]["verificationprogress"]);
273273
result.pushKV("timeoffset", batch[ID_NETWORKINFO]["result"]["timeoffset"]);
274-
result.pushKV("connections", batch[ID_NETWORKINFO]["result"]["connections"]);
274+
275+
UniValue connections(UniValue::VOBJ);
276+
connections.pushKV("in", batch[ID_NETWORKINFO]["result"]["connections_in"]);
277+
connections.pushKV("out", batch[ID_NETWORKINFO]["result"]["connections_out"]);
278+
connections.pushKV("total", batch[ID_NETWORKINFO]["result"]["connections"]);
279+
result.pushKV("connections", connections);
280+
275281
result.pushKV("proxy", batch[ID_NETWORKINFO]["result"]["networks"][0]["proxy"]);
276282
result.pushKV("difficulty", batch[ID_BLOCKCHAININFO]["result"]["difficulty"]);
277283
result.pushKV("chain", UniValue(batch[ID_BLOCKCHAININFO]["result"]["chain"]));

test/functional/interface_bitcoin_cli.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ def run_test(self):
7171
assert_equal(cli_get_info['blocks'], blockchain_info['blocks'])
7272
assert_equal(cli_get_info['headers'], blockchain_info['headers'])
7373
assert_equal(cli_get_info['timeoffset'], network_info['timeoffset'])
74-
assert_equal(cli_get_info['connections'], network_info['connections'])
74+
assert_equal(
75+
cli_get_info['connections'],
76+
{
77+
'in': network_info['connections_in'],
78+
'out': network_info['connections_out'],
79+
'total': network_info['connections']
80+
}
81+
)
7582
assert_equal(cli_get_info['proxy'], network_info['networks'][0]['proxy'])
7683
assert_equal(cli_get_info['difficulty'], blockchain_info['difficulty'])
7784
assert_equal(cli_get_info['chain'], blockchain_info['chain'])

0 commit comments

Comments
 (0)