Module: DevDNSd::ApplicationMethods::Server

Included in:
DevDNSd::Application
Defined in:
lib/devdnsd/application.rb

Overview

Methods to process requests.

Instance Method Summary collapse

Instance Method Details

#perform_serverObject

Starts the DNS server.

Returns:

  • (Object)

    The result of stop callbacks.



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'lib/devdnsd/application.rb', line 537

def perform_server
  application = self

  RubyDNS::run_server(listen: build_listen_interfaces) do
    self.logger = application.logger

    match(/.+/, DevDNSd::Application::ANY_CLASSES) do |transaction, match_data|
      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) }
    on(:start) { application.on_start }
    on(:stop) { application.on_stop }
  end
end

#process_rule(rule, type, match_data, transaction) ⇒ Object

Processes a DNS rule.

Parameters:

  • rule (Rule)

    The rule to process.

  • type (Symbol)

    The type of the query.

  • match_data (MatchData|nil)

    If the rule pattern was a Regexp, then this holds the match data, otherwise nil is passed.

  • transaction (RubyDNS::Transaction)


560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/devdnsd/application.rb', line 560

def process_rule(rule, type, match_data, transaction)
  reply, type = perform_process_rule(rule, type, match_data, transaction)
  logger.debug(reply ? i18n.reply(reply, type) : i18n.no_reply)

  if reply then
    transaction.respond!(*finalize_reply(reply, rule, type))
  elsif reply.is_a?(FalseClass) then
    false
  else
    nil
  end
end

#process_rule_in_classes(rule, match_data, transaction) ⇒ Object

Processes a rule against a set of DNS resource classes.

Parameters:

  • rule (Rule)

    The rule to process.

  • match_data (MatchData|nil)

    If the rule pattern was a Regexp, then this holds the match data, otherwise nil is passed.

  • transaction (RubyDNS::Transaction)


578
579
580
581
582
583
584
585
586
587
588
589
# File 'lib/devdnsd/application.rb', line 578

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])
      process_rule(rule, resource_class, rule.is_regexp? ? matches : nil, transaction) if matches
    end
  end
end