Class: DNSTraverse::Response
- Inherits:
-
Object
- Object
- DNSTraverse::Response
- Defined in:
- lib/dnstraverse/response.rb
Overview
get a response to a query (or pass in the response if you already have one) creates lots of stats and info, caching as much as possible
Defined Under Namespace
Classes: Loop, Maxdepth, NoGlue
Instance Attribute Summary collapse
-
#decoded_query ⇒ Object
readonly
Returns the value of attribute decoded_query.
-
#infocache ⇒ Object
readonly
Returns the value of attribute infocache.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#starters ⇒ Object
readonly
:referral/:restart only.
-
#starters_bailiwick ⇒ Object
readonly
:referral/:restart only.
-
#stats_key ⇒ Object
readonly
Returns the value of attribute stats_key.
-
#status ⇒ Object
readonly
our status, expanding on DecodedQuery status.
Instance Method Summary collapse
-
#cleanup ⇒ Object
clean up the workings.
-
#evaluate ⇒ Object
enrich the decoded_query to do the cache, lame checking and get starters.
-
#initialize(args) ⇒ Response
constructor
:qname, :qclass, :qtype, :ip, :bailiwick, optional :message.
- #inside_bailiwick?(name) ⇒ Boolean
- #method_missing(key, *args, &block) ⇒ Object
-
#to_s ⇒ Object
convert to string - check for our enrichments, or use decoded_status.
-
#update_stats_key ⇒ Object
set the statistics key - this is used to decide when to merge statistics together.
Constructor Details
#initialize(args) ⇒ Response
:qname, :qclass, :qtype, :ip, :bailiwick, optional :message
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dnstraverse/response.rb', line 32 def initialize(args) dqc_args = { :qname => args[:qname], :qclass => args[:qclass], :qtype => args[:qtype], :ip => args[:ip], :bailiwick => args[:bailiwick], :message => args[:message] } @decoded_query = args[:decoded_query_cache].query(dqc_args) @server = args[:server] @infocache = InfoCache.new(args[:infocache]) # our infocache @starters = nil # initial servers for :referral/:restart @starters_bailiwick = nil # for initial servers for :referral/:restart @parent_ip = args[:parent_ip] # passed in in case we get referral_lame, for the key evaluate update_stats_key return self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, *args, &block) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/dnstraverse/response.rb', line 47 def method_missing(key, *args, &block) if @decoded_query.respond_to?(key) then return @decoded_query.send(key, *args) end super end |
Instance Attribute Details
#decoded_query ⇒ Object (readonly)
Returns the value of attribute decoded_query.
24 25 26 |
# File 'lib/dnstraverse/response.rb', line 24 def decoded_query @decoded_query end |
#infocache ⇒ Object (readonly)
Returns the value of attribute infocache.
25 26 27 |
# File 'lib/dnstraverse/response.rb', line 25 def infocache @infocache end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
29 30 31 |
# File 'lib/dnstraverse/response.rb', line 29 def server @server end |
#starters ⇒ Object (readonly)
:referral/:restart only
27 28 29 |
# File 'lib/dnstraverse/response.rb', line 27 def starters @starters end |
#starters_bailiwick ⇒ Object (readonly)
:referral/:restart only
27 28 29 |
# File 'lib/dnstraverse/response.rb', line 27 def starters_bailiwick @starters_bailiwick end |
#stats_key ⇒ Object (readonly)
Returns the value of attribute stats_key.
28 29 30 |
# File 'lib/dnstraverse/response.rb', line 28 def stats_key @stats_key end |
#status ⇒ Object (readonly)
our status, expanding on DecodedQuery status
26 27 28 |
# File 'lib/dnstraverse/response.rb', line 26 def status @status end |
Instance Method Details
#cleanup ⇒ Object
clean up the workings
68 69 70 71 72 73 |
# File 'lib/dnstraverse/response.rb', line 68 def cleanup @infocache = nil ###@cacheable_good = @cacheable_bad = nil @starters = @starters_bailiwick = nil ###@auth_ns = @auth_soa = @auth_other = nil end |
#evaluate ⇒ Object
enrich the decoded_query to do the cache, lame checking and get starters
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/dnstraverse/response.rb', line 85 def evaluate @status = @decoded_query.status # use this as a base if @status != :exception # XXX order of cacheable_good is answer, authority, additional # perhaps we should add some checking for overlap between sections? @infocache.add(@decoded_query.cacheable_good) end case @decoded_query.status when :restart @starters, @starters_bailiwick = @infocache.get_startservers(@decoded_query.endname) when :referral @starters, @starters_bailiwick = @infocache.get_startservers(@decoded_query.endname) unless @decoded_query.bailiwick.nil? or @starters_bailiwick =~ /\.#{@decoded_query.bailiwick}$/i @status = :referral_lame end starternames = @starters.map { |x| x[:name].to_s.downcase } if starternames.sort != @decoded_query..sort @decoded_query.warnings_add "Referred authority names do not match query cache expectations" end end end |
#inside_bailiwick?(name) ⇒ Boolean
75 76 77 78 79 80 81 82 |
# File 'lib/dnstraverse/response.rb', line 75 def inside_bailiwick?(name) return true if @bailiwick.nil? bwend = ".#{@bailiwick}" namestr = name.to_s return true if namestr.casecmp(@bailiwick) == 0 return true if namestr =~ /#{bwend}$/i return false end |
#to_s ⇒ Object
convert to string - check for our enrichments, or use decoded_status
108 109 110 111 112 113 114 115 |
# File 'lib/dnstraverse/response.rb', line 108 def to_s case @status when :referral_lame return "Lame referral to #{@decoded_query.}" else return @decoded_query.to_s end end |
#update_stats_key ⇒ Object
set the statistics key - this is used to decide when to merge statistics together. the same key = merge, different key = keep separate this is why exception name/message is added for exception types
57 58 59 60 61 62 63 64 65 |
# File 'lib/dnstraverse/response.rb', line 57 def update_stats_key r = @decoded_query @stats_key = "key:#{@status}:#{r.ip}:#{@server}:#{r.qname}:#{r.qclass}:#{r.qtype}" if @status == :exception and r..is_a? Exception then @stats_key+= ":#{r.}" elsif @status == :referral_lame then @stats_key+= ":#{@parent_ip}" end end |