- A new option -dns is introduced that enables name lookups in -connect and -addnode, which is not enabled by default, as it may be considered a security issue.
- A NameLookup function is added that supports retrieving one or more addresses based on a host name
- CAddress constructors (optionally) support name lookups.
- The different places in the source code that did name lookups are refactored to use NameLookup or CAddress instead (dns seeding, irc server lookup, getexternalip, ...).
Support for name lookups in -connect and -addnode #192
pull sipa wants to merge 1 commits into bitcoin:master from sipa:dnslookup changing 4 files +148 −114-
sipa commented at 11:46 AM on May 3, 2011: member
-
jgarzik commented at 2:01 PM on May 3, 2011: contributor
This is a recent rough draft, but it needs improvement.
Think about the object structure a bit. You want a "CAddress factory", that will create one or more CAddress's from a DNS lookup. Supporting a multiple-address lookup from inside a singleton address object is awkward, because DNS lookups have a one-to-many relationship between DNS names and addresses.
The "create higher nIndex, until address returned is invalid" is unusual for this reason, and the code should be refactored.
You want a helper (CAddressFactory?) that returns one or more CAddress objects, from a DNS lookup. Because a DNS lookup may produce multiple addresses, this cannot be inside the CAddress implementation itself.
-
sipa commented at 11:21 AM on May 4, 2011: member
I agree, actually. I moved the lookup code to a NameLookup function that creates a CAddress or a vector of those, and is used in the (single-address only) lookup version of the CAddress constructor, for convenience.
- sipa closed this on May 4, 2011
- sipa reopened this on May 5, 2011
-
jgarzik commented at 2:55 PM on May 5, 2011: contributor
ACK, thanks for revising
-
jgarzik commented at 11:37 AM on May 6, 2011: contributor
Forum thread http://www.bitcoin.org/smf/index.php?topic=7123.0
-
jgarzik commented at 11:50 AM on May 6, 2011: contributor
My finger was hovering over the "Merge pull request" button, but I found a last minute issue.
Eventually, we do want to support IPv6. Satoshi reserved space for it in the P2P protocol address storage area, and it will be needed in years to come, to connect some clients.
As such, please separate hostname and port into two distinct function parameters / variables, and do not combine them into a single string "host:port", only to be parsed and separated in NameLookup()
Rationale:
It is recommended due to IPv6 that this convention be avoided. IPv6 addresses contain a colon, implying that proper parsing requires users to specify a bracketed string, if you are specifying a port: [0:1:2:3:4:5:6:7]:8333. For this reason, all new APIs -- most notably, libc function getaddrinfo(3) -- always keep hostname and port separate.
gethostbyname(3) is deprecated, and we need to switch to getaddrinfo(3). The commit is fine as-is, and relies on a well-tested API, so I did not request revision. But long term, again due to IPv6, it is recommended that all applications use getaddrinfo(3). This function is supported in winsock, freebsd (macos) and linux, all our supported platforms.
So, separate hostname and port, and you're golden with this commit.
Thanks.
-
sipa commented at 11:56 AM on May 6, 2011: member
I actually started writing this patch by using getaddrinfo, since its interface is much cleaner and supports seamless upgrading to IPv6. Not knowing what the compatibility of that is with other operating systems, i sticked to gethostbyname.
Considering IPv6 hostnames, I would suggest first trying to parse the string passed as [host]:port, and if this parsing fails, resort to host:port. Otherwise we will still need some function somewhere to do that parsing anyway, if people want to pass an address including a port number on the command line or config file somewhere.
-
a6a5bb7c20
Support for name lookups in -connect and -addnode
* A new option -dns is introduced that enables name lookups in -connect and -addnode, which is not enabled by default, as it may be considered a security issue. * A Lookup function is added that supports retrieving one or more addresses based on a host name * CAddress constructors (optionally) support name lookups. * The different places in the source code that did name lookups are refactored to use NameLookup or CAddress instead (dns seeding, irc server lookup, getexternalip, ...). * Removed ToStringLog() from CAddress, and switched to ToString(), since it was empty.
-
sipa commented at 9:52 PM on May 10, 2011: member
Added string+port number constructors.
-
jgarzik commented at 9:59 PM on May 10, 2011: contributor
ACK
- jgarzik referenced this in commit 9398bf946c on May 12, 2011
- jgarzik merged this on May 12, 2011
- jgarzik closed this on May 12, 2011
- dexX7 referenced this in commit 94b65c2d55 on Nov 15, 2014
- btcdrak referenced this in commit ade0464b58 on Nov 28, 2015
- CodeShark referenced this in commit a1a169e1aa on Jan 18, 2017
- CodeShark referenced this in commit 5e9f6942c6 on Jan 18, 2017
- deadalnix referenced this in commit a8eef2eb19 on Jan 19, 2017
- deadalnix referenced this in commit 569420e41f on Jan 19, 2017
- lateminer referenced this in commit 6afceda9b2 on Dec 9, 2017
- classesjack referenced this in commit 9fba9abd56 on Jan 2, 2018
- rajarshimaitra referenced this in commit a7f830d7f1 on Aug 5, 2021
- DrahtBot locked this on Sep 8, 2021