diff --git a/src/init.cpp b/src/init.cpp index 9154fc0a6f6258..fe32e536bda510 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1732,6 +1732,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) CService onion_service_target; if (!connOptions.onion_binds.empty()) { onion_service_target = connOptions.onion_binds.front(); + } else if (!connOptions.vBinds.empty()) { + onion_service_target = connOptions.vBinds.front(); } else { onion_service_target = DefaultOnionServiceTarget(); connOptions.onion_binds.push_back(onion_service_target); diff --git a/test/functional/feature_bind_extra.py b/test/functional/feature_bind_extra.py index 6802da8d4898fa..ca8717ad66fc8b 100755 --- a/test/functional/feature_bind_extra.py +++ b/test/functional/feature_bind_extra.py @@ -21,16 +21,20 @@ PORT_MIN, PORT_RANGE, assert_equal, + p2p_port, rpc_port, ) +# From chainparamsbase.cpp:CreateBaseChainParams(). +REGTEST_TOR_TARGET_PORT = 18445 + class BindExtraTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True # Avoid any -bind= on the command line. Force the framework to avoid # adding -bind=127.0.0.1. self.bind_to_localhost_only = False - self.num_nodes = 2 + self.num_nodes = 4 def setup_network(self): # Override setup_network() because we want to put the result of @@ -43,6 +47,7 @@ def setup_network(self): if not sys.platform.startswith('linux'): raise SkipTest("This test can only be run on Linux.") + any_ipv4 = addr_to_hex('0.0.0.0') loopback_ipv4 = addr_to_hex("127.0.0.1") # Start custom ports after p2p and rpc ports. @@ -69,14 +74,29 @@ def setup_network(self): ) port += 2 + # Node2, no -bind, expected to bind on any + tor target. + self.expected.append( + [ + ["-listen=1"], + [(any_ipv4, p2p_port(2)), (loopback_ipv4, REGTEST_TOR_TARGET_PORT)] + ] + ) + + # Node3, no -bind=...=onion, thus no extra port for Tor target. + self.expected.append( + [ + ['-bind=127.0.0.1:{}'.format(port)], + [(loopback_ipv4, port)] + ], + ) + port += 1 + self.extra_args = list(map(lambda e: e[0], self.expected)) - self.add_nodes(self.num_nodes, self.extra_args) - # Don't start the nodes, as some of them would collide trying to bind on the same port. + self.setup_nodes() def run_test(self): for i in range(len(self.expected)): - self.log.info(f"Starting node {i} with {self.expected[i][0]}") - self.start_node(i) + self.log.info(f"Checking listening ports of node {i} with {self.expected[i][0]}") pid = self.nodes[i].process.pid binds = set(get_bind_addrs(pid)) # Remove IPv6 addresses because on some CI environments "::1" is not configured @@ -88,8 +108,6 @@ def run_test(self): # Remove RPC ports. They are not relevant for this test. binds = set(filter(lambda e: e[1] != rpc_port(i), binds)) assert_equal(binds, set(self.expected[i][1])) - self.stop_node(i) - self.log.info(f"Stopped node {i}") if __name__ == '__main__': BindExtraTest().main()