mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
merge bitcoin#24991: allow startup with -onlynet=onion -listenonion=1
This commit is contained in:
parent
e67ed92d3d
commit
32f8fda7d6
16
src/init.cpp
16
src/init.cpp
@ -1821,6 +1821,8 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
|
|||||||
onion_proxy = addrProxy;
|
onion_proxy = addrProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool onlynet_used_with_onion{args.IsArgSet("-onlynet") && IsReachable(NET_ONION)};
|
||||||
|
|
||||||
// -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
|
// -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
|
||||||
// -noonion (or -onion=0) disables connecting to .onion entirely
|
// -noonion (or -onion=0) disables connecting to .onion entirely
|
||||||
// An empty string is used to not override the onion proxy (in which case it defaults to -proxy set above, or none)
|
// An empty string is used to not override the onion proxy (in which case it defaults to -proxy set above, or none)
|
||||||
@ -1828,6 +1830,11 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
|
|||||||
if (onionArg != "") {
|
if (onionArg != "") {
|
||||||
if (onionArg == "0") { // Handle -noonion/-onion=0
|
if (onionArg == "0") { // Handle -noonion/-onion=0
|
||||||
onion_proxy = Proxy{};
|
onion_proxy = Proxy{};
|
||||||
|
if (onlynet_used_with_onion) {
|
||||||
|
return InitError(
|
||||||
|
_("Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
|
||||||
|
"reaching the Tor network is explicitly forbidden: -onion=0"));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
CService addr;
|
CService addr;
|
||||||
if (!Lookup(onionArg, addr, 9050, fNameLookup) || !addr.IsValid()) {
|
if (!Lookup(onionArg, addr, 9050, fNameLookup) || !addr.IsValid()) {
|
||||||
@ -1840,11 +1847,14 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
|
|||||||
if (onion_proxy.IsValid()) {
|
if (onion_proxy.IsValid()) {
|
||||||
SetProxy(NET_ONION, onion_proxy);
|
SetProxy(NET_ONION, onion_proxy);
|
||||||
} else {
|
} else {
|
||||||
if (args.IsArgSet("-onlynet") && IsReachable(NET_ONION)) {
|
// If -listenonion is set, then we will (try to) connect to the Tor control port
|
||||||
|
// later from the torcontrol thread and may retrieve the onion proxy from there.
|
||||||
|
const bool listenonion_disabled{!args.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION)};
|
||||||
|
if (onlynet_used_with_onion && listenonion_disabled) {
|
||||||
return InitError(
|
return InitError(
|
||||||
_("Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
|
_("Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
|
||||||
"reaching the Tor network is not provided (no -proxy= and no -onion= given) or "
|
"reaching the Tor network is not provided: none of -proxy, -onion or "
|
||||||
"it is explicitly forbidden (-onion=0)"));
|
"-listenonion is given"));
|
||||||
}
|
}
|
||||||
SetReachable(NET_ONION, false);
|
SetReachable(NET_ONION, false);
|
||||||
}
|
}
|
||||||
|
@ -328,20 +328,27 @@ class ProxyTest(BitcoinTestFramework):
|
|||||||
msg = "Error: Invalid -i2psam address or hostname: 'def:xyz'"
|
msg = "Error: Invalid -i2psam address or hostname: 'def:xyz'"
|
||||||
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
|
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
|
||||||
|
|
||||||
|
self.log.info("Test passing -onlynet=onion with -onion=0/-noonion raises expected init error")
|
||||||
msg = (
|
msg = (
|
||||||
"Error: Outbound connections restricted to Tor (-onlynet=onion) but "
|
"Error: Outbound connections restricted to Tor (-onlynet=onion) but "
|
||||||
"the proxy for reaching the Tor network is not provided (no -proxy= "
|
"the proxy for reaching the Tor network is explicitly forbidden: -onion=0"
|
||||||
"and no -onion= given) or it is explicitly forbidden (-onion=0)"
|
|
||||||
)
|
)
|
||||||
self.log.info("Test passing -onlynet=onion without -proxy or -onion raises expected init error")
|
|
||||||
self.nodes[1].extra_args = ["-onlynet=onion"]
|
|
||||||
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
|
|
||||||
|
|
||||||
self.log.info("Test passing -onlynet=onion with -onion=0/-noonion raises expected init error")
|
|
||||||
for arg in ["-onion=0", "-noonion"]:
|
for arg in ["-onion=0", "-noonion"]:
|
||||||
self.nodes[1].extra_args = ["-onlynet=onion", arg]
|
self.nodes[1].extra_args = ["-onlynet=onion", arg]
|
||||||
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
|
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
|
||||||
|
|
||||||
|
self.log.info("Test passing -onlynet=onion without -proxy, -onion or -listenonion raises expected init error")
|
||||||
|
self.nodes[1].extra_args = ["-onlynet=onion", "-listenonion=0"]
|
||||||
|
msg = (
|
||||||
|
"Error: Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
|
||||||
|
"reaching the Tor network is not provided: none of -proxy, -onion or -listenonion is given"
|
||||||
|
)
|
||||||
|
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
|
||||||
|
|
||||||
|
self.log.info("Test passing -onlynet=onion without -proxy or -onion but with -listenonion=1 is ok")
|
||||||
|
self.start_node(1, extra_args=["-onlynet=onion", "-listenonion=1"])
|
||||||
|
self.stop_node(1)
|
||||||
|
|
||||||
self.log.info("Test passing unknown network to -onlynet raises expected init error")
|
self.log.info("Test passing unknown network to -onlynet raises expected init error")
|
||||||
self.nodes[1].extra_args = ["-onlynet=abc"]
|
self.nodes[1].extra_args = ["-onlynet=abc"]
|
||||||
msg = "Error: Unknown network specified in -onlynet: 'abc'"
|
msg = "Error: Unknown network specified in -onlynet: 'abc'"
|
||||||
|
Loading…
Reference in New Issue
Block a user