Class: Net::DNS::MDNS::Answer
- Inherits:
-
Object
- Object
- Net::DNS::MDNS::Answer
- Defined in:
- lib/net/dns/mdns.rb
Instance Attribute Summary collapse
-
#cacheflush ⇒ Object
readonly
Returns the value of attribute cacheflush.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#retries ⇒ Object
Returns the value of attribute retries.
-
#toa ⇒ Object
readonly
TOA - time of arrival (of an answer).
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
Instance Method Summary collapse
- #absolute? ⇒ Boolean
- #expired? ⇒ Boolean
- #expiry ⇒ Object
-
#initialize(name, ttl, data, cacheflush) ⇒ Answer
constructor
A new instance of Answer.
- #refresh ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(name, ttl, data, cacheflush) ⇒ Answer
Returns a new instance of Answer.
212 213 214 215 216 217 218 219 |
# File 'lib/net/dns/mdns.rb', line 212 def initialize(name, ttl, data, cacheflush) @name = name @ttl = ttl @data = data @cacheflush = cacheflush @toa = Time.now.to_i @retries = 0 end |
Instance Attribute Details
#cacheflush ⇒ Object (readonly)
Returns the value of attribute cacheflush.
207 208 209 |
# File 'lib/net/dns/mdns.rb', line 207 def cacheflush @cacheflush end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
207 208 209 |
# File 'lib/net/dns/mdns.rb', line 207 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
207 208 209 |
# File 'lib/net/dns/mdns.rb', line 207 def name @name end |
#retries ⇒ Object
Returns the value of attribute retries.
210 211 212 |
# File 'lib/net/dns/mdns.rb', line 210 def retries @retries end |
#toa ⇒ Object (readonly)
TOA - time of arrival (of an answer)
209 210 211 |
# File 'lib/net/dns/mdns.rb', line 209 def toa @toa end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
207 208 209 |
# File 'lib/net/dns/mdns.rb', line 207 def ttl @ttl end |
Instance Method Details
#absolute? ⇒ Boolean
241 242 243 |
# File 'lib/net/dns/mdns.rb', line 241 def absolute? @cacheflush end |
#expired? ⇒ Boolean
237 238 239 |
# File 'lib/net/dns/mdns.rb', line 237 def expired? true if Time.now.to_i > expiry end |
#expiry ⇒ Object
233 234 235 |
# File 'lib/net/dns/mdns.rb', line 233 def expiry toa + (ttl == 0 ? 1 : ttl) end |
#refresh ⇒ Object
225 226 227 228 229 230 231 |
# File 'lib/net/dns/mdns.rb', line 225 def refresh # Percentage points are from mDNS percent = [80,85,90,95][retries] # TODO - add a 2% of TTL jitter toa + ttl * percent / 100 if percent end |
#to_s ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/net/dns/mdns.rb', line 245 def to_s s = "#{name.to_s} (#{ttl}) " s << '!' if absolute? s << '-' if ttl == 0 s << " #{DNS.rrname(data)}" case data when IN::A s << " #{data.address.to_s}" when IN::PTR s << " #{data.name}" when IN::SRV s << " #{data.target}:#{data.port}" when IN::TXT s << " #{data.strings.first.inspect}#{data.strings.length > 1 ? ', ...' : ''}" when IN::HINFO s << " os=#{data.os}, cpu=#{data.cpu}" else s << data.inspect end s end |
#type ⇒ Object
221 222 223 |
# File 'lib/net/dns/mdns.rb', line 221 def type data.class end |