lib/rubydns/resolver.rb in rubydns-0.9.4 vs lib/rubydns/resolver.rb in rubydns-1.0.0
- old
+ new
@@ -32,10 +32,19 @@
class ResolutionFailure < StandardError
end
class Resolver
+ # Wait for up to 2 seconds for a response. Override with `options[:timeout]`
+ DEFAULT_TIMEOUT = 5.0
+
+ # 10ms wait between making requests. Override with `options[:delay]`
+ DEFAULT_DELAY = 0.01
+
+ # Try a given request 5 times before failing. Override with `options[:retries]`.
+ DEFAULT_RETRIES = 10
+
include Celluloid::IO
# Servers are specified in the same manor as options[:listen], e.g.
# [:tcp/:udp, address, port]
# In the case of multiple servers, they will be checked in sequence.
@@ -87,12 +96,12 @@
# Yields a list of `Resolv::IPv4` and `Resolv::IPv6` addresses for the given `name` and `resource_class`. Raises a ResolutionFailure if no severs respond.
def addresses_for(name, resource_class = Resolv::DNS::Resource::IN::A, options = {})
name = fully_qualified_name(name)
cache = options.fetch(:cache, {})
- retries = options.fetch(:retries, 10)
- delay = options.fetch(:delay, 0.01)
+ retries = options.fetch(:retries, DEFAULT_RETRIES)
+ delay = options.fetch(:delay, DEFAULT_DELAY)
records = lookup(name, resource_class, cache) do |name, resource_class|
response = nil
retries.times do |i|
@@ -126,10 +135,10 @@
abort ResolutionFailure.new("Could not find any addresses for #{name}.")
end
end
def request_timeout
- @options[:timeout] || 1
+ @options[:timeout] || DEFAULT_TIMEOUT
end
# Send the message to available servers. If no servers respond correctly, nil is returned. This result indicates a failure of the resolver to correctly contact any server and get a valid response.
def dispatch_request(message)
request = Request.new(message, @servers)