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.



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
51
52
53
54
# File 'lib/ddns-server.rb', line 26

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
  @ttl           = options[:ttl] || 300
  @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.



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

def address
  @address
end

#daemonObject (readonly)

Returns the value of attribute daemon.



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

def daemon
  @daemon
end

#gaddressObject (readonly)

Returns the value of attribute gaddress.



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

def gaddress
  @gaddress
end

#gossipObject (readonly)

Returns the value of attribute gossip.



24
25
26
# File 'lib/ddns-server.rb', line 24

def gossip
  @gossip
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



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

def hostname
  @hostname
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#loglevelObject (readonly)

Returns the value of attribute loglevel.



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

def loglevel
  @loglevel
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#resolverObject (readonly)

Returns the value of attribute resolver.



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

def resolver
  @resolver
end

#sockObject (readonly)

Returns the value of attribute sock.



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

def sock
  @sock
end

#ttlObject

Returns the value of attribute ttl.



23
24
25
# File 'lib/ddns-server.rb', line 23

def ttl
  @ttl
end

Instance Method Details

#lookup_a_record(name) ⇒ Object



56
57
58
59
60
# File 'lib/ddns-server.rb', line 56

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

#lookup_ptr_record(name) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/ddns-server.rb', line 62

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