Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net: Turn net structures into dumb storage classes #8128

Merged
merged 8 commits into from
Aug 15, 2016

Conversation

theuni
Copy link
Member

@theuni theuni commented May 31, 2016

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.

@sipa
Copy link
Member

sipa commented Jun 1, 2016

Concept ACK. I'll review for move and correctness later.

@jonasschnelli
Copy link
Contributor

Concept ACK.

nits:

@dcousens
Copy link
Contributor

dcousens commented Jun 2, 2016

concept ACK (utACK only up to 1394611 for now)

@theuni
Copy link
Member Author

theuni commented Jun 25, 2016

Rebased

{
valid = false;
}
if (ParseInt32(strNetmask, &n)) { // If valid number, assume /24 symtex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

symtex? syntax?

@sipa
Copy link
Member

sipa commented Jul 21, 2016

utACK 584dcdc with a tiny nit.
Verified d374dc0 to be move-only.

@theuni
Copy link
Member Author

theuni commented Jul 27, 2016

@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.

@sipa
Copy link
Member

sipa commented Jul 30, 2016

Needs rebase.

@sipa
Copy link
Member

sipa commented Jul 30, 2016

@theuni theuni force-pushed the split-resolve branch 2 times, most recently from a66f94e to 21ba407 Compare July 31, 2016 18:01
@theuni
Copy link
Member Author

theuni commented Jul 31, 2016

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.

@@ -106,6 +106,7 @@ BITCOIN_CORE_H = \
miner.h \
net.h \
netbase.h \
netaddress.h \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Please move netaddress.h one line up to match the alphabet and the cpp files order below.

@paveljanik
Copy link
Contributor

utACK 21ba407

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

@@ -614,7 +619,7 @@ CService HTTPRequest::GetPeer()
const char* address = "";
uint16_t port = 0;
evhttp_connection_get_peer(con, (char**)&address, &port);
peer = CService(address, port);
LookupNumeric(address, peer, port);
Copy link
Member

@laanwj laanwj Aug 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@sipa
Copy link
Member

sipa commented Aug 5, 2016

utACK 8945384

@sipa
Copy link
Member

sipa commented Aug 10, 2016

@theuni Can you address @paveljanik's comments above?

@theuni
Copy link
Member Author

theuni commented Aug 11, 2016

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.

@paveljanik
Copy link
Contributor

@theuni I think it can simplify a lot of code... But I'll leave the decision on you, of course.

@theuni
Copy link
Member Author

theuni commented Aug 12, 2016

@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.

@paveljanik
Copy link
Contributor

@theuni: OK, agreed.

utACK 9e9d644

@laanwj
Copy link
Member

laanwj commented Aug 13, 2016

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.

@laanwj
Copy link
Member

laanwj commented Aug 15, 2016

utACK 9e9d644

@laanwj laanwj merged commit 9e9d644 into bitcoin:master Aug 15, 2016
laanwj added a commit that referenced this pull request Aug 15, 2016
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)
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Jun 15, 2020
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants