mirror of
https://github.com/bitcoin-core/gui-qml.git
synced 2026-12-02 08:03:39 +00:00
Allow IPv6 in Proxy settings and moving validation out from the UI into the model/ interface #430
Labels
No labels
Android
Bug
Build system
Design suggestion
Doc
Needs design review
Needs rebase
Stage
UX
Up for grabs
Upstream
Wallet
duplicate
enhancement
good first issue
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin-core/gui-qml!430
Loading…
Reference in a new issue
No description provided.
Delete branch "qml-ipaddress-allow-ipv6"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The main purposes of this PR are:
bitcoin-qtrepo andbitcoind- e.g. IPv6 on Qt; IP validation in Qt)Feedback and suggestions are very welcome and will help establish a foundation for leaving business logic out of the UI going forward.
In order to test it, if it's the first time you run
./src/qt/bitcoin-qtyou need to go thru the on-boarding flow (start->next->next->next->next->connection settings->Proxy settings) otherwise you need to go to the settings (top right gear icon) then Connection->Proxy settings.Before this change, only IPv4 address were allow in the value input, now also IPv6 can be entered.
There are some look and feel kind of issues that will be handled on follow-ups (issues: #437 and #438).
Concept ACK
Pass the string as a const reference to avoid copying:
Would be good to document what this expects as input. That is - is the argument supposed to contain
:port? If yes, then maybe changeipAddressto something likeaddr_port.Up there, around line 130, is
getProxy(). Maybe move those two next to it.For consistency it would be best if the same rules apply to the
-proxy=config and the text that is accepted via the GUI. For the former the validation is happening here:github.com/bitcoin/bitcoin@f1bcf3edc5/src/init.cpp (L1140-L1168)and here
github.com/bitcoin/bitcoin@f1bcf3edc5/src/init.cpp (L1513-L1526)I am not sure how relevant the first check is for the proxy because the second check ends up calling
SplitHostPort()as well. Maybe ignore the first, move the second to a new function and call this new function from the GUI and frominit.cpp?I think this warrants some comments on what is the intention.
LookupNumeric()already callsSplitHostPort()internally (viaLookup()), can we avoid the call toSplitHostPort()here?What about
unix:/path/to/sock?I think that the example was useful:
Could have been negative and still considered as valid:
1.2.-3.4I read https://doc.qt.io/qt-5/qml-qtquick-regexpvalidator.html but it is unclear whether the framework would prefix the regexp with
^and suffix it with$. If it does not then we need to add it ourselves, because[0-9.:]*matches anything, e.g.:(this is because by default there is a match if the input contains a matching pattern and
[0-9.:]*denotes 0 or more chars, so "xyz" contains 0 of those chars followed by "xyz")In the examples from the doc they add an explicit
$at the end but not^at the front, hmm?In a bracket expression
\looses its special meaning. So the above closes the bracket expression at the first]:[0-9A-Fa-f.:\[\]followed by a literal]. Probably the regex should be something like^[][0-9A-Fa-f.:]*$, but is this even needed, given that there is a validation function?Variable names should use snake_case, so
ip_address, but maybeaddr_portor even justproxyorproxy_stris a better name, especially ifunix:/path/to/socketis to be accepted.Yes, I had it that way, somehow I lost it with testing, I'll add it back.
Ok, will do.
I agree, ok.
Ok, I thought it was too long.
Yeah, all that will be gone anyways.
True, ok.
Ok, it would make sense to remove the call
SplitHostPort()then, also because we are not returning what the cause of the invalid address is. I'll also add comments on the intention of this logic.It's a first landing and it will avoid the user to enter invalid symbols or chars, intentionally or not.
Ok, let me do some testing on this. Thanks!
As discussed offline, in the upstream repo, support to unix sockets was added (https://github.com/bitcoin/bitcoin/pull/27375) already but as this repo is not refreshed and updated yet, I've created https://github.com/bitcoin-core/gui-qml/issues/431 and will do a follow-up on this PR once we get the feature added here.
That's true for the terminal, but it seems regular expressions are handled a bit differently in QML.
In the terminal,
grepinterprets[and]differently and doesn’t use the same escaping rules as some programming environments (like QML). When using grep, we need to adjust the syntax to avoid issues with special characters and escaping but QML uses JavaScript-based regex syntax (similar to ECMAScript). I can use your suggestion as it works in both environments and the one I was adding was only working in QML.Anyways, the idea of having this regex validator (in fact looking at the doc ref you provided above I also realised that class is deprecated and should use
RegularExpressionValidatornow) is intended to ensure that an input contains only characters that are valid in IPv4 and IPv6 addresses, not to validate the format (as it would do the logic added into the node interface), it's purely esthetic. I've tried other alternatives likeinputMask:(horrible UX) and classes likeQHostAddressorQNetworkAddressEntrybut the regex validator seems very practical and simplest.As explained above, unix sockets support will be addressed in a follow-up once the feature is ready in this repo.
I'm planning to refactor the
init.cppfile after adding the persistence for the proxy setting, so the logic aligns with how the value is read and parsed from thesettings.jsonfile.Updates:
init.cpprefactoring will be done when the setting persistence is added in a separate PR.Just to clarify:
After playing with this a bit and reading https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class#non-v-mode_character_class I think it should be:
Do we want to accept the empty string as valid? If no, then change the
*to+.Approach ACK 3cb348bce27cfb8010dab89b645918f5583da9a9
[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:65123has length of 47.I'll correct it. Thanks!
Ok, let me check that again. Thanks!
As commented to you offline, current implementation of the regex works as expected and doesn't allow spaces, it also works on a terminal with grep.
But I tried both current and your suggestion on https://jsconsole.com/, current implementation doesn't work well there but your does so I'm deciding to use yours (which includes
iflag that allows case-insensitive); regarding*and+, it doesn't matter as the validation is being triggered anyways but for consistency and since it works in thejsconsole, I'll use+too.Updates:
ACK ebabe49eeb48d7579d4465d0f709839f0efe9fff
I am not very familiar with the QML side of things, but this change looks ok to me.
Good to have in a followup: unify the checks for valid proxy from
init.cppand from the GUI: https://github.com/bitcoin-core/gui-qml/pull/430#discussion_r1826541696Thanks @vasild for taking the time to review this PR! I'm working already on the next PR which will have both the persistence logic of the proxy and the refactoring of the
init.cppyou suggested.tACK ebabe49 works as expected on WSL Ubuntu 22.04
I’ll restore the call to
SplitHostPort()as advised offline. This is necessary because, without it,LookupNumericwould apply a default port if none is provided, making an address entered without a port (like127) appear valid. I discovered this while testing the persistence of values insettings.json(a separate PR, which is nearly finished and will be pushed ASAP). For example, if a user enters127in the UI, it’s stored in the file without a port. While adding a default port could work, it might not be transparent for the user.Another point we could discuss, if necessary, in the "setting persistence" PR (coming soon today) is why an IP like 127 remains valid even when a port is specified. This is because, as discussed with @vasil during his review of https://github.com/bitcoin-core/gui/pull/836, the IP validation is left to the OS (thru CService. For example,
$ ping 127results inPING 127 (0.0.0.127) 56(84) bytes of data, and this behavior aligns with how Qt andbitcoindcurrently handle IPs.Updates:
SplitHostPort()withinvalidateProxyAddressas explained above. This was previously removed in ebabe49 - same comments thread.:65535).Simplification idea: always require a port, from the GUI and from the command line and from the config file. Edit: the optional
:portpart is making it more difficult for developers while (probably) providing near 0 benefit to the users.ACK
4dea7c91a5I agree.
4dea7c91a5the layout breaks when you paste when the default value (127.0.0.1:9050) is still present:

