Skip to content

Commit 489030f

Browse files
author
MarcoFalke
committed
Merge #20965: net, rpc: return NET_UNROUTABLE as not_publicly_routable, automate helps
96635e6 init: use GetNetworkNames() in -onlynet help (Jon Atack) 0dbde70 rpc: use GetNetworkNames() in getnetworkinfo and getpeerinfo helps (Jon Atack) 1c3af37 net: create GetNetworkNames() (Jon Atack) b45eae4 net: update NET_UNROUTABLE to not_publicly_routable in GetNetworkName() (Jon Atack) Pull request description: per the IRC discussion today at http://www.erisian.com.au/bitcoin-core-dev/log-2021-01-19.html#l-87 - return a more helpful string name for `Network::NET_UNROUTABLE`: "not_publicly_routable" instead of "unroutable" - update the RPC getpeerinfo "network" help, and automate it and the getnetworkinfo "network#name" and the -onlynet help doc generation ACKs for top commit: theStack: re-ACK 96635e6 🌳 MarcoFalke: review ACK 96635e6 🐗 Tree-SHA512: 511a7d987126b48a7a090739aa7c4964b6186a3ff8f5f7eec9233dd816c6b7a6dc91b3ea6b824aa68f218a8a3ebdc6ffd214e9a88af38f2bf23f3257c4284c3a
2 parents cb073be + 96635e6 commit 489030f

File tree

7 files changed

+29
-7
lines changed

7 files changed

