# `Chronicle.Connections.DnsResolver`
[🔗](https://github.com/Cratis/Chronicle.Elixir/blob/main/lib/chronicle/connections/dns_resolver.ex#L4)

Resolves `chronicle+srv://` connection strings via DNS SRV lookups.

A Chronicle Kernel deployment that publishes a DNS SRV record can be
addressed with a single `chronicle+srv://<host>` connection string instead of
an explicit multi-host list. `Chronicle.Connections.Connection` re-resolves
the record on every connect/reconnect attempt — through the injectable
`:resolve_fun` option, mirroring the `:connect_fun`/`:disconnect_fun` seam
already used to fake the gRPC channel in tests — so membership changes are
picked up automatically without a separate background refresh loop.

The query name is `_chronicle._tcp.<host>`, following the standard SRV
naming convention (`_service._proto.name`). Resolution goes through the
system resolver via `:inet_res` by default; passing a `srvNameServer`
connection string option (a `"host"` or `"host:port"` string) queries that
name server directly instead.

Resolved addresses are sorted ascending by priority, then descending by
weight, matching standard SRV record selection order (lower priority first;
among equal priorities, higher weight first).

# `srv_record`

```elixir
@type srv_record() ::
  {non_neg_integer(), non_neg_integer(), non_neg_integer(),
   charlist() | String.t()}
```

# `resolve`

```elixir
@spec resolve(String.t(), String.t() | nil) ::
  {:ok, [Chronicle.Connections.ConnectionString.ServerAddress.t()]}
  | {:error, term()}
```

Resolves the SRV record for `host`, optionally via a specific `name_server`.

`name_server` is a `"host"` or `"host:port"` string; `nil` (the default) uses
the system resolver. Returns `{:ok, addresses}` sorted per the module doc, or
`{:error, reason}` when the lookup fails or returns no records.

# `to_addresses`

```elixir
@spec to_addresses([srv_record()]) :: [
  Chronicle.Connections.ConnectionString.ServerAddress.t()
]
```

Converts raw SRV answer tuples (`{priority, weight, port, target}`) into
sorted `ServerAddress` structs.

Exposed separately from `resolve/2` so the selection/ordering logic can be
unit tested without touching real DNS.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
