Object
Manages a single DNS question message across one or more servers.
# File lib/rubydns/resolver.rb, line 80 def self.fetch(*args) request = self.new(*args) request.callback do |message| yield message end request.errback do |error| # In the case of a timeout, error will be nil, so we make one up. yield error end request.run! end
# File lib/rubydns/resolver.rb, line 96 def initialize(message, servers, options = {}, &block) @message = message @packet = message.encode @servers = servers.dup # We select the protocol based on the size of the data: if @packet.bytesize > UDP_TRUNCATION_SIZE @servers.delete_if{|server| server[0] == :udp} end # Measured in seconds: @timeout = options[:timeout] || 5 @logger = options[:logger] end
Once either an exception or message is received, we update the status of this request.
# File lib/rubydns/resolver.rb, line 122 def process_response!(response) finish_request! if Exception === response @logger.warn "[#{@message.id}] Failure while processing response #{response}!" if @logger RubyDNS.log_exception(@logger, response) if @logger try_next_server! elsif response.tc != 0 @logger.warn "[#{@message.id}] Received truncated response!" if @logger try_next_server! elsif response.id != @message.id @logger.warn "[#{@message.id}] Received response with incorrect message id: #{response.id}" if @logger try_next_server! else @logger.debug "[#{@message.id}] Received valid response #{response.inspect}" if @logger succeed response end end
Generated with the Darkfish Rdoc Generator 2.