net: avoid overriding non-virtual ToString() in CService and use better naming #25619

pull vasild wants to merge 5 commits into bitcoin:master from vasild:CNetAddr_ToString changing 20 files +138 −160
  1. vasild commented at 12:58 PM on July 15, 2022: contributor

    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 from CNetAddr) 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.

  2. fanquake added the label P2P on Jul 15, 2022
  3. maflcko commented at 1:10 PM on July 15, 2022: member

    ToStringPort should probably be removed. The only place where it is used in the gui should probably use ToStringIPPort to properly display IPV6, no?

  4. vasild force-pushed on Jul 15, 2022
  5. vasild commented at 4:03 PM on July 15, 2022: contributor

    5b3c6bc788..7f4aa41772: simplify OptionsDialog::updateDefaultProxyNets() to not use CService::ToStringPort() and drop the latter.

    ToStringPort should probably be removed.

    Done! :)

    The only place where it is used in the gui should probably use ToStringIPPort to properly display IPV6, no?

    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 [ ] !?", but it only used that (non-standard) representation to compare with another string internally, never displayed it. It could have used any other separator, e.g. "ipv6addr-port". Anyway, we have CService::operator==() for that, so I changed it.

  6. jonatack commented at 5:05 PM on July 15, 2022: contributor

    Concept ACK

  7. jonatack commented at 5:32 PM on July 15, 2022: contributor

    Light ACK, skimmed commits, debug build and unit tests. Will review more thoroughly.

  8. DrahtBot commented at 1:44 AM on July 16, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK sipa, jonatack, LarryRuane, achow101
    Stale ACK Empact

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #27071 (Handle CJDNS from LookupSubNet() by vasild)
    • #26621 (refactor: Continue moving application data from CNode to Peer by dergoegge)
    • #26312 (Remove Sock::Get() and Sock::Sock() by vasild)
    • #26261 (p2p: cleanup LookupIntern, Lookup and LookupHost by brunoerg)
    • #25390 (sync: introduce a thread-safe generic container and use it to remove a bunch of "GlobalMutex"es by vasild)
    • #24545 (BIP324: Enable v2 P2P encrypted transport by dhruv)
    • #21878 (Make all networking code mockable by vasild)

    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.

  9. DrahtBot cross-referenced this on Jul 16, 2022 from issue net processing: Move CNode::nServices and CNode::nLocalServices to Peer by dergoegge
  10. DrahtBot cross-referenced this on Jul 16, 2022 from issue net: convert standalone IsSelectableSocket() and SetSocketNonBlocking() to Sock methods by vasild
  11. DrahtBot cross-referenced this on Jul 16, 2022 from issue sync: introduce a thread-safe generic container and use it to remove a bunch of "GlobalMutex"es by vasild
  12. DrahtBot cross-referenced this on Jul 16, 2022 from issue I2P: add support for transient addresses for outbound connections by vasild
  13. DrahtBot cross-referenced this on Jul 16, 2022 from issue Severity-based logging -- parent PR by jonatack
  14. DrahtBot cross-referenced this on Jul 16, 2022 from issue refactor: Make FEELER_SLEEP_WINDOW type safe (std::chrono) by maflcko
  15. DrahtBot cross-referenced this on Jul 16, 2022 from issue refactor address relay time by maflcko
  16. DrahtBot cross-referenced this on Jul 16, 2022 from issue Make all networking code mockable by vasild
  17. luke-jr commented at 5:35 PM on July 16, 2022: member

    nit: "host" seems preferable to "addr"

  18. maflcko commented at 11:09 AM on July 18, 2022: member

    Maybe the scripted-diff can be made first to avoid repeatedly changing the same line of code several times?

  19. vasild force-pushed on Jul 18, 2022
  20. vasild commented at 1:11 PM on July 18, 2022: contributor

    7f4aa41772...b9ca6d0af3: do the scripted-diff first

    Cumulative diff of the PR is unchanged before and after this force push: before: git diff 85b601e043..7f4aa41772 after: git diff d806407173..b9ca6d0af3 (identical)

    Maybe the scripted-diff can be made first to avoid repeatedly changing the same line of code several times?

    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.

    nit: "host" seems preferable to "addr"

    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. ToStringHost() could be misunderstood to return bar.foo.com instead of 34.206.39.153. I am fine either way, what do others think?

  21. DrahtBot added the label Needs rebase on Jul 19, 2022
  22. vasild force-pushed on Jul 19, 2022
  23. vasild commented at 12:48 PM on July 19, 2022: contributor

    b9ca6d0af3...9854d3a820: rebase due to conflicts

  24. DrahtBot removed the label Needs rebase on Jul 19, 2022
  25. DrahtBot added the label Needs rebase on Jul 26, 2022
  26. vasild force-pushed on Jul 27, 2022
  27. vasild commented at 5:58 AM on July 27, 2022: contributor

    9854d3a820...0a798d56c2: rebase due to conflicts

  28. DrahtBot removed the label Needs rebase on Jul 27, 2022
  29. vasild force-pushed on Jul 27, 2022
  30. vasild commented at 11:07 AM on July 27, 2022: contributor

    0a798d56c2...cbfa859028: rebase due to conflicts

  31. DrahtBot cross-referenced this on Jul 30, 2022 from issue addrman: Use system time instead of adjusted network time by maflcko
  32. in src/netaddress.cpp:916 in cbfa859028 outdated
     910 | @@ -916,25 +911,17 @@ std::vector<unsigned char> CService::GetKey() const
     911 |      return key;
     912 |  }
     913 |  
     914 | -std::string CService::ToStringPort() const
     915 | +std::string CService::ToStringAddrPort() const
     916 |  {
     917 | -    return strprintf("%u", port);
     918 | -}
     919 | +    const auto port_str = strprintf("%u", port);
    


    jonatack commented at 9:58 AM on July 30, 2022:

    cbfa859 would this avoid a copy, or is copy ellision doing it for us

        const auto& port_str = strprintf("%u", port);
    

    vasild commented at 3:02 PM on August 12, 2022:

    There is no copy elision because there is no copy. The standard mandates that in this case there is no temporary to be copied and that the object should be constructed directly into port_str.

  33. in src/qt/optionsdialog.cpp:413 in cbfa859028 outdated
     405 | @@ -406,24 +406,21 @@ void OptionsDialog::updateProxyValidationState()
     406 |  
     407 |  void OptionsDialog::updateDefaultProxyNets()
     408 |  {
     409 | +    CNetAddr ui_proxy_netaddr;
     410 | +    LookupHost(ui->proxyIp->text().toStdString(), ui_proxy_netaddr, /*fAllowLookup=*/false);
     411 | +    const CService ui_proxy{ui_proxy_netaddr, ui->proxyPort->text().toUShort()};
    


    jonatack commented at 10:08 AM on July 30, 2022:

    7f420c508968 TIL about toUShort() (https://doc.qt.io/qt-5/qlocale.html#toUShort) used for the first time in this codebase. It seems compatible with our minimum required version of qt 5.11.3.


    vasild commented at 3:04 PM on August 12, 2022:

    I wasn't aware of toUShort() either. IIRC the auto-completion showed it to me ;-)

  34. jonatack commented at 10:13 AM on July 30, 2022: contributor

    utACK cbfa85902839255a382a9f4556372ba5ceecf819 code review and debug build

    Edit: might be clearest to prefix the PR title and the commit messages with refactor:

  35. DrahtBot added the label Needs rebase on Aug 5, 2022
  36. vasild force-pushed on Aug 12, 2022
  37. vasild commented at 3:22 PM on August 12, 2022: contributor

    cbfa859028...d4117c37f6: rebase due to conflicts

    Invalidates ACK from @jonatack

  38. DrahtBot removed the label Needs rebase on Aug 12, 2022
  39. jonatack approved
  40. jonatack commented at 8:16 PM on August 12, 2022: contributor

    ACK d4117c37f6e4030af623d56c22bdb7a8c84a38c6 only change is a trivial rebase

  41. DrahtBot added the label Needs rebase on Aug 26, 2022
  42. vasild force-pushed on Aug 30, 2022
  43. vasild commented at 9:44 AM on August 30, 2022: contributor

    d4117c37f6...e5d1916425: rebase due to conflicts

    Invalidates ACK from @jonatack

  44. DrahtBot removed the label Needs rebase on Aug 30, 2022
  45. jonatack commented at 4:25 PM on August 30, 2022: contributor

    re-ACK e5d191642503346ba6d9fe24f0c8f4414ffa00bc only change since my last review is a trivial rebase

  46. DrahtBot cross-referenced this on Sep 13, 2022 from issue BIP324: Enable v2 P2P encrypted transport by dhruv
  47. DrahtBot cross-referenced this on Sep 28, 2022 from issue p2p: Don't self-advertise during version processing by mzumsande
  48. DrahtBot cross-referenced this on Oct 11, 2022 from issue p2p: cleanup `LookupIntern`, `Lookup` and `LookupHost` by brunoerg
  49. achow101 commented at 7:45 PM on October 12, 2022: member
  50. DrahtBot added the label Needs rebase on Oct 12, 2022
  51. Empact commented at 7:33 PM on October 13, 2022: member

    Code Review ACK e5d191642503346ba6d9fe24f0c8f4414ffa00bc

  52. vasild force-pushed on Oct 14, 2022
  53. vasild commented at 10:04 AM on October 14, 2022: contributor

    e5d1916425...caeec22664: rebase due to conflicts

    Invalidates ACKs from @jonatack, @Empact

  54. DrahtBot cross-referenced this on Oct 14, 2022 from issue Remove Sock::Get() and Sock::Sock() by vasild
  55. DrahtBot removed the label Needs rebase on Oct 14, 2022
  56. DrahtBot cross-referenced this on Oct 29, 2022 from issue p2p: always provide CNodeStateStats and getpeerinfo/netinfo/gui updates by jonatack
  57. DrahtBot cross-referenced this on Nov 28, 2022 from issue net, refactor: Kill proxy globals by dergoegge
  58. DrahtBot cross-referenced this on Dec 6, 2022 from issue refactor: Continue moving application data from CNode to Peer by dergoegge
  59. DrahtBot added the label Needs rebase on Dec 12, 2022
  60. scripted-diff: rename ToStringIP[Port]() to ToStringAddr[Port]()
    "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-
    043b9de59a
  61. net: remove CNetAddr::ToString() and use ToStringAddr() instead
    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.
    944a9de08a
  62. net: remove CService::ToString() use ToStringAddrPort() instead
    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()`.
    96c791dd20
  63. gui: simplify OptionsDialog::updateDefaultProxyNets()
    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.
    fd4f0f41e9
  64. net: remove CService::ToStringPort()
    It is used only internally in `CService::ToStringAddrPort()`.
    c9d548c91f
  65. vasild force-pushed on Dec 12, 2022
  66. vasild commented at 11:01 AM on December 12, 2022: contributor

    caeec22664...c9d548c91f: rebase due to conflicts

    Previously invalidated ACKs from @jonatack, @Empact

  67. DrahtBot removed the label Needs rebase on Dec 12, 2022
  68. DrahtBot cross-referenced this on Dec 17, 2022 from issue test/BIP324: functional tests for v2 P2P encryption by stratospher
  69. DrahtBot cross-referenced this on Feb 10, 2023 from issue Handle CJDNS from LookupSubNet() by vasild
  70. sipa commented at 10:50 PM on February 13, 2023: member

    utACK c9d548c91fb12fba516dee896f1f97692cfa2104

  71. DrahtBot requested review from Empact on Feb 13, 2023
  72. DrahtBot requested review from jonatack on Feb 13, 2023
  73. jonatack approved
  74. jonatack commented at 4:33 PM on February 14, 2023: contributor

    re-ACK c9d548c91fb12fba516dee896f1f97692cfa2104 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

  75. LarryRuane commented at 5:16 PM on February 17, 2023: contributor

    ACK c9d548c91fb12fba516dee896f1f97692cfa2104 rebased to master, built, ran tests, ran bitcoind mainnet, code reviewed except I didn't completely understand the qt changes.

  76. achow101 commented at 6:21 PM on February 17, 2023: member

    ACK c9d548c91fb12fba516dee896f1f97692cfa2104

  77. achow101 merged this on Feb 17, 2023
  78. achow101 closed this on Feb 17, 2023

  79. sidhujag referenced this in commit 8241d6adaa on Feb 17, 2023
  80. vasild deleted the branch on Feb 20, 2023
  81. bitcoin locked this on Feb 20, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:53 UTC