Class: Dnsign::ResolveUpdateLoop

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsign/resolve_update_loop.rb

Instance Method Summary collapse

Constructor Details

#initialize(domain, dns_service, ip_resolver, opts = {}) ⇒ ResolveUpdateLoop

Returns a new instance of ResolveUpdateLoop.


12
13
14
15
16
17
18
19
20
# File 'lib/dnsign/resolve_update_loop.rb', line 12

def initialize(domain, dns_service, ip_resolver, opts={})
  @domain      = domain
  @ip_resolver = ip_resolver
  @dns_service = dns_service
  @timers      = Timers::Group.new

  @verbose     = opts[:verbose].nil? ? true : opts[:verbose]
  @interval    = opts[:interval] || 300
end

Instance Method Details

#kickoffObject


22
23
24
25
26
27
# File 'lib/dnsign/resolve_update_loop.rb', line 22

def kickoff
  if @interval > 0
    @timer = @timers.every( @interval ) { update }
    loop { @timers.wait }
  end
end

#updateObject


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dnsign/resolve_update_loop.rb', line 29

def update
  real_ip = resolve_real_ip
  dns_ip  = retrieve_dns_ip

  if real_ip != dns_ip
    update_dns_ip(real_ip)
    log "UPDATE:   Public #{real_ip} differs from the resolved #{dns_ip}"
    true
  else
    log "SKIPPING: Public #{real_ip} matches with the resolved #{dns_ip}"
    false
  end
end