aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2020-06-29 10:05:15 +0200
committerJon Atack <jon@atack.com>2020-08-24 18:41:24 +0200
commit581b343d5bf517510ab0236583ca96628751177d (patch)
tree90bdb32391a32b2664183dcc1bf844a9ff649bc8
parentd9cc13e88d096c1a171159c01cbb96444f7f8d7f (diff)
downloadbitcoin-581b343d5bf517510ab0236583ca96628751177d.tar.xz
Add in/out connections to cli -getinfo
-rw-r--r--doc/release-notes-19405.md6
-rw-r--r--src/bitcoin-cli.cpp8
-rwxr-xr-xtest/functional/interface_bitcoin_cli.py9
3 files changed, 21 insertions, 2 deletions
diff --git a/doc/release-notes-19405.md b/doc/release-notes-19405.md
index 5ffe328a4c..14f2a81c7a 100644
--- a/doc/release-notes-19405.md
+++ b/doc/release-notes-19405.md
@@ -4,3 +4,9 @@
`connections_out`, that provide the number of inbound and outbound peer
connections. These new fields are in addition to the existing `connections`
field, which returns the total number of peer connections. (#19405)
+
+## CLI
+
+- The `connections` field of `bitcoin-cli -getinfo` is expanded to return a JSON
+ object with `in`, `out` and `total` numbers of peer connections. It previously
+ returned a single integer value for the total number of peer connections. (#19405)
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index cf52b710cb..437251a02e 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -271,7 +271,13 @@ public:
result.pushKV("headers", batch[ID_BLOCKCHAININFO]["result"]["headers"]);
result.pushKV("verificationprogress", batch[ID_BLOCKCHAININFO]["result"]["verificationprogress"]);
result.pushKV("timeoffset", batch[ID_NETWORKINFO]["result"]["timeoffset"]);
- result.pushKV("connections", batch[ID_NETWORKINFO]["result"]["connections"]);
+
+ UniValue connections(UniValue::VOBJ);
+ connections.pushKV("in", batch[ID_NETWORKINFO]["result"]["connections_in"]);
+ connections.pushKV("out", batch[ID_NETWORKINFO]["result"]["connections_out"]);
+ connections.pushKV("total", batch[ID_NETWORKINFO]["result"]["connections"]);
+ result.pushKV("connections", connections);
+
result.pushKV("proxy", batch[ID_NETWORKINFO]["result"]["networks"][0]["proxy"]);
result.pushKV("difficulty", batch[ID_BLOCKCHAININFO]["result"]["difficulty"]);
result.pushKV("chain", UniValue(batch[ID_BLOCKCHAININFO]["result"]["chain"]));
diff --git a/test/functional/interface_bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py
index 80003aca0d..81c007c27b 100755
--- a/test/functional/interface_bitcoin_cli.py
+++ b/test/functional/interface_bitcoin_cli.py
@@ -71,7 +71,14 @@ class TestBitcoinCli(BitcoinTestFramework):
assert_equal(cli_get_info['blocks'], blockchain_info['blocks'])
assert_equal(cli_get_info['headers'], blockchain_info['headers'])
assert_equal(cli_get_info['timeoffset'], network_info['timeoffset'])
- assert_equal(cli_get_info['connections'], network_info['connections'])
+ assert_equal(
+ cli_get_info['connections'],
+ {
+ 'in': network_info['connections_in'],
+ 'out': network_info['connections_out'],
+ 'total': network_info['connections']
+ }
+ )
assert_equal(cli_get_info['proxy'], network_info['networks'][0]['proxy'])
assert_equal(cli_get_info['difficulty'], blockchain_info['difficulty'])
assert_equal(cli_get_info['chain'], blockchain_info['chain'])