+29
-7
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ void SetupServerArgs(NodeContext& node)
446446
argsman.AddArg("-maxtimeadjustment", strprintf("Maximum allowed median peer time offset adjustment. Local perspective of time may be influenced by peers forward or backward by this amount. (default: %u seconds)", DEFAULT_MAX_TIME_ADJUSTMENT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
447447
argsman.AddArg("-maxuploadtarget=<n>", strprintf("Tries to keep outbound traffic under the given target (in MiB per 24h). Limit does not apply to peers with 'download' permission. 0 = no limit (default: %d)", DEFAULT_MAX_UPLOAD_TARGET), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
448448
argsman.AddArg("-onion=<ip:port>", "Use separate SOCKS5 proxy to reach peers via Tor onion services, set -noonion to disable (default: -proxy)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
449-
argsman.AddArg("-onlynet=<net>", "Make outgoing connections only through network <net> (ipv4, ipv6 or onion). Incoming connections are not affected by this option. This option can be specified multiple times to allow multiple networks. Warning: if it is used with ipv4 or ipv6 but not onion and the -onion or -proxy option is set, then outbound onion connections will still be made; use -noonion or -onion=0 to disable outbound onion connections in this case.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
449+
argsman.AddArg("-onlynet=<net>", "Make outgoing connections only through network <net> (" + Join(GetNetworkNames(), ", ") + "). Incoming connections are not affected by this option. This option can be specified multiple times to allow multiple networks. Warning: if it is used with ipv4 or ipv6 but not onion and the -onion or -proxy option is set, then outbound onion connections will still be made; use -noonion or -onion=0 to disable outbound onion connections in this case.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
450450
argsman.AddArg("-peerbloomfilters", strprintf("Support filtering of blocks and transaction with bloom filters (default: %u)", DEFAULT_PEERBLOOMFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
451451
argsman.AddArg("-peerblockfilters", strprintf("Serve compact block filters to peers per BIP 157 (default: %u)", DEFAULT_PEERBLOCKFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
452452
argsman.AddArg("-permitbaremultisig", strprintf("Relay non-P2SH multisig (default: %u)", DEFAULT_PERMIT_BAREMULTISIG), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);

src/netaddress.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static constexpr int ADDRV2_FORMAT = 0x20000000;
3636
* @note An address may belong to more than one network, for example `10.0.0.1`
3737
* belongs to both `NET_UNROUTABLE` and `NET_IPV4`.
3838
* Keep these sequential starting from 0 and `NET_MAX` as the last entry.
39-
* We have loops like `for (int i = 0; i < NET_MAX; i++)` that expect to iterate
39+
* We have loops like `for (int i = 0; i < NET_MAX; ++i)` that expect to iterate
4040
* over all enum values and also `GetExtNetwork()` "extends" this enum by
4141
* introducing standalone constants starting from `NET_MAX`.
4242
*/

src/netbase.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ enum Network ParseNetwork(const std::string& net_in) {
5959
std::string GetNetworkName(enum Network net)
6060
{
6161
switch (net) {
62-
case NET_UNROUTABLE: return "unroutable";
62+
case NET_UNROUTABLE: return "not_publicly_routable";
6363
case NET_IPV4: return "ipv4";
6464
case NET_IPV6: return "ipv6";
6565
case NET_ONION: return "onion";
@@ -72,6 +72,20 @@ std::string GetNetworkName(enum Network net)
7272
assert(false);
7373
}
7474

75+
std::vector<std::string> GetNetworkNames(bool append_unroutable)
76+
{
77+
std::vector<std::string> names;
78+
for (int n = 0; n < NET_MAX; ++n) {
79+
const enum Network network{static_cast<Network>(n)};
80+
if (network == NET_UNROUTABLE || network == NET_I2P || network == NET_CJDNS || network == NET_INTERNAL) continue;
81+
names.emplace_back(GetNetworkName(network));
82+
}
83+
if (append_unroutable) {
84+
names.emplace_back(GetNetworkName(NET_UNROUTABLE));
85+
}
86+
return names;
87+
}
88+
7589
bool static LookupIntern(const std::string& name, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
7690
{
7791
vIP.clear();

src/netbase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class proxyType
4242

4343
enum Network ParseNetwork(const std::string& net);
4444
std::string GetNetworkName(enum Network net);
45+
/** Return a vector of publicly routable Network names; optionally append NET_UNROUTABLE. */
46+
std::vector<std::string> GetNetworkNames(bool append_unroutable = false);
4547
bool SetProxy(enum Network net, const proxyType &addrProxy);
4648
bool GetProxy(enum Network net, proxyType &proxyInfoOut);
4749
bool IsProxy(const CNetAddr &addr);

src/rpc/net.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static RPCHelpMan getpeerinfo()
104104
{RPCResult::Type::STR, "addr", "(host:port) The IP address and port of the peer"},
105105
{RPCResult::Type::STR, "addrbind", "(ip:port) Bind address of the connection to the peer"},
106106
{RPCResult::Type::STR, "addrlocal", "(ip:port) Local address as reported by the peer"},
107-
{RPCResult::Type::STR, "network", "Network (ipv4, ipv6, or onion) the peer connected through"},
107+
{RPCResult::Type::STR, "network", "Network (" + Join(GetNetworkNames(/* append_unroutable */ true), ", ") + ")"},
108108
{RPCResult::Type::NUM, "mapped_as", "The AS in the BGP route to the peer used for diversifying\n"
109109
"peer selection (only available if the asmap config flag is set)"},
110110
{RPCResult::Type::STR_HEX, "services", "The services offered"},
@@ -587,7 +587,7 @@ static RPCHelpMan getnetworkinfo()
587587
{
588588
{RPCResult::Type::OBJ, "", "",
589589
{
590-
{RPCResult::Type::STR, "name", "network (ipv4, ipv6 or onion)"},
590+
{RPCResult::Type::STR, "name", "network (" + Join(GetNetworkNames(), ", ") + ")"},
591591
{RPCResult::Type::BOOL, "limited", "is the network limited using -onlynet?"},
592592
{RPCResult::Type::BOOL, "reachable", "is the network reachable?"},
593593
{RPCResult::Type::STR, "proxy", "(\"host:port\") the proxy that is used for this network, or empty if none"},

test/functional/feature_proxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444

4545
RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports
4646

47-
# Networks returned by RPC getpeerinfo, defined in src/netbase.cpp::GetNetworkName()
48-
NET_UNROUTABLE = "unroutable"
47+
# Networks returned by RPC getpeerinfo.
48+
NET_UNROUTABLE = "not_publicly_routable"
4949
NET_IPV4 = "ipv4"
5050
NET_IPV6 = "ipv6"
5151
NET_ONION = "onion"

test/functional/rpc_net.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ def test_getpeerinfo(self):
104104
assert_equal(peer_info[1][0]['connection_type'], 'manual')
105105
assert_equal(peer_info[1][1]['connection_type'], 'inbound')
106106

107+
# Check dynamically generated networks list in getpeerinfo help output.
108+
assert "(ipv4, ipv6, onion, not_publicly_routable)" in self.nodes[0].help("getpeerinfo")
109+
107110
def test_getnettotals(self):
108111
self.log.info("Test getnettotals")
109112
# Test getnettotals and getpeerinfo by doing a ping. The bytes
@@ -152,6 +155,9 @@ def test_getnetworkinfo(self):
152155
for info in network_info:
153156
assert_net_servicesnames(int(info["localservices"], 0x10), info["localservicesnames"])
154157

158+
# Check dynamically generated networks list in getnetworkinfo help output.
159+
assert "(ipv4, ipv6, onion)" in self.nodes[0].help("getnetworkinfo")
160+
155161
def test_getaddednodeinfo(self):
156162
self.log.info("Test getaddednodeinfo")
157163
assert_equal(self.nodes[0].getaddednodeinfo(), [])

0 commit comments

Comments
 (0)