rpc, test: expose CNodeStats network in RPC getpeerinfo
This commit is contained in:
parent
6df7882029
commit
4938a109ad
2 changed files with 38 additions and 13 deletions
|
@ -94,6 +94,7 @@ static RPCHelpMan getpeerinfo()
|
||||||
{RPCResult::Type::STR, "addr", "(host:port) The IP address and port of the peer"},
|
{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, "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, "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::NUM, "mapped_as", "The AS in the BGP route to the peer used for diversifying\n"
|
{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)"},
|
"peer selection (only available if the asmap config flag is set)"},
|
||||||
{RPCResult::Type::STR_HEX, "services", "The services offered"},
|
{RPCResult::Type::STR_HEX, "services", "The services offered"},
|
||||||
|
@ -165,10 +166,13 @@ static RPCHelpMan getpeerinfo()
|
||||||
bool fStateStats = GetNodeStateStats(stats.nodeid, statestats);
|
bool fStateStats = GetNodeStateStats(stats.nodeid, statestats);
|
||||||
obj.pushKV("id", stats.nodeid);
|
obj.pushKV("id", stats.nodeid);
|
||||||
obj.pushKV("addr", stats.addrName);
|
obj.pushKV("addr", stats.addrName);
|
||||||
if (!(stats.addrLocal.empty()))
|
if (stats.addrBind.IsValid()) {
|
||||||
obj.pushKV("addrlocal", stats.addrLocal);
|
|
||||||
if (stats.addrBind.IsValid())
|
|
||||||
obj.pushKV("addrbind", stats.addrBind.ToString());
|
obj.pushKV("addrbind", stats.addrBind.ToString());
|
||||||
|
}
|
||||||
|
if (!(stats.addrLocal.empty())) {
|
||||||
|
obj.pushKV("addrlocal", stats.addrLocal);
|
||||||
|
}
|
||||||
|
obj.pushKV("network", stats.m_network);
|
||||||
if (stats.m_mapped_as != 0) {
|
if (stats.m_mapped_as != 0) {
|
||||||
obj.pushKV("mapped_as", uint64_t(stats.m_mapped_as));
|
obj.pushKV("mapped_as", uint64_t(stats.m_mapped_as));
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,9 @@ Test plan:
|
||||||
- proxy on IPv6
|
- proxy on IPv6
|
||||||
|
|
||||||
- Create various proxies (as threads)
|
- Create various proxies (as threads)
|
||||||
- Create bitcoinds that connect to them
|
- Create nodes that connect to them
|
||||||
- Manipulate the bitcoinds using addnode (onetry) an observe effects
|
- Manipulate the peer connections using addnode (onetry) and observe effects
|
||||||
|
- Test the getpeerinfo `network` field for the peer
|
||||||
|
|
||||||
addnode connect to IPv4
|
addnode connect to IPv4
|
||||||
addnode connect to IPv6
|
addnode connect to IPv6
|
||||||
|
@ -40,6 +41,12 @@ from test_framework.util import (
|
||||||
from test_framework.netutil import test_ipv6_local
|
from test_framework.netutil import test_ipv6_local
|
||||||
|
|
||||||
RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports
|
RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports
|
||||||
|
# From GetNetworkName() in netbase.cpp:
|
||||||
|
NET_UNROUTABLE = ""
|
||||||
|
NET_IPV4 = "ipv4"
|
||||||
|
NET_IPV6 = "ipv6"
|
||||||
|
NET_ONION = "onion"
|
||||||
|
|
||||||
|
|
||||||
class ProxyTest(BitcoinTestFramework):
|
class ProxyTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
|
@ -90,10 +97,16 @@ class ProxyTest(BitcoinTestFramework):
|
||||||
self.add_nodes(self.num_nodes, extra_args=args)
|
self.add_nodes(self.num_nodes, extra_args=args)
|
||||||
self.start_nodes()
|
self.start_nodes()
|
||||||
|
|
||||||
|
def network_test(self, node, addr, network):
|
||||||
|
for peer in node.getpeerinfo():
|
||||||
|
if peer["addr"] == addr:
|
||||||
|
assert_equal(peer["network"], network)
|
||||||
|
|
||||||
def node_test(self, node, proxies, auth, test_onion=True):
|
def node_test(self, node, proxies, auth, test_onion=True):
|
||||||
rv = []
|
rv = []
|
||||||
# Test: outgoing IPv4 connection through node
|
addr = "15.61.23.23:1234"
|
||||||
node.addnode("15.61.23.23:1234", "onetry")
|
self.log.debug("Test: outgoing IPv4 connection through node for address {}".format(addr))
|
||||||
|
node.addnode(addr, "onetry")
|
||||||
cmd = proxies[0].queue.get()
|
cmd = proxies[0].queue.get()
|
||||||
assert isinstance(cmd, Socks5Command)
|
assert isinstance(cmd, Socks5Command)
|
||||||
# Note: bitcoind's SOCKS5 implementation only sends atyp DOMAINNAME, even if connecting directly to IPv4/IPv6
|
# Note: bitcoind's SOCKS5 implementation only sends atyp DOMAINNAME, even if connecting directly to IPv4/IPv6
|
||||||
|
@ -104,10 +117,12 @@ class ProxyTest(BitcoinTestFramework):
|
||||||
assert_equal(cmd.username, None)
|
assert_equal(cmd.username, None)
|
||||||
assert_equal(cmd.password, None)
|
assert_equal(cmd.password, None)
|
||||||
rv.append(cmd)
|
rv.append(cmd)
|
||||||
|
self.network_test(node, addr, network=NET_IPV4)
|
||||||
|
|
||||||
if self.have_ipv6:
|
if self.have_ipv6:
|
||||||
# Test: outgoing IPv6 connection through node
|
addr = "[1233:3432:2434:2343:3234:2345:6546:4534]:5443"
|
||||||
node.addnode("[1233:3432:2434:2343:3234:2345:6546:4534]:5443", "onetry")
|
self.log.debug("Test: outgoing IPv6 connection through node for address {}".format(addr))
|
||||||
|
node.addnode(addr, "onetry")
|
||||||
cmd = proxies[1].queue.get()
|
cmd = proxies[1].queue.get()
|
||||||
assert isinstance(cmd, Socks5Command)
|
assert isinstance(cmd, Socks5Command)
|
||||||
# Note: bitcoind's SOCKS5 implementation only sends atyp DOMAINNAME, even if connecting directly to IPv4/IPv6
|
# Note: bitcoind's SOCKS5 implementation only sends atyp DOMAINNAME, even if connecting directly to IPv4/IPv6
|
||||||
|
@ -118,10 +133,12 @@ class ProxyTest(BitcoinTestFramework):
|
||||||
assert_equal(cmd.username, None)
|
assert_equal(cmd.username, None)
|
||||||
assert_equal(cmd.password, None)
|
assert_equal(cmd.password, None)
|
||||||
rv.append(cmd)
|
rv.append(cmd)
|
||||||
|
self.network_test(node, addr, network=NET_IPV6)
|
||||||
|
|
||||||
if test_onion:
|
if test_onion:
|
||||||
# Test: outgoing onion connection through node
|
addr = "bitcoinostk4e4re.onion:8333"
|
||||||
node.addnode("bitcoinostk4e4re.onion:8333", "onetry")
|
self.log.debug("Test: outgoing onion connection through node for address {}".format(addr))
|
||||||
|
node.addnode(addr, "onetry")
|
||||||
cmd = proxies[2].queue.get()
|
cmd = proxies[2].queue.get()
|
||||||
assert isinstance(cmd, Socks5Command)
|
assert isinstance(cmd, Socks5Command)
|
||||||
assert_equal(cmd.atyp, AddressType.DOMAINNAME)
|
assert_equal(cmd.atyp, AddressType.DOMAINNAME)
|
||||||
|
@ -131,9 +148,11 @@ class ProxyTest(BitcoinTestFramework):
|
||||||
assert_equal(cmd.username, None)
|
assert_equal(cmd.username, None)
|
||||||
assert_equal(cmd.password, None)
|
assert_equal(cmd.password, None)
|
||||||
rv.append(cmd)
|
rv.append(cmd)
|
||||||
|
self.network_test(node, addr, network=NET_ONION)
|
||||||
|
|
||||||
# Test: outgoing DNS name connection through node
|
addr = "node.noumenon:8333"
|
||||||
node.addnode("node.noumenon:8333", "onetry")
|
self.log.debug("Test: outgoing DNS name connection through node for address {}".format(addr))
|
||||||
|
node.addnode(addr, "onetry")
|
||||||
cmd = proxies[3].queue.get()
|
cmd = proxies[3].queue.get()
|
||||||
assert isinstance(cmd, Socks5Command)
|
assert isinstance(cmd, Socks5Command)
|
||||||
assert_equal(cmd.atyp, AddressType.DOMAINNAME)
|
assert_equal(cmd.atyp, AddressType.DOMAINNAME)
|
||||||
|
@ -143,6 +162,7 @@ class ProxyTest(BitcoinTestFramework):
|
||||||
assert_equal(cmd.username, None)
|
assert_equal(cmd.username, None)
|
||||||
assert_equal(cmd.password, None)
|
assert_equal(cmd.password, None)
|
||||||
rv.append(cmd)
|
rv.append(cmd)
|
||||||
|
self.network_test(node, addr, network=NET_UNROUTABLE)
|
||||||
|
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
@ -197,5 +217,6 @@ class ProxyTest(BitcoinTestFramework):
|
||||||
assert_equal(n3[net]['proxy_randomize_credentials'], False)
|
assert_equal(n3[net]['proxy_randomize_credentials'], False)
|
||||||
assert_equal(n3['onion']['reachable'], False)
|
assert_equal(n3['onion']['reachable'], False)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
ProxyTest().main()
|
ProxyTest().main()
|
||||||
|
|
Loading…
Reference in a new issue