-
Notifications
You must be signed in to change notification settings - Fork 36.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Args: -noconnect=0 is interpreted as -connect=0.0.0.1 #31426
Comments
But:
😭 |
Oh boy, maybe not a good first issue. 😮💨 |
@vasild how does the table look if you re-test using |
Hi guys, did you just produce this table or is it from a documentation? |
I believe vasild hand-rolled modifications to output the values. On another note, it seems like I don't have permissions to remove the "good first issue" label. Anyone with access, please remove it. @Julian128 feel free to take a stab at it anyway, but I'm no longer clear on what the solution would be. Will edit the description. |
I updated the table... but why did you had to ask! Now it looks even more convoluted 🫤 😀
I created the table manually, and used something like this to get the values: [patch] print -connect value--- i/src/init.cpp
+++ w/src/init.cpp
@@ -1939,12 +1939,16 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
connOptions.vWhitelistedRangeOutgoing.push_back(subnet);
}
}
connOptions.vSeedNodes = args.GetArgs("-seednode");
+ return InitError(strprintf(_("is negated: %s, size: %u, value[0]: %s"),
+ args.IsArgNegated("-connect") ? "true" : "false",
+ args.GetArgs("-connect").size(),
+ args.GetArgs("-connect").size() > 0 ? args.GetArgs("-connect")[0] : "empty"));
// Initiate outbound connections unless connect=0
connOptions.m_use_addrman_outgoing = !args.IsArgSet("-connect");
if (!connOptions.m_use_addrman_outgoing) {
const auto connect = args.GetArgs("-connect");
if (connect.size() != 1 || connect[0] != "0") {
connOptions.m_specified_outgoing = connect; What about, generally, forbidding |
I think a good way to handle this is to make the using ConnectSetting = common::Setting<
"-connect=<ip>", std::variant<common::Disabled, std::vector<std::string>>, SettingOptions{.network_only = true},
"Connect only to the specified node; -noconnect disables automatic connections (the rules for this peer are the same as for -addnode). This option can be specified multiple times to connect to multiple nodes.">
::Category<OptionsCategory::CONNECTION>; Retrieving the setting with
If using I do think, in general 0 and 1 addresses should be allowed since most network tools do allow them, 0 can be a convenient way to specify localhost, and in general network stacks probably have more context for interpreting addresses than we do. |
These double negatives are inherently confusing. I wonder if this is making things more convoluted than they have to be, what if we simply disallow double negatives? Or is there any reason to use such a flag? edit: I found this comment regarding this: |
Agree, can we rather prohibit double negations? |
Agree on the double negatives, I think @ryanofsky's change #16545 is pretty spot on in his table above for the
Oof, that's suprising to me, but never thought to try them in other networking contexts. |
Not sure when double negatives ( --- a/src/common/args.cpp
+++ b/src/common/args.cpp
@@ -363,7 +363,8 @@ std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
{
std::vector<std::string> result;
for (const common::SettingsValue& value : GetSettingsList(strArg)) {
- result.push_back(value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str());
+ // Treat double-negative -noarg=0 the same as -arg and return ""
+ result.push_back(value.isFalse() ? "0" : value.isTrue() ? "" : value.get_str());
}
return result;
} IMO double negatives are just tip of the iceberg when it comes to unusual option parsing behavior, compared to more harmful behavior like interpreting #16545 does disallow double negatives for typed settings. But apart from this bug, which I think is caused more by bad API design than by the double negatives, that double negatives are pretty innocuous and just a throwback to a more casual computing culture where developers trusted users more and thought things like this were convenient and cute. |
So there is nothing left to do here, your existing PRs will eventually take care of it? |
Do we use type checking for any configuration argument? I just noticed i could start bitcoind with |
Given the complexity of existing behavior, it may be better to help review one of @ryanofsky's giga-PRs. The older one has had its 5th year anniversary already.
Approximately zero type checking on a generalized level ( |
Motivation
-noconnect=0
is interpreted as-connect=1
which is interpreted as-connect=0.0.0.1
Produces the following output:
Main issue
bitcoind
should not try to connect to the0.0.0.1
IPv4 address.Bonus
-noconnect=0
should not result in-dnsseed=0
and-listen=0
in the parameter interaction logic.Issue inspiration: #31212 (comment)
Possible solution
Probably best to fail the Init-stage for invalid
-(no)connect(=value)
permutations.Should include a functional test verifying that there is an Init-error for this case, possibly added to test/functional/feature_config_args.py.
The text was updated successfully, but these errors were encountered: