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.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
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.
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( = {}) @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 @ttl = [:ttl] || 300 @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.
15 16 17 |
# File 'lib/ddns-server.rb', line 15 def address @address end |
#daemon ⇒ Object (readonly)
Returns the value of attribute daemon.
19 20 21 |
# File 'lib/ddns-server.rb', line 19 def daemon @daemon end |
#gaddress ⇒ Object (readonly)
Returns the value of attribute gaddress.
17 18 19 |
# File 'lib/ddns-server.rb', line 17 def gaddress @gaddress end |
#gossip ⇒ Object (readonly)
Returns the value of attribute gossip.
24 25 26 |
# File 'lib/ddns-server.rb', line 24 def gossip @gossip end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
14 15 16 |
# File 'lib/ddns-server.rb', line 14 def hostname @hostname end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
21 22 23 |
# File 'lib/ddns-server.rb', line 21 def logger @logger end |
#loglevel ⇒ Object (readonly)
Returns the value of attribute loglevel.
22 23 24 |
# File 'lib/ddns-server.rb', line 22 def loglevel @loglevel end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
16 17 18 |
# File 'lib/ddns-server.rb', line 16 def port @port end |
#resolver ⇒ Object (readonly)
Returns the value of attribute resolver.
20 21 22 |
# File 'lib/ddns-server.rb', line 20 def resolver @resolver end |
#sock ⇒ Object (readonly)
Returns the value of attribute sock.
18 19 20 |
# File 'lib/ddns-server.rb', line 18 def sock @sock end |
#ttl ⇒ Object
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, , 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, , data| address == name end end |