Class: Dnsruby::Cache::CacheData

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsruby/cache.rb

Overview

:nodoc: all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CacheData

Returns a new instance of CacheData.



151
152
153
154
155
# File 'lib/dnsruby/cache.rb', line 151

def initialize(*args)
  @expiration = 0
  @time_stored = Time.now.to_i
  self.message=(args[0])
end

Instance Attribute Details

#expirationObject (readonly)

Returns the value of attribute expiration.



117
118
119
# File 'lib/dnsruby/cache.rb', line 117

def expiration
  @expiration
end

Instance Method Details

#get_expiration(m) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/dnsruby/cache.rb', line 136

def get_expiration(m)
  #  Find the minimum ttl of any of the rrsets
  min_ttl = 9999999
  m.each_section {|section|
    section.rrsets.each {|rrset|
      if (rrset.ttl < min_ttl)
        min_ttl = rrset.ttl
      end
    }
  }
  if (min_ttl == 9999999)
    return 0
  end
  return (Time.now.to_i + min_ttl)
end

#messageObject



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/dnsruby/cache.rb', line 123

def message
  m = Message.decode(@message.encode)
  m.cached = true
  #  @TODO@ What do we do about answerfrom, answersize, etc.?
  m.header.aa = false # Anything else to do here?
  #  Fix up TTLs!!
  offset = (Time.now - @time_stored).to_i
  m.each_resource {|rr|
    next if rr.type == Types::OPT
    rr.ttl = rr.ttl - offset
  }
  return m
end

#message=(m) ⇒ Object



118
119
120
121
122
# File 'lib/dnsruby/cache.rb', line 118

def message=(m)
  @expiration = get_expiration(m)
  @message = Message.decode(m.encode(true))
  @message.cached = true
end

#to_sObject



156
157
158
# File 'lib/dnsruby/cache.rb', line 156

def to_s
  return "#{self.message}"
end