Class: Async::DNS::GenericHandler
- Inherits:
-
Object
- Object
- Async::DNS::GenericHandler
- Defined in:
- lib/async/dns/handler.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #error_response(query = nil, code = Resolv::DNS::RCode::ServFail) ⇒ Object
-
#initialize(server, socket) ⇒ GenericHandler
constructor
A new instance of GenericHandler.
- #process_query(data, options) ⇒ Object
Constructor Details
#initialize(server, socket) ⇒ GenericHandler
Returns a new instance of GenericHandler.
27 28 29 30 31 32 |
# File 'lib/async/dns/handler.rb', line 27 def initialize(server, socket) @server = server @socket = socket @logger = @server.logger || Console.logger end |
Instance Attribute Details
#server ⇒ Object (readonly)
Returns the value of attribute server.
34 35 36 |
# File 'lib/async/dns/handler.rb', line 34 def server @server end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
35 36 37 |
# File 'lib/async/dns/handler.rb', line 35 def socket @socket end |
Instance Method Details
#error_response(query = nil, code = Resolv::DNS::RCode::ServFail) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/async/dns/handler.rb', line 37 def error_response(query = nil, code = Resolv::DNS::RCode::ServFail) # Encoding may fail, so we need to handle this particular case: server_failure = Resolv::DNS::Message::new(query ? query.id : 0) server_failure.qr = 1 server_failure.opcode = query ? query.opcode : 0 server_failure.aa = 1 server_failure.rd = 0 server_failure.ra = 0 server_failure.rcode = code # We can't do anything at this point... return server_failure end |
#process_query(data, options) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/async/dns/handler.rb', line 53 def process_query(data, ) @logger.debug "<> Receiving incoming query (#{data.bytesize} bytes) to #{self.class.name}..." query = nil begin query = Async::DNS::(data) return @server.process_query(query, ) rescue StandardError => error @logger.error(self) { error } return error_response(query) end end |