this doesn't happen when first removing the default value and then pasting.
Maybe add scroll functionality to this page?
If you're not on full screen and paste and get the invalid message, the bottom of the page cannot be accessed anymore as you can't scroll down.
On desktop switching to full screen works, but it might be a bigger problem on mobile.
So simple scroll functionality is good to add to the proxy settings page.
Thanks @MarnixCroes.
As discussed in our call among the team, both the overlapping (#437) and when the validation occurs (#438 - reverting
onTextChangedintoonEditingFinishedwould need a "done" button at the top - opposed to the "<back" button - as @GBKS proposed) will be done on follow-ups.Check out the updated web prototype to see for a proposal of how this logic could work out.
I really like it, also the fact that the default is greyed out and it disappears when the user starts typing instead of having to delete it (I think it behaves like that currently) . Many thanks!
Are these actually default settings values or just values presented to the user? If they are just hints, they can be left as strings in the QML.
I don't believe this should return a string. I think it should be an in/out Proxy&.
validateProxyAddress shouldn't be in this module. It should exist in the nodemodel or possibly in netbase.
In the prototype, the light grey text is a placeholder, not the default. We could still treat it that way if we want.
tACK 4dea7c9 on Ubuntu 20.04 works as expected.
Ubuntu 20.04 screenshot
These are proper default values. I would leave them here for now, but maybe they can be moved into the netbase later.
This is just for display purposes, it doesn't make sense to build the object which also involves
CServiceand so on, just to come back with egipv4.proxy.ToStringAddrPort();, I'd leave it as it is but can be done on a follow-up if more ppl think the change is required.I agree, maybe it could be moved deeper into de netbase but I didn't what to touch that at this stage, it can be done later once we update the interfaces upstream.
ACK
4dea7c91a5Is my ACK needed on this? Looks more like a code task to me than a UI one.