class Matchd::Server

Specific implementation of the {Async::DNS::Server} using a list of rules to determine it's response

Rules will get {#call}'ed in order until the first one matches (returns truthy). If none matches, a default {Matchd::Rule::Passthrough} will get executed forwarding the query to the resolver defined via the `:resolver` option.

Attributes

resolver[R]
rules[R]

Public Class Methods

new(rules, listen, options = {}) click to toggle source

@param rules [Matchd::Registry|Array<Matchd.Rule>] A rules registry @param listen [Array] On which interfaces to listen (`[[<protocol>, <ip>, <port>], …]`). See `Matchd::Glue::AsyncEndpoint` for more formats. @param [Hash] options @option options [Array|Async::DNS::Resolver] :resolver The upstream resolvers (`[[<protocol>, <ip>, <port>], …]`). See `Matchd::Glue::AsyncEndpoint` for more formats. (default: `Async::DNS::System.nameservers`) @option options [TrueClass|FalseClass] :forced_passthtough The default Passthrough rule's `force` option

Calls superclass method
# File lib/matchd/server.rb, line 15
def initialize(rules, listen, options = {})
  @rules = rules
  @resolver = options.delete(:resolver)
  @forced_passthtough = options.delete(:forced_passthtough) { true }

  listen = Matchd::Glue::AsyncEndpoint.parse(listen)

  super(listen, *options)
end

Public Instance Methods

passthrough!(name, resource_class, transaction) click to toggle source
# File lib/matchd/server.rb, line 35
def passthrough!(name, resource_class, transaction)
  Matchd::Rule::Passthrough.new(
    "passthrough" => resolver,
    "match" => name,
    "resource_class" => resource_class,
    "force" => @forced_passthtough
  ).visit!(self, name, resource_class, transaction)
end
process(name, resource_class, transaction) click to toggle source
# File lib/matchd/server.rb, line 27
def process(name, resource_class, transaction)
  found = rules.any? do |rule|
    rule.call(self, name, resource_class, transaction)
  end

  passthrough!(name, resource_class, transaction) unless found
end