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 28 def initialize(family, options) 29 super 30 @ns_index = 0 31 @resolver_options = DEFAULTS.merge(@options.resolver_options) 32 @socket_type = @resolver_options.fetch(:socket_type, :udp) 33 @nameserver = if (nameserver = @resolver_options[:nameserver]) 34 nameserver = nameserver[family] if nameserver.is_a?(Hash) 35 Array(nameserver) 36 end 37 @ndots = @resolver_options.fetch(:ndots, 1) 38 @search = Array(@resolver_options[:search]).map { |srch| srch.scan(/[^.]+/) } 39 @_timeouts = Array(@resolver_options[:timeouts]) 40 @timeouts = Hash.new { |timeouts, host| timeouts[host] = @_timeouts.dup } 41 @name = @message_id = @timer = nil 42 @queries = {} 43 @read_buffer = "".b 44 @write_buffer = Buffer.new(@resolver_options[:packet_size]) 45 @state = :idle 46 end
Public Instance methods
<<(connection)
[show source]
# File lib/httpx/resolver/native.rb 105 def <<(connection) 106 if @nameserver.nil? 107 ex = ResolveError.new("No available nameserver") 108 ex.set_backtrace(caller) 109 connection.force_close 110 throw(:resolve_error, ex) 111 else 112 @connections << connection 113 resolve 114 end 115 end
call()
[show source]
# File lib/httpx/resolver/native.rb 75 def call 76 case @state 77 when :idle, :closed 78 return if @connections.empty? 79 80 transition(:idle) if @state == :closed 81 transition(:open) 82 83 consume if @state == :open 84 when :open 85 consume 86 end 87 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 == :idle || @state == :closed 69 end
closed_for_select?()
[show source]
# File lib/httpx/resolver/native.rb 89 def closed_for_select? 90 @state == :closed 91 end
force_close(*)
[show source]
# File lib/httpx/resolver/native.rb 52 def force_close(*) 53 @timer.cancel if @timer 54 @timer = @name = @message_id = 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 133 def handle_error(error) 134 if error.respond_to?(:connection) && 135 error.respond_to?(:host) 136 reset_hostname(error.host, connection: error.connection) 137 else 138 @queries.each do |host, connection| 139 reset_hostname(host, connection: connection) 140 end 141 end 142 143 super 144 end
handle_socket_timeout(interval)
[show source]
# File lib/httpx/resolver/native.rb 131 def handle_socket_timeout(interval); end
interests()
[show source]
# File lib/httpx/resolver/native.rb 93 def interests 94 case @state 95 when :idle 96 transition(:open) 97 when :closed 98 transition(:idle) 99 transition(:open) 100 end 101 102 calculate_interests 103 end
timeout()
[show source]
# File lib/httpx/resolver/native.rb 117 def timeout 118 return unless @name 119 120 @start_timeout = Utils.now 121 122 timeouts = @timeouts[@name] 123 124 return if timeouts.empty? 125 126 log(level: 2) { "resolver #{FAMILY_TYPES[@record_type]}: next timeout #{timeouts.first} secs... (#{timeouts.size - 1} left)" } 127 128 timeouts.first 129 end