Class: DDNS::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/ddns-server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Attributes

Returns a new instance of Attributes.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ddns-server.rb', line 23

def initialize(options = {})
  @hostname      = options[:hostname] || Socket.gethostname
  @address       = options[:address] || ('0.0.0.0')
  @port          = options[:port] || 10053
  @gaddress      = options[:gaddress] || IPSocket.getaddress(Socket.gethostname)
  @sock          = options[:sock]
  @daemon        = options[:daemon]
  @resolver      = options[:resolver]
  @logger        = options[:logger] || Logger.new($stderr)
  @loglevel      = options[:loglevel] || Logger::INFO
  @logger.level  = @loglevel

  @gossip = RGossip::Client.new(
    (options[:initial_nodes] || []), @gaddress, @hostname)

  @gossip.callback = lambda do |action, address, timestamp, data|
    case action
    when :add
      logger.info "Add node: #{address}(#{data})"
    when :comeback
      logger.info "Come back node: #{address}(#{data})"
    when :delete
      logger.info "Delete node: #{address}(#{data})"
    end
  end

  $DDNS_ATTR = self
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



13
14
15
# File 'lib/ddns-server.rb', line 13

def address
  @address
end

#daemonObject (readonly)

Returns the value of attribute daemon.



17
18
19
# File 'lib/ddns-server.rb', line 17

def daemon
  @daemon
end

#gaddressObject (readonly)

Returns the value of attribute gaddress.



15
16
17
# File 'lib/ddns-server.rb', line 15

def gaddress
  @gaddress
end

#gossipObject (readonly)

Returns the value of attribute gossip.



21
22
23
# File 'lib/ddns-server.rb', line 21

def gossip
  @gossip
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



12
13
14
# File 'lib/ddns-server.rb', line 12

def hostname
  @hostname
end

#loggerObject (readonly)

Returns the value of attribute logger.



19
20
21
# File 'lib/ddns-server.rb', line 19

def logger
  @logger
end

#loglevelObject (readonly)

Returns the value of attribute loglevel.



20
21
22
# File 'lib/ddns-server.rb', line 20

def loglevel
  @loglevel
end

#portObject (readonly)

Returns the value of attribute port.



14
15
16
# File 'lib/ddns-server.rb', line 14

def port
  @port
end

#resolverObject (readonly)

Returns the value of attribute resolver.



18
19
20
# File 'lib/ddns-server.rb', line 18

def resolver
  @resolver
end

#sockObject (readonly)

Returns the value of attribute sock.



16
17
18
# File 'lib/ddns-server.rb', line 16

def sock
  @sock
end

Instance Method Details

#lookup_a_record(name) ⇒ Object



52
53
54
55
56
# File 'lib/ddns-server.rb', line 52

def lookup_a_record(name)
  @gossip.any? do |address, timestamp, data|
    data == name
  end
end

#lookup_ptr_record(name) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/ddns-server.rb', line 58

def lookup_ptr_record(name)
  name = name.sub(/\.in-addr\.arpa\Z/, '').split('.').reverse.join('.')

  @gossip.any? do |address, timestamp, data|
    address == name
  end
end