[Twisted-Python] twisted.names.client.getHostByName() vs. reactor.resolve()

Hi, I need to do a DNS resolution of a hostname to an IPv4 address in order to then send out a UDP packet via twisted’s APIs. There appears to be 2 ways to do this. Is it better to use twisted.names.client.getHostByName(), or is it better to use reactor.resolve()? Is there a bias for one over the other? Is one deprecated and the other isn’t? BTW they appear to behave differently; at work, I have a hostname that the one (getHostByName) resolves to None in the callback, and the other (reactor.resolve) resolves to a valid IP address in the callback. That analysis is based on twisted 12.3.0 on linux. Naturally I'm preferring reactor.resolve at this point, as it works better for the hostname in question (it happens to be a hostname that uses a CNAME record to alias to another hostname). Thanks, -- Benjamin Rutt

On 02:16 pm, rutt.4@osu.edu wrote:
`reactor.resolve` is "do something, who knows what really, to turn a name into an IPv4 address". `twisted.names.client.getHostByName` is "use Twisted's DNS client implementation to issue the necessary DNS queries to resolve a name into an IPv4 or IPv6 address". If you definitely only care about IPv4 then `reactor.resolve` is going to work correctly in more situations. By default it will use the system resolver. Therefore, by default, you will get whatever weird configuration the system resolver has been given (for example: use /etc/hosts or use mDNS or use NIS or YP or whatever. Note that `reactor.resolve` is a pluggable interface and application code is allowed to substitute an alternate resolver implementation which may work in some other way. If you care specifically about DNS or you need IPv6 or you have a reason to want to avoid threads (which, by default, `reactor.resolve` uses), you might prefer to use `twisted.names.client` directly. Most applications will probably be okay with `reactor.resolve` but I imagine this could change as IPv6 use gradually becomes more widespread. Jean-Paul

Jean-Paul, you knowledge about twisted and your willingness to help is just amazing for the framework ;) http://www.ihighfive.com

On 02:16 pm, rutt.4@osu.edu wrote:
`reactor.resolve` is "do something, who knows what really, to turn a name into an IPv4 address". `twisted.names.client.getHostByName` is "use Twisted's DNS client implementation to issue the necessary DNS queries to resolve a name into an IPv4 or IPv6 address". If you definitely only care about IPv4 then `reactor.resolve` is going to work correctly in more situations. By default it will use the system resolver. Therefore, by default, you will get whatever weird configuration the system resolver has been given (for example: use /etc/hosts or use mDNS or use NIS or YP or whatever. Note that `reactor.resolve` is a pluggable interface and application code is allowed to substitute an alternate resolver implementation which may work in some other way. If you care specifically about DNS or you need IPv6 or you have a reason to want to avoid threads (which, by default, `reactor.resolve` uses), you might prefer to use `twisted.names.client` directly. Most applications will probably be okay with `reactor.resolve` but I imagine this could change as IPv6 use gradually becomes more widespread. Jean-Paul

Jean-Paul, you knowledge about twisted and your willingness to help is just amazing for the framework ;) http://www.ihighfive.com
participants (3)
-
Benjamin Rutt
-
exarkun@twistedmatrix.com
-
Jonas Brunsgaard