Net: Turn net structures into dumb storage classes#8128
Net: Turn net structures into dumb storage classes#8128laanwj merged 8 commits intobitcoin:masterfrom
Conversation
|
Concept ACK. I'll review for move and correctness later. |
|
Concept ACK. nits: |
|
concept ACK (utACK only up to 1394611 for now) |
|
Rebased |
src/netbase.cpp
Outdated
| { | ||
| valid = false; | ||
| } | ||
| if (ParseInt32(strNetmask, &n)) { // If valid number, assume /24 symtex |
|
@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. |
|
Needs rebase. |
|
@theuni Trivial rebase: https://github.com/sipa/bitcoin/commits/pr8128. |
a66f94e to
21ba407
Compare
Net functionality is no longer needed for CAddress/CAddrman/etc. now that CNetAddr/CService/CSubNet are dumb storage classes.
|
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. |
| miner.h \ | ||
| net.h \ | ||
| netbase.h \ | ||
| netaddress.h \ |
There was a problem hiding this comment.
nit: Please move netaddress.h one line up to match the alphabet and the cpp files order below.
|
utACK 21ba407 This also helped reducing shadow warnings from the |
src/httpserver.cpp
Outdated
| uint16_t port = 0; | ||
| evhttp_connection_get_peer(con, (char**)&address, &port); | ||
| peer = CService(address, port); | ||
| LookupNumeric(address, peer, port); |
There was a problem hiding this comment.
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:
peer = LookupNumeric(address, port);
Then check for IsValid afterward.
There was a problem hiding this comment.
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.
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
|
utACK 8945384 |
|
@theuni Can you address @paveljanik's comments above? |
|
Whoops, missed @paveljanik's batch. Will fix up the nits. |
|
@theuni I think it can simplify a lot of code... But I'll leave the decision on you, of course. |
|
@paveljanik Looking at the others, I'd rather not add a string method here. The most logical (imo) choices are:
I think I'd prefer to leave it as-is unless there's a compelling reason otherwise. |
|
Agree with the decision to use |
|
utACK 9e9d644 |
9e9d644 net: fixup nits (Cory Fields) 8945384 net: Have LookupNumeric return a CService directly (Cory Fields) 21ba407 net: narrow include scope after moving to netaddress (Cory Fields) 21e5b96 net: move CNetAddr/CService/CSubNet out of netbase (Cory Fields) 1017b8a net: Add direct tests for new CSubNet constructors (Cory Fields) b6c3ff3 net: Split resolving out of CSubNet (Cory Fields) f96c7c4 net: Split resolving out of CService (Cory Fields) 31d6b1d net: Split resolving out of CNetAddr (Cory Fields)
b36f743 Fix masternode service lookup (furszy) 65feb7f fixup styling (Fuzzbawls) 059ca2c net: fixup nits (Cory Fields) 5a51a5f net: Have LookupNumeric return a CService directly (Cory Fields) acd22b7 net: narrow include scope after moving to netaddress (Cory Fields) e5bea4b net: move CNetAddr/CService/CSubNet out of netbase (Cory Fields) 840d826 net: Add direct tests for new CSubNet constructors (Cory Fields) 63c46c6 net: Split resolving out of CSubNet (Fuzzbawls) a801a9e net: layer 2 CService abstraction (Fuzzbawls) 94732d2 Simplify checking of masternode.conf (Fuzzbawls) d6f81b5 RPC: Remove masternodeconnect command (Fuzzbawls) c4fe27e net: Split resolving out of CService (Cory Fields) 502343a net: Split resolving out of CNetAddr (Cory Fields) Pull request description: Backport of bitcoin#8128 as part of #1374. Based on top of #1640 Original Description: > 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. Additional work has been done in the following commits: * fcef585 - Removes a useless RPC command * 235c33e - Refactors the masternode.conf parsing with regards to valid ports * 3ddd35e - Adds additional sanity checks during client init for MN port numbers and listen options. ACKs for top commit: furszy: tested ACK b36f743 random-zebra: ACK b36f743 and merging... Tree-SHA512: 1663dc0591e3a4eeb50c1d3265ae125451bd9185e1e44e0cf36d0675fe93daf21d873ba0baa48f0e0e50b20f9313de2da5ee257eeb75c779cd07cebca61a3f99
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.