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
  1. sipa commented at 11:46 AM on May 3, 2011: member
    • 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, ...).
  2. 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.

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

  4. sipa closed this on May 4, 2011

  5. sipa reopened this on May 5, 2011

  6. jgarzik commented at 2:55 PM on May 5, 2011: contributor

    ACK, thanks for revising

  7. jgarzik commented at 11:37 AM on May 6, 2011: contributor
  8. 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:

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

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

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

  10. 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.
    a6a5bb7c20
  11. sipa commented at 9:52 PM on May 10, 2011: member

    Added string+port number constructors.

  12. jgarzik commented at 9:59 PM on May 10, 2011: contributor

    ACK

  13. jgarzik referenced this in commit 9398bf946c on May 12, 2011
  14. jgarzik merged this on May 12, 2011
  15. jgarzik closed this on May 12, 2011

  16. dexX7 referenced this in commit 94b65c2d55 on Nov 15, 2014
  17. btcdrak referenced this in commit ade0464b58 on Nov 28, 2015
  18. CodeShark referenced this in commit a1a169e1aa on Jan 18, 2017
  19. CodeShark referenced this in commit 5e9f6942c6 on Jan 18, 2017
  20. deadalnix referenced this in commit a8eef2eb19 on Jan 19, 2017
  21. deadalnix referenced this in commit 569420e41f on Jan 19, 2017
  22. lateminer referenced this in commit 6afceda9b2 on Dec 9, 2017
  23. classesjack referenced this in commit 9fba9abd56 on Jan 2, 2018
  24. rajarshimaitra referenced this in commit a7f830d7f1 on Aug 5, 2021
  25. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 21:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me