net: Correct comparison of addr count #15345

pull dongcarl wants to merge 1 commits into bitcoin:master from dongcarl:2019-02-getnscore-fix changing 1 files +1 −2
  1. dongcarl commented at 6:15 PM on February 4, 2019: member

    LOCAL_NONE is supposed to be an enum indicating the nScore of a LocalServiceInfo rather than the count of an addr in mapLocalHost.

  2. net: Correct comparison of addr count
    LOCAL_NONE is supposed to be an enum indicating the score of a
    LocalServiceInfo rather than the count of an addr in mapLocalHost.
    107623c26c
  3. in src/net.cpp:177 in 107623c26c
     173 | @@ -174,8 +174,7 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
     174 |  static int GetnScore(const CService& addr)
     175 |  {
     176 |      LOCK(cs_mapLocalHost);
     177 | -    if (mapLocalHost.count(addr) == LOCAL_NONE)
    


    laanwj commented at 6:19 PM on February 4, 2019:

    Huh, this is really strange. I guess it's correct because LOCAL_NONE effectively is 0 but it's certainly not right.

  4. laanwj commented at 6:21 PM on February 4, 2019: member

    utACK 107623c26c2113428446effaa24edb986a3e780c

  5. laanwj added the label P2P on Feb 4, 2019
  6. MarcoFalke added the label Refactoring on Feb 4, 2019
  7. MarcoFalke commented at 6:31 PM on February 4, 2019: member

    ACK 107623c26c (also checked that this commit doesn't change the binary produced by clang7 on my system, so tagged with "refactoring")

  8. MarcoFalke added this to the milestone 0.18.0 on Feb 4, 2019
  9. promag commented at 6:58 PM on February 4, 2019: member

    utACK 107623c, although it could improve a bit by avoiding 2nd lookup.

    std::map<CNetAddr, LocalServiceInfo>::const_iterator it = mapLocalHost.find(addr);
    return it == mapLocalHost.end() ? 0 : it->second.nScore;
    
  10. jonasschnelli commented at 7:01 PM on February 4, 2019: contributor

    utACK 107623c26c2113428446effaa24edb986a3e780c

  11. laanwj commented at 7:04 PM on February 4, 2019: member

    utACK 107623c, although it could improve a bit by avoiding 2nd lookup.

    I thought about commenting that, but I don't think that's really much of an improvement in readability (and this isn't exactly a critical path for perfomance).

  12. laanwj merged this on Feb 4, 2019
  13. laanwj closed this on Feb 4, 2019

  14. laanwj referenced this in commit bfbe42585e on Feb 4, 2019
  15. deadalnix referenced this in commit 7df5863a23 on May 30, 2020
  16. ftrader referenced this in commit a5226ac3c4 on Aug 17, 2020
  17. PastaPastaPasta referenced this in commit 00afeff55d on Jun 25, 2021
  18. PastaPastaPasta referenced this in commit ae6ce01be6 on Jun 25, 2021
  19. PastaPastaPasta referenced this in commit 2796f46f3c on Jun 27, 2021
  20. MarcoFalke locked this on Dec 16, 2021

Milestone
0.18.0


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-04-22 06:15 UTC

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