Net: Turn net structures into dumb storage classes #8128

pull theuni wants to merge 8 commits into bitcoin:master from theuni:split-resolve changing 21 files +1246 −1136
  1. theuni commented at 10:51 pm on May 31, 2016: member

    This finishes the work started in #7868. The changed lines count is high, but it’s mostly tests.

    CNetAddr/CService/CSubNet lose their string constructors, they must now have lookup operations performed externally. This means that functions/classes that depend on them are no longer dependent on any particular lookup mechanism.

    From a high level: New resolvers/parsers may now be used for net operations. libbtcnet will replace what remains of netbase with async versions.

  2. jonasschnelli added the label P2P on Jun 1, 2016
  3. sipa commented at 4:24 pm on June 1, 2016: member
    Concept ACK. I’ll review for move and correctness later.
  4. theuni force-pushed on Jun 1, 2016
  5. jonasschnelli commented at 7:01 pm on June 1, 2016: contributor

    Concept ACK.

    nits:

  6. dcousens commented at 3:08 am on June 2, 2016: contributor
    concept ACK (utACK only up to 1394611 for now)
  7. theuni force-pushed on Jun 25, 2016
  8. theuni commented at 2:40 pm on June 25, 2016: member
    Rebased
  9. in src/netbase.cpp: in 9b0c8149cb outdated
    1289-                }
    1290-                else
    1291-                {
    1292-                    valid = false;
    1293-                }
    1294+            if (ParseInt32(strNetmask, &n)) { // If valid number, assume /24 symtex
    


    sipa commented at 12:43 pm on July 21, 2016:
    symtex? syntax?
  10. sipa commented at 12:53 pm on July 21, 2016: member
    utACK 584dcdc2cfac757130b060879aba1b25cff5cedd with a tiny nit. Verified d374dc01f8e388101a039dcd642d566b9296d5da to be move-only.
  11. theuni commented at 9:11 pm on July 27, 2016: member
    @sipa Thanks for the review. I added a separate commit for the nit rather than clobbering the verified move-only commit hashes. I’m happy to squash for merge.
  12. sipa commented at 0:24 am on July 30, 2016: member
    Needs rebase.
  13. sipa commented at 9:15 pm on July 30, 2016: member
  14. net: Split resolving out of CNetAddr 31d6b1d5f0
  15. net: Split resolving out of CService f96c7c4d91
  16. theuni force-pushed on Jul 31, 2016
  17. theuni force-pushed on Jul 31, 2016
  18. net: Split resolving out of CSubNet b6c3ff3dae
  19. net: Add direct tests for new CSubNet constructors 1017b8a960
  20. net: move CNetAddr/CService/CSubNet out of netbase 21e5b96ff4
  21. net: narrow include scope after moving to netaddress
    Net functionality is no longer needed for CAddress/CAddrman/etc. now that
    CNetAddr/CService/CSubNet are dumb storage classes.
    21ba407a73
  22. theuni commented at 6:02 pm on July 31, 2016: member
    Rebased and squashed the nit while I was at it. @sipa: I rebased on the same commit as you, so the diff should be null.
  23. in src/Makefile.am: in 21ba407a73 outdated
    105@@ -106,6 +106,7 @@ BITCOIN_CORE_H = \
    106   miner.h \
    107   net.h \
    108   netbase.h \
    109+  netaddress.h \
    


    paveljanik commented at 7:02 pm on July 31, 2016:
    nit: Please move netaddress.h one line up to match the alphabet and the cpp files order below.
  24. in src/httpserver.cpp: in 21ba407a73 outdated
    202+    CNetAddr localv4;
    203+    CNetAddr localv6;
    204+    LookupHost("127.0.0.1", localv4, false);
    205+    LookupHost("::1", localv6, false);
    206+    rpc_allow_subnets.push_back(CSubNet(localv4, 8)); // always allow IPv4 local subnet
    207+    rpc_allow_subnets.push_back(CSubNet(localv6));         // always allow IPv6 localhost
    


    paveljanik commented at 7:04 pm on July 31, 2016:
    nit: align comments.
  25. in src/httpserver.cpp: in 21ba407a73 outdated
    208     if (mapMultiArgs.count("-rpcallowip")) {
    209         const std::vector<std::string>& vAllow = mapMultiArgs["-rpcallowip"];
    210         for (std::string strAllow : vAllow) {
    211-            CSubNet subnet(strAllow);
    212+            CSubNet subnet;
    213+            LookupSubNet(strAllow.c_str(), subnet);
    


    paveljanik commented at 7:07 pm on July 31, 2016:

    Hmm. Why char * instead of std::string in prototypes and c_str() everywhere?

    Edit: probably to keep the old/already used semantics?

  26. paveljanik commented at 8:20 pm on July 31, 2016: contributor

    utACK https://github.com/bitcoin/bitcoin/pull/8128/commits/21ba407a7369a0229b8a8554dee0da63a64e6639

    This also helped reducing shadow warnings from the net* codes (e.g. for randomize_credentials: from 309 occurrences in the build log to 42 only).

  27. net: Have LookupNumeric return a CService directly
    Also fix up a few small issues:
    - Lookup with "badip:port" now sets the port to 0
    - Don't allow assert to have side-effects
    8945384bca
  28. in src/httpserver.cpp: in 21ba407a73 outdated
    618@@ -614,7 +619,7 @@ CService HTTPRequest::GetPeer()
    619         const char* address = "";
    620         uint16_t port = 0;
    621         evhttp_connection_get_peer(con, (char**)&address, &port);
    622-        peer = CService(address, port);
    623+        LookupNumeric(address, peer, port);
    


    laanwj commented at 6:58 am on August 1, 2016:

    You ignore the return value of Lookup* almost everywhere. Is this on purpose? I think the old behavior was to return a service with !IsValid() when the lookup fails. But if that is still the case we could just as well have the API be:

    0peer = LookupNumeric(address, port);
    

    Then check for IsValid afterward.


    theuni commented at 4:18 pm on August 1, 2016:

    Yes, this is inconsistent. The return value was intended to be a shortcut to avoid having to check for IsValid afterwards, but most places end up forwarding the result elsewhere even if invalid.

    I’ll just remove the return.

  29. in src/torcontrol.cpp: in 21ba407a73 outdated
    461@@ -462,7 +462,9 @@ void TorController::auth_cb(TorControlConnection& conn, const TorControlReply& r
    462         // Now that we know Tor is running setup the proxy for onion addresses
    463         // if -onion isn't set to something else.
    464         if (GetArg("-onion", "") == "") {
    465-            proxyType addrOnion = proxyType(CService("127.0.0.1", 9050), true);
    466+            CService resolved;
    467+            assert(LookupNumeric("127.0.0.1", resolved, 9050));
    


    laanwj commented at 7:00 am on August 1, 2016:
    Don’t use side-effects of assertions

    theuni commented at 4:19 pm on August 1, 2016:
    Thanks, will remove. This should just be covered by tests.
  30. sipa commented at 7:09 pm on August 5, 2016: member
    utACK 8945384bca00f74ba85c98a52925c254c49025a5
  31. sipa commented at 5:45 pm on August 10, 2016: member
    @theuni Can you address @paveljanik’s comments above?
  32. theuni commented at 2:00 am on August 11, 2016: member

    Whoops, missed @paveljanik’s batch. @paveljanik Logic for the cstr’s only was that they’re going to be used as pointers for the lookup anyway. That kinda breaks down though since we end up using strings for pre-processing. I can add a string version as well if you’d like.

    Will fix up the nits.

  33. paveljanik commented at 11:45 am on August 11, 2016: contributor
    @theuni I think it can simplify a lot of code… But I’ll leave the decision on you, of course.
  34. theuni commented at 6:20 pm on August 12, 2016: member

    @paveljanik Looking at the others, I’d rather not add a string method here. The most logical (imo) choices are:

    1. Use char* and std::string for Lookup*. Lots of duplication for functionality that just ends up acting on c strings anyway.
    2. Use std::string (by value) everywhere. Dangerous when passing in null pointers.
    3. Use char* everywhere. Means using c_str() to call in from std::string, but otherwise harmless.

    I think I’d prefer to leave it as-is unless there’s a compelling reason otherwise.

  35. net: fixup nits 9e9d644f51
  36. laanwj commented at 3:12 pm on August 13, 2016: member
    Agree with the decision to use char* here. C string manipulation, because of the inherent buffer overflow risks, should not be used in any new code, but there is no need to refactor this right now in old code, or new code closely modeled after the old code. And these strings are not manipulated anyhow, but directly passed through to libevent/the OS, so nothing would be won by making them std::string.
  37. laanwj merged this on Aug 15, 2016
  38. laanwj closed this on Aug 15, 2016

  39. laanwj referenced this in commit 1030fa718c on Aug 15, 2016
  40. random-zebra referenced this in commit 4c829bb274 on Jun 15, 2020
  41. MarcoFalke locked this on Sep 8, 2021

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: 2024-07-08 22:13 UTC

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