-
Notifications
You must be signed in to change notification settings - Fork 37.7k
net: Split DNS resolving functionality out of net structures #7868
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
Conversation
CService addrResolved; | ||
if (Lookup(strDest.c_str(), addrResolved, port, fNameLookup && !HaveNameProxy())) | ||
{ | ||
if (addrResolved.IsValid()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: inconsistent {
indentation
concept ACK, light utACK 825de38 |
825de38
to
6088311
Compare
Concept ACK. |
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. |
@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)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good catch.
Concept ACK; utACK apart from one comment |
utACK, good to see DNS lookup being decoupled from connecting. |
6088311
to
1955067
Compare
To make it clear where DNS resolves are happening
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. |
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]); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.
1955067
to
d39f5b4
Compare
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 [::]:
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. |
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? |
@sipa yep, exactly. |
…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
…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
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.