Module: DevDNSd::Server

Included in:
Application
Defined in:
lib/devdnsd/server.rb

Overview

Methods to process requests.

Instance Method Summary (collapse)

Instance Method Details

- (Object) perform_server Also known as: startup

Starts the DNS server.

Returns:

  • (Object)

    The result of stop callbacks.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/devdnsd/server.rb', line 14

def perform_server
  application = self

  @server = RubyDNS.run_server(server_options) do
    self.logger = application.logger

    match(/.+/, DevDNSd::Application::ANY_CLASSES) do |transaction, match_data|
      # During debugging, wrap the inside of the block with a begin rescue and PRINT the exception because RubyDNS hides it.
      application.config.rules.each { |rule| application.process_rule_in_classes(rule, match_data, transaction) }
    end

    # Default DNS handler and event handlers
    otherwise { |transaction| transaction.failure!(:NXDomain) }
    on(:start) { application.on_start }
    on(:stop) { application.on_stop }
  end
end

- (Object) process_rule(rule, type, match_data, transaction)

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)

    The current DNS transaction (http://rubydoc.info/gems/rubydns/RubyDNS/Transaction).



40
41
42
43
44
45
46
47
48
49
# File 'lib/devdnsd/server.rb', line 40

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
    transaction.respond!(*finalize_reply(reply, rule, type))
  else
    reply.is_a?(FalseClass) ? false : nil
  end
end

- (Object) process_rule_in_classes(rule, match_data, transaction)

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)

    The current DNS transaction (http://rubydoc.info/gems/rubydns/RubyDNS/Transaction).



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/devdnsd/server.rb', line 56

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 &= [transaction.resource_class] if transaction.resource_class != DevDNSd::Application::ANY_REQUEST

  if resource_classes.present?
    resource_classes.each do |resource_class| # Now for every class
      matches = rule.match_host(match_data[0])
      process_rule(rule, resource_class, rule.regexp? ? matches : nil, transaction) if matches
    end
  end
end