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
net: avoid overriding non-virtual ToString() in CService and use better naming #25619
Conversation
ToStringPort should probably be removed. The only place where it is used in the gui should probably use ToStringIPPort to properly display IPV6, no? |
19e1f8a
to
5b3c6bc
Compare
Done! :)
To be honest, I stared at that code in the GUI for a few minutes before opening this PR, trying to figure out what is going on and "how is it possible that it displays ipv6addr:port without |
Concept ACK |
Light ACK, skimmed commits, debug build and unit tests. Will review more thoroughly. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
nit: "host" seems preferable to "addr" |
Maybe the scripted-diff can be made first to avoid repeatedly changing the same line of code several times? |
7f4aa41
to
b9ca6d0
Compare
Cumulative diff of the PR is unchanged before and after this force push:
I actually made it this way originally but then decided it is better to have the scripted-diff at the end so that it is optional and if it is contentious, then just drop the last commit (the scripted-diff). Changed now, since there are two more commits on top. For reviewing it shouldn't matter much since, I guess, reviewers are not staring carefully at the entire diff of scripted-diffs. It would matter for history chasing - to reduce the number of hops ("git blame"s) one has to do.
Could be, can you elaborate a bit why? I did not change it yet because I am somewhat in favor of "addr" because "host" may be misunderstood to return a host (aka hostname): e.g. |
b9ca6d0
to
9854d3a
Compare
|
9854d3a
to
0a798d5
Compare
|
0a798d5
to
cbfa859
Compare
|
Code Review ACK e5d1916 |
e5d1916
to
caeec22
Compare
"IP" stands for "Internet Protocol". "IP address" is sometimes shortened to just "IP" or "address". However, Tor or I2P addresses are not "IP addresses", nor "IPs". Thus, use "Addr" instead of "IP" for addresses that could be IP, Tor or I2P addresses: `CService::ToStringIPPort()` -> `CService::ToStringAddrPort()` `CNetAddr::ToStringIP()` -> `CNetAddr::ToStringAddr()` -BEGIN VERIFY SCRIPT- sed -i 's/ToStringIPPort/ToStringAddrPort/g' -- $(git grep -l ToStringIPPort src) sed -i 's/ToStringIP/ToStringAddr/g' -- $(git grep -l ToStringIP src) -END VERIFY SCRIPT-
Both methods do the same thing, so simplify to having just one. Further, `CService` inherits `CNetAddr` and `CService::ToString()` overrides `CNetAddr::ToString()` but the latter is not virtual which may be confusing. Avoid such a confusion by not having non-virtual methods with the same names in inheritance.
Both methods do the same thing, so simplify to having just one. `ToString()` is too generic in this case and it is unclear what it does, given that there are similar methods: `ToStringAddr()` (inherited from `CNetAddr`), `ToStringPort()` and `ToStringAddrPort()`.
Do not create strings and compare them to check if one `addr:port` equals another. Use `CService::operator==()` instead. `strDefaultProxyGUI` was assigned the same value 3 times. Instead save it in `const CService ui_proxy` at the beginning of the function.
It is used only internally in `CService::ToStringAddrPort()`.
caeec22
to
c9d548c
Compare
utACK c9d548c |
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.
re-ACK c9d548c only change since my previous reviews is rebase, but as a sanity check rebased to current master and at each commit quickly re-reviewed and re-verified clean build and green unit tests
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.
ACK c9d548c
rebased to master, built, ran tests, ran bitcoind
mainnet, code reviewed except I didn't completely understand the qt changes.
ACK c9d548c |
Before this PR we had the somewhat confusing combination of methods:
CNetAddr::ToStringIP()
CNetAddr::ToString()
(duplicate of the above)CService::ToStringIPPort()
CService::ToString()
(duplicate of the above, overrides a non-virtual method fromCNetAddr
)CService::ToStringPort()
Avoid overriding non-virtual methods.
"IP" stands for "Internet Protocol" and while sometimes "IP addresses" are called just "IPs", it is incorrect to call Tor or I2P addresses "IPs". Thus use "Addr" instead of "IP".
Change the above to:
CNetAddr::ToStringAddr()
CService::ToStringAddrPort()
The changes touch a lot of files, but are mostly mechanical.