Class: DDNS::Attributes
- Inherits:
-
Object
- Object
- DDNS::Attributes
- Defined in:
- lib/ddns-server.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#daemon ⇒ Object
readonly
Returns the value of attribute daemon.
-
#gaddress ⇒ Object
readonly
Returns the value of attribute gaddress.
-
#gossip ⇒ Object
readonly
Returns the value of attribute gossip.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#loglevel ⇒ Object
readonly
Returns the value of attribute loglevel.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#resolver ⇒ Object
readonly
Returns the value of attribute resolver.
-
#sock ⇒ Object
readonly
Returns the value of attribute sock.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Attributes
constructor
A new instance of Attributes.
- #lookup_a_record(name) ⇒ Object
- #lookup_ptr_record(name) ⇒ Object
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( = {}) @hostname = [:hostname] || Socket.gethostname @address = [:address] || ('0.0.0.0') @port = [:port] || 10053 @gaddress = [:gaddress] || IPSocket.getaddress(Socket.gethostname) @sock = [:sock] @daemon = [:daemon] @resolver = [:resolver] @logger = [:logger] || Logger.new($stderr) @loglevel = [:loglevel] || Logger::INFO @logger.level = @loglevel @gossip = RGossip::Client.new( ([:initial_nodes] || []), @gaddress, @hostname) @gossip.callback = lambda do |action, address, , 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
#address ⇒ Object (readonly)
Returns the value of attribute address.
13 14 15 |
# File 'lib/ddns-server.rb', line 13 def address @address end |
#daemon ⇒ Object (readonly)
Returns the value of attribute daemon.
17 18 19 |
# File 'lib/ddns-server.rb', line 17 def daemon @daemon end |
#gaddress ⇒ Object (readonly)
Returns the value of attribute gaddress.
15 16 17 |
# File 'lib/ddns-server.rb', line 15 def gaddress @gaddress end |
#gossip ⇒ Object (readonly)
Returns the value of attribute gossip.
21 22 23 |
# File 'lib/ddns-server.rb', line 21 def gossip @gossip end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
12 13 14 |
# File 'lib/ddns-server.rb', line 12 def hostname @hostname end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
19 20 21 |
# File 'lib/ddns-server.rb', line 19 def logger @logger end |
#loglevel ⇒ Object (readonly)
Returns the value of attribute loglevel.
20 21 22 |
# File 'lib/ddns-server.rb', line 20 def loglevel @loglevel end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
14 15 16 |
# File 'lib/ddns-server.rb', line 14 def port @port end |
#resolver ⇒ Object (readonly)
Returns the value of attribute resolver.
18 19 20 |
# File 'lib/ddns-server.rb', line 18 def resolver @resolver end |
#sock ⇒ Object (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, , 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, , data| address == name end end |