Skip to content

Conversation

theuni
Copy link
Member

@theuni theuni commented Apr 13, 2016

First PR of many in the p2p refactor.

This brings CNetAddr/CSubNet/CService one step closer to being dumb storage structures. By forcing addresses to be resolved elsewhere, the implementation details are free to change. In particular, this is necessary for making the resolves fully async, which is necessary in a model in which the entire connection process is asynchronous.

The DNS seed TODO could be fixed more properly with something like this: theuni@792b0f5 (an ipv6 range would probably make more sense, though), but I'll leave that for another PR.

CService addrResolved;
if (Lookup(strDest.c_str(), addrResolved, port, fNameLookup && !HaveNameProxy()))
{
if (addrResolved.IsValid()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: inconsistent { indentation

@dcousens
Copy link
Contributor

concept ACK, light utACK 825de38

@theuni theuni force-pushed the net-cleanup-resolve branch from 825de38 to 6088311 Compare April 13, 2016 03:58
@jonasschnelli
Copy link
Contributor

Concept ACK.

@instagibbs
Copy link
Member

meta-comment: Is there an issue open with all the various things to be done for p2p refactor, for a higher-level view? I'd like to review but my knowledge of p2p part of Core is weak. I think a higher-level view may help me review.

@theuni
Copy link
Member Author

theuni commented Apr 14, 2016

@instagibbs good point. I have another RFC PR coming up today, that will be a good place to discuss general scope/goals. I'll begin writing something up.

return InitError(ResolveErrMsg("externalip", strAddr));
AddLocal(CService(strAddr, GetListenPort(), fNameLookup), LOCAL_MANUAL);
CService addrLocal;
if (Lookup(strAddr.c_str(), addrLocal, GetListenPort(), fNameLookup)) {
Copy link
Member

Choose a reason for hiding this comment

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

If the Lookup fails, shouldn't the InitError below trigger as well?

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, good catch.

@sipa
Copy link
Member

sipa commented Apr 14, 2016

Concept ACK; utACK apart from one comment

@laanwj
Copy link
Member

laanwj commented Apr 15, 2016

utACK, good to see DNS lookup being decoupled from connecting.

@theuni theuni force-pushed the net-cleanup-resolve branch from 6088311 to 1955067 Compare April 17, 2016 21:35
To make it clear where DNS resolves are happening
@theuni
Copy link
Member Author

theuni commented Apr 18, 2016

Updated for @sipa's comment.

@instagibbs I didn't manage to get it ready last week as hoped, but a PR that looks similar to https://github.com/theuni/bitcoin/tree/net-refactor12 plus a lengthy explanation is hopefully coming up in the next day or two. That work aims to segregate the p2p functionality from the rest of the code so that it can be replaced in chunks without interfering with other subsystems.

@instagibbs
Copy link
Member

concept ACK, lightly tACK

// TODO: It doesn't make sense to define an arbitrary IP as the source of others.
// Instead, a dummy range should be created to identify seed resolves.
if (!vIPs.empty())
addrman.Add(vAdd, vIPs[0]);
Copy link
Member

Choose a reason for hiding this comment

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

That's not actually correct. The "source IP" the addresses get assigned to should be stable over multiple runs, as the DNS seed is seen as a potential attacker who is only allowed to modify a certain subset of entries. If the IP changes over time, that protection disappears.

Copy link
Member Author

Choose a reason for hiding this comment

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

@sipa To clarify, I meant that each dns seed should have a corresponding stable "source" dummy ip. Something like this: theuni@792b0f5

I see now that the second resolve is happening on seed.name rather than seed.host, so the resolve isn't actually arbitrary. That was just poor reading on my account.

I'll add back the second resolve, and we can revisit the dummy later.

theuni added 3 commits April 20, 2016 13:07
Note: Some seeds aren't actually returning an IP for their name entries, so
they're being added to addrman with a source of [::].

This commit shouldn't change that behavior, for better or worse.
Rather than allowing CNetAddr/CService/CSubNet to launch DNS queries, require
that addresses are already resolved.

This greatly simplifies async resolve logic, and makes it harder to
accidentally leak DNS queries.
CNetAddr/CService/CSubnet can no longer resolve DNS.
@theuni theuni force-pushed the net-cleanup-resolve branch from 1955067 to d39f5b4 Compare April 20, 2016 17:10
@theuni
Copy link
Member Author

theuni commented Apr 20, 2016

Addressed @sipa's concern above (I hope). For reference, the following mainnet seeds don't currently resolve their names properly (for me, anyway), so they end up grouped together with sources of [::]:

xf2.org
bluematt.me

I've confirmed that seed results are added to addrman that way before and after this change. I'll work on fixing that in a follow-up pull-request.

@sipa
Copy link
Member

sipa commented Apr 21, 2016

utACK d39f5b4

Meta question: I am right to expect that there will be follow-ups that split the Lookup functions in resolving ones and non-resolving ones, and make the CNetAddr constructors only depend in the non-resolving ones?

@theuni
Copy link
Member Author

theuni commented Apr 21, 2016

@sipa yep, exactly.

@sipa sipa merged commit d39f5b4 into bitcoin:master Apr 21, 2016
sipa added a commit that referenced this pull request Apr 21, 2016
…ures

d39f5b4 net: disable resolving from storage structures (Cory Fields)
3675699 net: resolve outside of storage structures (Cory Fields)
a98cd1f net: manually resolve dns seed sources (Cory Fields)
e9fc71e net: require lookup functions to specify all arguments (Cory Fields)
furszy added a commit to PIVX-Project/PIVX that referenced this pull request Mar 4, 2020
…tures

ccf4902 net: disable resolving from storage structures (Cory Fields)
424722f net: resolve outside of storage structures (Cory Fields)
deb76ab net: manually resolve dns seed sources (Cory Fields)
f3bd785 net: require lookup functions to specify all arguments (Cory Fields)

Pull request description:

  Port of bitcoin#7868

  This brings CNetAddr/CSubNet/CService one step closer to being dumb storage structures. By forcing addresses to be resolved elsewhere, the implementation details are free to change. In particular, this is necessary for making the resolves fully async, which is necessary in a model in which the entire connection process is asynchronous.

ACKs for top commit:
  random-zebra:
    ACK ccf4902
  furszy:
    good initial back port, utACK ccf4902

Tree-SHA512: 560c0212901474a1de8540595cf957af73960355a64840fbdb40b728b0d4a320475b77368dadb2221cf5ec7a3c2a06088ce6bb31d69fa5b05c2e02a54b21ad31
wqking pushed a commit to wqking-temp/Vitae that referenced this pull request Aug 5, 2020
…tures

ccf49028439469248e402d6da748f3515ea82adf net: disable resolving from storage structures (Cory Fields)
424722f26d80b9d602fcb16e2f5ad22416e38a84 net: resolve outside of storage structures (Cory Fields)
deb76abafd2cf47619d3eccd5f8993942a0ad9e1 net: manually resolve dns seed sources (Cory Fields)
f3bd785389181bb2f286e6c80c2ce5b85df52186 net: require lookup functions to specify all arguments (Cory Fields)

Pull request description:

  Port of bitcoin/bitcoin#7868

  This brings CNetAddr/CSubNet/CService one step closer to being dumb storage structures. By forcing addresses to be resolved elsewhere, the implementation details are free to change. In particular, this is necessary for making the resolves fully async, which is necessary in a model in which the entire connection process is asynchronous.

ACKs for top commit:
  random-zebra:
    ACK ccf49028439469248e402d6da748f3515ea82adf
  furszy:
    good initial back port, utACK ccf4902

Tree-SHA512: 560c0212901474a1de8540595cf957af73960355a64840fbdb40b728b0d4a320475b77368dadb2221cf5ec7a3c2a06088ce6bb31d69fa5b05c2e02a54b21ad31
@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