Implements a pure ruby name resolver, which abides by the Selectable API. It delegates DNS payload encoding/decoding to the resolv stlid gem.
Methods
Public Class
Public Instance
Constants
| DEFAULTS | = | { nameserver: nil, **Resolv::DNS::Config.default_config_hash, packet_size: 512, timeouts: Resolver::RESOLVE_TIMEOUT, }.freeze | ||
| DNS_PORT | = | 53 |
Attributes
| state | [R] |
Public Class methods
new(family, options)
[show source]
# File lib/httpx/resolver/native.rb 27 def initialize(family, options) 28 super 29 @ns_index = 0 30 @resolver_options = DEFAULTS.merge(@options.resolver_options) 31 @socket_type = @resolver_options.fetch(:socket_type, :udp) 32 @nameserver = if (nameserver = @resolver_options[:nameserver]) 33 nameserver = nameserver[family] if nameserver.is_a?(Hash) 34 Array(nameserver) 35 end 36 @ndots = @resolver_options.fetch(:ndots, 1) 37 @search = Array(@resolver_options[:search]).map { |srch| srch.scan(/[^.]+/) } 38 @_timeouts = Array(@resolver_options[:timeouts]) 39 @timeouts = Hash.new { |timeouts, host| timeouts[host] = @_timeouts.dup } 40 @name = nil 41 @queries = {} 42 @read_buffer = "".b 43 @write_buffer = Buffer.new(@resolver_options[:packet_size]) 44 @state = :idle 45 @timer = nil 46 end
Public Instance methods
<<(connection)
[show source]
# File lib/httpx/resolver/native.rb 94 def <<(connection) 95 if @nameserver.nil? 96 ex = ResolveError.new("No available nameserver") 97 ex.set_backtrace(caller) 98 connection.force_close 99 throw(:resolve_error, ex) 100 else 101 @connections << connection 102 resolve 103 end 104 end
call()
[show source]
# File lib/httpx/resolver/native.rb 75 def call 76 case @state 77 when :open 78 consume 79 end 80 end
close()
[show source]
# File lib/httpx/resolver/native.rb 48 def close 49 transition(:closed) 50 end
closed?()
[show source]
# File lib/httpx/resolver/native.rb 67 def closed? 68 @state == :closed 69 end
force_close(*)
[show source]
# File lib/httpx/resolver/native.rb 52 def force_close(*) 53 @timer.cancel if @timer 54 @timer = @name = nil 55 @queries.clear 56 @timeouts.clear 57 close 58 super 59 ensure 60 terminate 61 end
handle_error(error)
[show source]
# File lib/httpx/resolver/native.rb 122 def handle_error(error) 123 if error.respond_to?(:connection) && 124 error.respond_to?(:host) 125 reset_hostname(error.host, connection: error.connection) 126 else 127 @queries.each do |host, connection| 128 reset_hostname(host, connection: connection) 129 end 130 end 131 132 super 133 end
handle_socket_timeout(interval)
[show source]
# File lib/httpx/resolver/native.rb 120 def handle_socket_timeout(interval); end
interests()
[show source]
# File lib/httpx/resolver/native.rb 82 def interests 83 case @state 84 when :idle 85 transition(:open) 86 when :closed 87 transition(:idle) 88 transition(:open) 89 end 90 91 calculate_interests 92 end
timeout()
[show source]
# File lib/httpx/resolver/native.rb 106 def timeout 107 return unless @name 108 109 @start_timeout = Utils.now 110 111 timeouts = @timeouts[@name] 112 113 return if timeouts.empty? 114 115 log(level: 2) { "resolver #{FAMILY_TYPES[@record_type]}: next timeout #{timeouts.first} secs... (#{timeouts.size - 1} left)" } 116 117 timeouts.first 118 end