Class: Dnsruby::Cache::CacheData

Inherits:
Object
  • Object
show all
Defined in:
lib/Dnsruby/Cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CacheData



123
124
125
126
127
# File 'lib/Dnsruby/Cache.rb', line 123

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.



89
90
91
# File 'lib/Dnsruby/Cache.rb', line 89

def expiration
  @expiration
end

Instance Method Details

#get_expiration(m) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/Dnsruby/Cache.rb', line 108

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



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/Dnsruby/Cache.rb', line 95

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



90
91
92
93
94
# File 'lib/Dnsruby/Cache.rb', line 90

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

#to_sObject



128
129
130
# File 'lib/Dnsruby/Cache.rb', line 128

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