-
Notifications
You must be signed in to change notification settings - Fork 37.7k
util: Add TorControlArgumentCheck function #23605
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to return the error from StartTorControl
? This way, other error conditions that are currently silently ignored are reported to the user.
In any case, please properly format new code you add.
You may install clang-format
and run the https://github.com/bitcoin/bitcoin/tree/master/contrib/devtools#clang-format-diffpy script to preempt whitespace nitpicking.
46cdabc
to
503359e
Compare
Updated from 46cdabc to 503359e Changes:
Let me take a look and try to figure it out. |
A drawback of this is that |
Sure, I am not against early sanity checks. Though, some errors can only be checked when the thread is started, so I don't think there is any way to avoid the delay (in general). Currently all errors are ignored, so anything that turns them into actual init errors is an improvement, regardless of when that happens. |
So would you suggest I should move |
Right. I'm fine with moving the check there, to be clear.
No, not really. If it's a generally useful utility function it makes sense to put it under It was more of a question of where to put the argument checking logic itself, with regard to responsibilities. Init shouldn't "know" the implementation details of everything. It's already a big mess in that regard. So you could add a function, say, But I agree with @MarcoFalke 's solution. |
That's true. I was not sure where to put the function since none of the
(p.s. I know I should try figuring out myself instead of asking. But I want to get this PR right, and a little expert's advice always helps)
I got your point here. Let me fix this while we think about the right place for the IsValidHostPort function. |
Concept ACK Tried experimenting with PR branch and use
Also not sure about use of |
@prayank23 Thanks for testing. Handling domains is a good point. We really need a test for this.
Doing it without introducing use of |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with previous comments in that init.cpp shouldn't need to know the implementation details for specific options, like in this case torcontrol
. That's up to StartTorControl
to check, perhaps in TorControlConnection::Connect(...)
. Following that, perhaps having HasValidHost(...)
and HasValidPort(...)
makes more sense in that sometimes you only pass a port, sometimes a full address socket?
Another way would be to modify Lookup()
in netbase.cpp, so that if no default port is given AND no port is parsed in SplitHostPort
, we fail with a suitable message. I find it a bit confusing that TorControl
would absolutely require host:port
yet supply a default port to fall back on.
Sanity checking for early rejection is imo more suitable for init
, see #22087.
If I recall correctly, valid ports are <= 65535 and tor blocks port 0 completely.
Adding some test to the new utility function would be useful.
503359e
to
7a0c95a
Compare
Updated from 503359e to 7a0c95a (pr23605.02 -> pr23605.03) Changes:
That’s a good idea. I am working on those and will include them in PR as soon as they are done. |
@shaavan check out src/test/ and for sure the documentation for inspiration, an idea could be:
This test ofc fails because of |
I am not sure having a default port (9051) is a problem. And even if it is, I think it is beyond the scope of this PR, as the goal of this PR was to check if the However, I still had one concern, though. Is |
I don't think it is a problem, but if you're going to have one, it should be defined as a constant (for re-use) and used consistently between the argument pre-check and the eventual use in But it's also fine to require users to provide the entire
That's a hairy issue. I would say it is out of scope for bitcoind to have an opinion on what are valid hostnames. I'd say it's a valid hostname if the OS DNS resolver can resolve it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ack 7a0c95a
Good to see some test units implemented.
src/init.cpp
Outdated
@@ -873,6 +873,11 @@ bool AppInitParameterInteraction(const ArgsManager& args) | |||
return InitError(Untranslated("Cannot set -listen=0 together with -listenonion=1")); | |||
} | |||
|
|||
//if torcontrol given, it needs to be in form of <host>:<port> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//if torcontrol given, it needs to be in form of <host>:<port> | |
// if torcontrol given, it needs to be in form of <host>:<port> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 4925963
It's not 9051 specifically that is a problem.
and comment
As well as the original issue described by @laanwj in #23589:
I tested with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
That makes sense. However, since OS DNS resolver can resolve hostname = 1, I think the argument value I can now understand that in our case, falling on a default port if no ports are provided seems like a suboptimal behavior.
Let me add a preliminary check for if a valid port is provided in the argument before passing it through the |
- This PR adds a new helper function, TorControlArgumentCheck, which is used for doing early sanity check for the validity of the -torcontrol argument during the init process - The checks raises an InitError along with an appropriate error message to let the user know the cause of the issue.
7a0c95a
to
4925963
Compare
Updated from 7a0c95a to 4925963 (pr23605.03 -> pr23605.04) Changes:
I shall add the unit test in a subsequent commit. |
@shaavan are you still working on this? Looks like the current branch has issues in any case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open
This PR fixes #23589
This PR adds a new utility function,
TorControlArgumentCheck
, which can be used to check if a given string is a valid<host>:<port>
pair or not.This PR also uses this new function to check the validity of the
-torcontrol
argument and raises anInitError
in case the value of this argument is invalid.