@@ -1821,13 +1821,20 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
1821
1821
onion_proxy = addrProxy;
1822
1822
}
1823
1823
1824
+ const bool onlynet_used_with_onion{args.IsArgSet (" -onlynet" ) && IsReachable (NET_ONION)};
1825
+
1824
1826
// -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
1825
1827
// -noonion (or -onion=0) disables connecting to .onion entirely
1826
1828
// An empty string is used to not override the onion proxy (in which case it defaults to -proxy set above, or none)
1827
1829
std::string onionArg = args.GetArg (" -onion" , " " );
1828
1830
if (onionArg != " " ) {
1829
1831
if (onionArg == " 0" ) { // Handle -noonion/-onion=0
1830
1832
onion_proxy = Proxy{};
1833
+ if (onlynet_used_with_onion) {
1834
+ return InitError (
1835
+ _ (" Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
1836
+ " reaching the Tor network is explicitly forbidden: -onion=0" ));
1837
+ }
1831
1838
} else {
1832
1839
CService addr;
1833
1840
if (!Lookup (onionArg, addr, 9050 , fNameLookup ) || !addr.IsValid ()) {
@@ -1840,11 +1847,14 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
1840
1847
if (onion_proxy.IsValid ()) {
1841
1848
SetProxy (NET_ONION, onion_proxy);
1842
1849
} else {
1843
- if (args.IsArgSet (" -onlynet" ) && IsReachable (NET_ONION)) {
1850
+ // If -listenonion is set, then we will (try to) connect to the Tor control port
1851
+ // later from the torcontrol thread and may retrieve the onion proxy from there.
1852
+ const bool listenonion_disabled{!args.GetBoolArg (" -listenonion" , DEFAULT_LISTEN_ONION)};
1853
+ if (onlynet_used_with_onion && listenonion_disabled) {
1844
1854
return InitError (
1845
1855
_ (" Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
1846
- " reaching the Tor network is not provided (no -proxy= and no -onion= given) or "
1847
- " it is explicitly forbidden (-onion=0) " ));
1856
+ " reaching the Tor network is not provided: none of -proxy, -onion or "
1857
+ " -listenonion is given " ));
1848
1858
}
1849
1859
SetReachable (NET_ONION, false );
1850
1860
}
0 commit comments