Skip to content

Commit

Permalink
Support SRV records
Browse files Browse the repository at this point in the history
Priority is not taken into consideration at this time and ports are ignored as there is no mechanism to specify the port used when connecting to a node with net_kernel:connect_node/1
  • Loading branch information
feld committed Nov 2, 2023
1 parent 4b52fd3 commit bcfc9d8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/dns_cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ defmodule DNSCluster do

def list_nodes, do: Node.list(:visible)

def lookup(query, type = :srv) when is_binary(query) do
:inet_res.lookup(~c"#{query}", :in, type)
|> Enum.map(&elem(&1, 3))
end

def lookup(query, type) when is_binary(query) and type in [:a, :aaaa] do
:inet_res.lookup(~c"#{query}", :in, type)
end
Expand Down Expand Up @@ -145,10 +150,13 @@ defmodule DNSCluster do
end

defp discover_ips(%{resolver: resolver, query: query}) do
[:a, :aaaa]
[:a, :aaaa, :srv]
|> Enum.flat_map(&resolver.lookup(query, &1))
|> Enum.uniq()
|> Enum.map(&to_string(:inet.ntoa(&1)))
|> Enum.map(fn
[_] = result -> to_string(result)
result -> to_string(:inet.ntoa(result))
end)
end

defp warn_on_invalid_dist do
Expand Down

0 comments on commit bcfc9d8

Please sign in to comment.