net: reduce CAddress usage to CService or CNetAddr #31854

pull vasild wants to merge 1 commits into bitcoin:master from vasild:reduce_CAddress changing 3 files +23 −24
  1. vasild commented at 10:50 am on February 13, 2025: contributor

    Using CAddress when only CService or CNetAddr is needed is excessive and confusing. Fix those occurrences to use the class they need:

    • CConnman::CalculateKeyedNetGroup() needs CNetAddr, not CAddress, thus change its argument.

    • Both callers of CConnman::CreateNodeFromAcceptedSocket() create a dummy CAddress from CService, so use CService instead.

    • GetBindAddress() only needs to return CService.

    • CNode::addrBind only needs to be CService.

  2. DrahtBot commented at 10:50 am on February 13, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31854.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK hodlinator, Sjors, laanwj, achow101

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

    Conflicts

    No conflicts as of last run.

  3. DrahtBot added the label P2P on Feb 13, 2025
  4. net: reduce CAddress usage to CService or CNetAddr
    * `CConnman::CalculateKeyedNetGroup()` needs `CNetAddr`, not `CAddress`,
      thus change its argument.
    
    * Both callers of `CConnman::CreateNodeFromAcceptedSocket()` create a
      dummy `CAddress` from `CService`, so use `CService` instead.
    
    * `GetBindAddress()` only needs to return `CService`.
    
    * `CNode::addrBind` only needs to be `CService`.
    cd4bfaee10
  5. in src/net.cpp:383 in 74f42a5920 outdated
    380@@ -381,9 +381,9 @@ bool CConnman::CheckIncomingNonce(uint64_t nonce)
    381 }
    382 
    383 /** Get the bind address for a socket as CAddress */
    


    fanquake commented at 11:23 am on February 13, 2025:
    Still documented as returning a CAddress?

    vasild commented at 11:40 am on February 13, 2025:
    Should be “CService”, fixed, thanks!
  6. vasild force-pushed on Feb 13, 2025
  7. vasild commented at 11:39 am on February 13, 2025: contributor
    74f42a5920...cd4bfaee10: address #31854 (review)
  8. laanwj commented at 12:57 pm on February 13, 2025: member
    Concept ACK
  9. hodlinator approved
  10. hodlinator commented at 2:47 pm on February 13, 2025: contributor

    ACK cd4bfaee103591f212b88afd17969c16c1056eb6

    Concept

    Defers “faking” of CAddress by initializing CAddress::nServices = NODE_NONE when all we actually have is a CService (network address+port), to all the way down to the construction of CNode:

    https://github.com/bitcoin/bitcoin/blob/cd4bfaee103591f212b88afd17969c16c1056eb6/src/net.cpp#L1831-L1833

    Type safety sanity check

    0graph LR;
    1    CService-->CNetAddr;
    2    CAddress-->CService;
    

    CAddress, which inherits from CService, has non-explicit constructors taking either 0 or 2 arguments, so implicit conversion CService -> CAddress is not an issue (verified to give compiler error). CAddress -> CService is allowed due to implicitly generated CService copy-constructor, but should be acceptable. Similarly, CService -> CNetAddr works, but the inverse does not (also verified).

  11. DrahtBot requested review from laanwj on Feb 13, 2025
  12. Sjors commented at 10:06 am on February 14, 2025: member
    ACK cd4bfaee10
  13. laanwj approved
  14. laanwj commented at 11:08 am on February 14, 2025: member
    Code review ACK cd4bfaee103591f212b88afd17969c16c1056eb6
  15. achow101 commented at 6:49 pm on February 14, 2025: member
    ACK cd4bfaee103591f212b88afd17969c16c1056eb6
  16. achow101 merged this on Feb 14, 2025
  17. achow101 closed this on Feb 14, 2025

  18. jonatack commented at 7:00 pm on February 14, 2025: member
    Post-merge ACK cd4bfaee103591f212b88afd17969c16c1056eb6. Good idea.
  19. vasild deleted the branch on Feb 17, 2025

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: 2025-02-22 06:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me