MailAuth.Resolver behaviour (MailAuth v0.1.0)

Copy Markdown View Source

The behaviour for DNS resolvers.

Every check in this library reads DNS through a resolver, chosen with the :resolver option. Three come with the library:

Answers

A resolver returns {:ok, records, ttl} with:

  • :txt: one binary per record, with the strings of one record joined
  • :a: IPv4 address tuples, such as {192, 0, 2, 1}
  • :aaaa: IPv6 address tuples
  • :mx: {preference, exchange} pairs, the exchange a string
  • :ptr: names, as strings

or {:error, reason, ttl}, where reason is:

  • :nxdomain: the name does not exist
  • :no_data: the name exists, with no records of this type
  • :temperror: anything else, such as a timeout or a server failure

The TTL is in seconds. For errors, it says how long the answer may be cached; use 0 for :temperror.

Names are given in lowercase A-labels, without a trailing dot. The options are the options of the call, so a resolver can read its own from them, and :timeout holds the milliseconds left for this query.

Summary

Types

record_type()

@type record_type() :: :txt | :a | :aaaa | :mx | :ptr

Callbacks

lookup(name, type, opts)

@callback lookup(name :: String.t(), type :: record_type(), opts :: keyword()) ::
  {:ok, [term()], ttl :: non_neg_integer()}
  | {:error, :nxdomain | :no_data | :temperror, ttl :: non_neg_integer()}