Class: Net::DNS::MDNS::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/net/dns/mdns.rb

Constant Summary collapse

RETRIES =

Normally we see our own question, so an update will occur right away, causing retries to be set to 1. If we don’t see our own question, for some reason, we’ll ask again a second later.

[1, 1, 2, 4]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ Question

Returns a new instance of Question.



278
279
280
281
282
283
284
285
# File 'lib/net/dns/mdns.rb', line 278

def initialize(name, type)
  @name = name
  @type = type

  @lastq = Time.now.to_i

  @retries = 0
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



270
271
272
# File 'lib/net/dns/mdns.rb', line 270

def name
  @name
end

#retriesObject

Returns the value of attribute retries.



270
271
272
# File 'lib/net/dns/mdns.rb', line 270

def retries
  @retries
end

#typeObject (readonly)

Returns the value of attribute type.



270
271
272
# File 'lib/net/dns/mdns.rb', line 270

def type
  @type
end

Instance Method Details

#refreshObject

Questions are asked 4 times, repeating at increasing intervals of 1, 2, and 4 seconds.



297
298
299
300
# File 'lib/net/dns/mdns.rb', line 297

def refresh
  r = RETRIES[retries]
  @lastq + r if r
end

#to_sObject



302
303
304
# File 'lib/net/dns/mdns.rb', line 302

def to_s
  "#{@name.to_s}/#{DNS.rrname @type} (#{@retries})"
end

#updateObject

Update the number of times the question has been asked based on having seen the question, so that the question is considered asked whether we asked it, or another machine/process asked.



290
291
292
293
# File 'lib/net/dns/mdns.rb', line 290

def update
  @retries += 1
  @lastq = Time.now.to_i
end