View Source MCPing.Srv (mcping v0.4.0)
Functions for resolving SRV records. SRV records are used to provide a way to map a service name and protocol to a hostname and port. This module is used as a part of MCPing for optionally resolving the SRV record for a Minecraft server, but it is general enough to be used for any service that uses SRV records, such as XMPP or SIP.
Summary
Functions
Resolves all SRV records for a given service, protocol, and hostname. Returns a list of all SRV records found, sorted by priority order. If a record with a given priority has multiple records with different weights, the records will be randomly selected based on their weight.
Resolves a single SRV record for a given service, protocol, and hostname. Returns the first SRV record with the highest priority. If no SRV records are found, returns an error.
Functions
@spec lookup_server(String.t(), String.t(), String.t(), non_neg_integer()) :: {:ok, [{String.t(), non_neg_integer()}]} | {:error, term()}
Resolves all SRV records for a given service, protocol, and hostname. Returns a list of all SRV records found, sorted by priority order. If a record with a given priority has multiple records with different weights, the records will be randomly selected based on their weight.
If no SRV records are found, returns :error
.
Examples
iex> MCPing.Srv.lookup_server("minecraft", "tcp", "hypixel.net", 5000)
{:ok, [{~c"mc.hypixel.net", 25565}]}
@spec resolve_srv_record(String.t(), String.t(), String.t(), non_neg_integer()) :: {:ok, {String.t(), non_neg_integer()}} | {:error, term()}
Resolves a single SRV record for a given service, protocol, and hostname. Returns the first SRV record with the highest priority. If no SRV records are found, returns an error.
Examples
iex> MCPing.Srv.resolve_srv_record("minecraft", "tcp", "hypixel.net", 5000)
{:ok, {~c"mc.hypixel.net", 25565}}
iex> MCPing.Srv.resolve_srv_record("minecraft", "tcp", "mc.example.com", 5000)
{:error, :nxdomain}