Module: DevDNSd::ApplicationMethods::Server
- Included in:
- DevDNSd::Application
- Defined in:
- lib/devdnsd/application.rb
Overview
Methods to process requests.
Instance Method Summary (collapse)
-
- (Object) perform_server
Starts the DNS server.
-
- (Object) process_rule(rule, type, match_data, transaction)
Processes a DNS rule.
-
- (Object) process_rule_in_classes(rule, match_data, transaction)
Processes a rule against a set of DNS resource classes.
Instance Method Details
- (Object) perform_server
Starts the DNS server.
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/devdnsd/application.rb', line 276 def perform_server application = self RubyDNS::run_server(listen: [[:udp, @config.address, @config.port.to_integer]]) do self.logger = application.logger match(/.+/, DevDNSd::Application::ANY_CLASSES) do |match_data, transaction| transaction.append_question! application.config.rules.each { |rule| application.process_rule_in_classes(rule, match_data, transaction) } # During debugging, wrap the inside of the block with a begin rescue and PRINT the exception because RubyDNS hides it. end # Default DNS handler and event handlers otherwise { |transaction| transaction.failure!(:NXDomain) } self.on(:start) { application.on_start } self.on(:stop) { application.on_stop } end end |
- (Object) process_rule(rule, type, match_data, transaction)
Processes a DNS rule.
299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/devdnsd/application.rb', line 299 def process_rule(rule, type, match_data, transaction) reply, type = perform_process_rule(rule, type, match_data, transaction) self.logger.debug(reply ? self.i18n.reply(reply, type) : self.i18n.no_reply) if reply then transaction.respond!(*finalize_reply(reply, rule, type)) elsif reply.is_a?(FalseClass) then false else nil end end |
- (Object) process_rule_in_classes(rule, match_data, transaction)
Processes a rule against a set of DNS resource classes.
317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/devdnsd/application.rb', line 317 def process_rule_in_classes(rule, match_data, transaction) # Get the subset of handled class that is valid for the rule resource_classes = DevDNSd::Application::ANY_CLASSES & rule.resource_class.ensure_array resource_classes = resource_classes & [transaction.resource_class] if transaction.resource_class != DevDNSd::Application::ANY_REQUEST if resource_classes.present? then resource_classes.each do |resource_class| # Now for every class matches = rule.match_host(match_data[0]) self.process_rule(rule, resource_class, rule.is_regexp? ? matches : nil, transaction) if matches end end end |