aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-11-09 17:03:37 +0100
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-11-09 17:07:23 +0100
commit79a3b59cc70622fbadc43ade5fce31fcf94d852d (patch)
treee57248e1840572b8ef9b02625f8faf317d530c64 /src
parent4fd37d0a104ff1b05a3c8e374af9b2c92a0078c2 (diff)
parent7b5bd3102e06f7ff34b5d0f1d45a005560f265a5 (diff)
downloadbitcoin-79a3b59cc70622fbadc43ade5fce31fcf94d852d.tar.xz
Merge #20120: net, rpc, test, bugfix: update GetNetworkName, GetNetworksInfo, regression tests
7b5bd3102e06f7ff34b5d0f1d45a005560f265a5 test: add getnetworkinfo network name regression tests (Jon Atack) 9a75e1e5697476058b56cd8014a36de31bfecd4c rpc: update GetNetworksInfo() to not return unsupported networks (Jon Atack) ba8997fb2eda73603ce457bfec668cb7e0acbc89 net: update GetNetworkName() with all enum Network cases (Jon Atack) Pull request description: Following up on the BIP155 addrv2 changes, and starting with 7be6ff6 in #19845, RPC getnetworkinfo began returning networks with empty names. <details><summary><code>getnetworkinfo</code> on current master</summary><p> ``` "networks": [ { "name": "ipv4", "limited": false, "reachable": true, "proxy": "", "proxy_randomize_credentials": false }, { "name": "ipv6", "limited": false, "reachable": true, "proxy": "", "proxy_randomize_credentials": false }, { "name": "onion", "limited": false, "reachable": true, "proxy": "127.0.0.1:9050", "proxy_randomize_credentials": true }, { "name": "", "limited": false, "reachable": true, "proxy": "", "proxy_randomize_credentials": false }, { "name": "", "limited": false, "reachable": true, "proxy": "", "proxy_randomize_credentials": false } ], ``` </p></details> <details><summary><code>getnetworkinfo</code> on this branch</summary><p> ``` "networks": [ { "name": "ipv4", "limited": false, "reachable": true, "proxy": "", "proxy_randomize_credentials": false }, { "name": "ipv6", "limited": false, "reachable": true, "proxy": "", "proxy_randomize_credentials": false }, { "name": "onion", "limited": false, "reachable": true, "proxy": "127.0.0.1:9050", "proxy_randomize_credentials": true } ], ``` </p></details> This patch: - updates `GetNetworkName()` to the current Network enum - updates `getNetworksInfo()` to ignore as-yet unsupported networks - adds regression tests ACKs for top commit: hebasto: re-ACK 7b5bd3102e06f7ff34b5d0f1d45a005560f265a5 vasild: ACK 7b5bd3102 Tree-SHA512: 8f12363eb430e6f45e59e3b1d69c2f2eb5ead254ce7a67547d116c3b70138d763157335a3c85b51f684a3b3b502c6aace4f6fa60ac3b988cf7a9475a7423c4d7
Diffstat (limited to 'src')
-rw-r--r--src/netbase.cpp16
-rw-r--r--src/rpc/net.cpp6
2 files changed, 13 insertions, 9 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp
index 0273839017..264029d8a2 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -52,14 +52,20 @@ enum Network ParseNetwork(const std::string& net_in) {
return NET_UNROUTABLE;
}
-std::string GetNetworkName(enum Network net) {
- switch(net)
- {
+std::string GetNetworkName(enum Network net)
+{
+ switch (net) {
+ case NET_UNROUTABLE: return "unroutable";
case NET_IPV4: return "ipv4";
case NET_IPV6: return "ipv6";
case NET_ONION: return "onion";
- default: return "";
- }
+ case NET_I2P: return "i2p";
+ case NET_CJDNS: return "cjdns";
+ case NET_INTERNAL: return "internal";
+ case NET_MAX: assert(false);
+ } // no default case, so the compiler can warn about missing cases
+
+ assert(false);
}
bool static LookupIntern(const std::string& name, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index b81e6414a5..f98ea63782 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -497,11 +497,9 @@ static RPCHelpMan getnettotals()
static UniValue GetNetworksInfo()
{
UniValue networks(UniValue::VARR);
- for(int n=0; n<NET_MAX; ++n)
- {
+ for (int n = 0; n < NET_MAX; ++n) {
enum Network network = static_cast<enum Network>(n);
- if(network == NET_UNROUTABLE || network == NET_INTERNAL)
- continue;
+ if (network == NET_UNROUTABLE || network == NET_I2P || network == NET_CJDNS || network == NET_INTERNAL) continue;
proxyType proxy;
UniValue obj(UniValue::VOBJ);
GetProxy(network, proxy);