Skip to content

Commit ecd590d

Browse files
committed
Normalize inconsistent -noonlynet behavior
Treat specifying -noonlynet the same as not specifying -onlynet, instead of marking all networks unreachable. Before this change, specifying -noonlynet cleared list of reachable networks and did not allow connecting to any network. It was basically an undocumented synonym for -noconnect. After this change, specifying -nononlynet just clears previously specifed -onlynet options and allows connecting to all networks, restoring default behavior as if no -onlynet options were specified. Before this change, there was no way to restore default behavior once an -onlynet option was specified. So for example, if a config file specifed onlynet settings, they couldn't be reset on the command line without disabling the entire config file. The previous -noonlynet behavior wasn't neccessarily bad, but it was undocumented, redundant with the -noconnect option, inconsistent with behavior of other list options, and inconsistent with being able to use the command line to selectively override config options. It was also probably unintended, arising from use of the IsArgSet() method and its interaction with negated options.
1 parent 5544a19 commit ecd590d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/init.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,8 @@ void InitParameterInteraction(ArgsManager& args)
782782
if (args.SoftSetBoolArg("-whitelistrelay", true))
783783
LogInfo("parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n");
784784
}
785-
if (args.IsArgSet("-onlynet")) {
786-
const auto onlynets = args.GetArgs("-onlynet");
785+
const auto onlynets = args.GetArgs("-onlynet");
786+
if (!onlynets.empty()) {
787787
bool clearnet_reachable = std::any_of(onlynets.begin(), onlynets.end(), [](const auto& net) {
788788
const auto n = ParseNetwork(net);
789789
return n == NET_IPV4 || n == NET_IPV6;
@@ -1511,9 +1511,10 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15111511
strSubVersion.size(), MAX_SUBVERSION_LENGTH));
15121512
}
15131513

1514-
if (args.IsArgSet("-onlynet")) {
1514+
const auto onlynets = args.GetArgs("-onlynet");
1515+
if (!onlynets.empty()) {
15151516
g_reachable_nets.RemoveAll();
1516-
for (const std::string& snet : args.GetArgs("-onlynet")) {
1517+
for (const std::string& snet : onlynets) {
15171518
enum Network net = ParseNetwork(snet);
15181519
if (net == NET_UNROUTABLE)
15191520
return InitError(strprintf(_("Unknown network specified in -onlynet: '%s'"), snet));
@@ -1522,7 +1523,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15221523
}
15231524

15241525
if (!args.IsArgSet("-cjdnsreachable")) {
1525-
if (args.IsArgSet("-onlynet") && g_reachable_nets.Contains(NET_CJDNS)) {
1526+
if (!onlynets.empty() && g_reachable_nets.Contains(NET_CJDNS)) {
15261527
return InitError(
15271528
_("Outbound connections restricted to CJDNS (-onlynet=cjdns) but "
15281529
"-cjdnsreachable is not provided"));
@@ -1573,7 +1574,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15731574
onion_proxy = addrProxy;
15741575
}
15751576

1576-
const bool onlynet_used_with_onion{args.IsArgSet("-onlynet") && g_reachable_nets.Contains(NET_ONION)};
1577+
const bool onlynet_used_with_onion{!onlynets.empty() && g_reachable_nets.Contains(NET_ONION)};
15771578

15781579
// -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
15791580
// -noonion (or -onion=0) disables connecting to .onion entirely
@@ -2018,7 +2019,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
20182019
}
20192020
SetProxy(NET_I2P, Proxy{addr.value()});
20202021
} else {
2021-
if (args.IsArgSet("-onlynet") && g_reachable_nets.Contains(NET_I2P)) {
2022+
if (!onlynets.empty() && g_reachable_nets.Contains(NET_I2P)) {
20222023
return InitError(
20232024
_("Outbound connections restricted to i2p (-onlynet=i2p) but "
20242025
"-i2psam is not provided"));

src/torcontrol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ void TorController::get_socks_cb(TorControlConnection& _conn, const TorControlRe
403403
const auto onlynets = gArgs.GetArgs("-onlynet");
404404

405405
const bool onion_allowed_by_onlynet{
406-
!gArgs.IsArgSet("-onlynet") ||
406+
onlynets.empty() ||
407407
std::any_of(onlynets.begin(), onlynets.end(), [](const auto& n) {
408408
return ParseNetwork(n) == NET_ONION;
409409
})};

0 commit comments

Comments
 (0)