mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
Merge #20965: net, rpc: return NET_UNROUTABLE as not_publicly_routable, automate helps
96635e6177
init: use GetNetworkNames() in -onlynet help (Jon Atack)0dbde700a6
rpc: use GetNetworkNames() in getnetworkinfo and getpeerinfo helps (Jon Atack)1c3af37881
net: create GetNetworkNames() (Jon Atack)b45eae4d53
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-ACK96635e6177
🌳 MarcoFalke: review ACK96635e6177
🐗 Tree-SHA512: 511a7d987126b48a7a090739aa7c4964b6186a3ff8f5f7eec9233dd816c6b7a6dc91b3ea6b824aa68f218a8a3ebdc6ffd214e9a88af38f2bf23f3257c4284c3a
This commit is contained in:
commit
489030f2a8
@ -446,7 +446,7 @@ void SetupServerArgs(NodeContext& node)
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
argsman.AddArg("-peerbloomfilters", strprintf("Support filtering of blocks and transaction with bloom filters (default: %u)", DEFAULT_PEERBLOOMFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||
argsman.AddArg("-peerblockfilters", strprintf("Serve compact block filters to peers per BIP 157 (default: %u)", DEFAULT_PEERBLOCKFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||
argsman.AddArg("-permitbaremultisig", strprintf("Relay non-P2SH multisig (default: %u)", DEFAULT_PERMIT_BAREMULTISIG), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||
|
@ -36,7 +36,7 @@ static constexpr int ADDRV2_FORMAT = 0x20000000;
|
||||
* @note An address may belong to more than one network, for example `10.0.0.1`
|
||||
* belongs to both `NET_UNROUTABLE` and `NET_IPV4`.
|
||||
* Keep these sequential starting from 0 and `NET_MAX` as the last entry.
|
||||
* We have loops like `for (int i = 0; i < NET_MAX; i++)` that expect to iterate
|
||||
* We have loops like `for (int i = 0; i < NET_MAX; ++i)` that expect to iterate
|
||||
* over all enum values and also `GetExtNetwork()` "extends" this enum by
|
||||
* introducing standalone constants starting from `NET_MAX`.
|
||||
*/
|
||||
|
@ -59,7 +59,7 @@ enum Network ParseNetwork(const std::string& net_in) {
|
||||
std::string GetNetworkName(enum Network net)
|
||||
{
|
||||
switch (net) {
|
||||
case NET_UNROUTABLE: return "unroutable";
|
||||
case NET_UNROUTABLE: return "not_publicly_routable";
|
||||
case NET_IPV4: return "ipv4";
|
||||
case NET_IPV6: return "ipv6";
|
||||
case NET_ONION: return "onion";
|
||||
@ -72,6 +72,20 @@ std::string GetNetworkName(enum Network net)
|
||||
assert(false);
|
||||
}
|
||||
|
||||
std::vector<std::string> GetNetworkNames(bool append_unroutable)
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
for (int n = 0; n < NET_MAX; ++n) {
|
||||
const enum Network network{static_cast<Network>(n)};
|
||||
if (network == NET_UNROUTABLE || network == NET_I2P || network == NET_CJDNS || network == NET_INTERNAL) continue;
|
||||
names.emplace_back(GetNetworkName(network));
|
||||
}
|
||||
if (append_unroutable) {
|
||||
names.emplace_back(GetNetworkName(NET_UNROUTABLE));
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
bool static LookupIntern(const std::string& name, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
|
||||
{
|
||||
vIP.clear();
|
||||
|
@ -42,6 +42,8 @@ public:
|
||||
|
||||
enum Network ParseNetwork(const std::string& net);
|
||||
std::string GetNetworkName(enum Network net);
|
||||
/** Return a vector of publicly routable Network names; optionally append NET_UNROUTABLE. */
|
||||
std::vector<std::string> GetNetworkNames(bool append_unroutable = false);
|
||||
bool SetProxy(enum Network net, const proxyType &addrProxy);
|
||||
bool GetProxy(enum Network net, proxyType &proxyInfoOut);
|
||||
bool IsProxy(const CNetAddr &addr);
|
||||
|
@ -104,7 +104,7 @@ static RPCHelpMan getpeerinfo()
|
||||
{RPCResult::Type::STR, "addr", "(host:port) The IP address and port of the peer"},
|
||||
{RPCResult::Type::STR, "addrbind", "(ip:port) Bind address of the connection to the peer"},
|
||||
{RPCResult::Type::STR, "addrlocal", "(ip:port) Local address as reported by the peer"},
|
||||
{RPCResult::Type::STR, "network", "Network (ipv4, ipv6, or onion) the peer connected through"},
|
||||
{RPCResult::Type::STR, "network", "Network (" + Join(GetNetworkNames(/* append_unroutable */ true), ", ") + ")"},
|
||||
{RPCResult::Type::NUM, "mapped_as", "The AS in the BGP route to the peer used for diversifying\n"
|
||||
"peer selection (only available if the asmap config flag is set)"},
|
||||
{RPCResult::Type::STR_HEX, "services", "The services offered"},
|
||||
@ -587,7 +587,7 @@ static RPCHelpMan getnetworkinfo()
|
||||
{
|
||||
{RPCResult::Type::OBJ, "", "",
|
||||
{
|
||||
{RPCResult::Type::STR, "name", "network (ipv4, ipv6 or onion)"},
|
||||
{RPCResult::Type::STR, "name", "network (" + Join(GetNetworkNames(), ", ") + ")"},
|
||||
{RPCResult::Type::BOOL, "limited", "is the network limited using -onlynet?"},
|
||||
{RPCResult::Type::BOOL, "reachable", "is the network reachable?"},
|
||||
{RPCResult::Type::STR, "proxy", "(\"host:port\") the proxy that is used for this network, or empty if none"},
|
||||
|
@ -44,8 +44,8 @@ from test_framework.netutil import test_ipv6_local
|
||||
|
||||
RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports
|
||||
|
||||
# Networks returned by RPC getpeerinfo, defined in src/netbase.cpp::GetNetworkName()
|
||||
NET_UNROUTABLE = "unroutable"
|
||||
# Networks returned by RPC getpeerinfo.
|
||||
NET_UNROUTABLE = "not_publicly_routable"
|
||||
NET_IPV4 = "ipv4"
|
||||
NET_IPV6 = "ipv6"
|
||||
NET_ONION = "onion"
|
||||
|
@ -104,6 +104,9 @@ class NetTest(BitcoinTestFramework):
|
||||
assert_equal(peer_info[1][0]['connection_type'], 'manual')
|
||||
assert_equal(peer_info[1][1]['connection_type'], 'inbound')
|
||||
|
||||
# Check dynamically generated networks list in getpeerinfo help output.
|
||||
assert "(ipv4, ipv6, onion, not_publicly_routable)" in self.nodes[0].help("getpeerinfo")
|
||||
|
||||
def test_getnettotals(self):
|
||||
self.log.info("Test getnettotals")
|
||||
# Test getnettotals and getpeerinfo by doing a ping. The bytes
|
||||
@ -152,6 +155,9 @@ class NetTest(BitcoinTestFramework):
|
||||
for info in network_info:
|
||||
assert_net_servicesnames(int(info["localservices"], 0x10), info["localservicesnames"])
|
||||
|
||||
# Check dynamically generated networks list in getnetworkinfo help output.
|
||||
assert "(ipv4, ipv6, onion)" in self.nodes[0].help("getnetworkinfo")
|
||||
|
||||
def test_getaddednodeinfo(self):
|
||||
self.log.info("Test getaddednodeinfo")
|
||||
assert_equal(self.nodes[0].getaddednodeinfo(), [])
|
||||
|
Loading…
Reference in New Issue
Block a user