webrtc_mdns (webrtc v0.1.0)

View Source

Name resolution for ICE candidates whose address is a host name, and an optional mDNS responder for our own host candidates (draft-ietf-mmusic-mdns-ice-candidates).

One process per transport, started on demand. It never blocks its caller: resolve/2 returns a reference and the result arrives as {webrtc_mdns, Ref, {ok, [IP, ...]} | {error, Reason}}.

  • .local names use one-shot multicast DNS queries (webrtc_mdns_resolver, RFC 6762 §5.1) sent from an ephemeral port to the group (224.0.0.251:5353). Legacy unicast replies come back on that port; multicast replies are received on a socket bound to the group port with SO_REUSEPORT (shared with the system responder) and joined to the group.
  • Other names are looked up with inet:getaddrs(Name, Family, Timeout) in a helper process, AAAA then A (RFC 8839 §5.1).
  • Responses must come from an address on a local subnet (RFC 6762 §11).
  • register_name/2 gives an address a random <uuid>.local name (draft §3.1.1), announces it and answers queries for it on the group socket (webrtc_mdns_responder).

Queries go out over IPv4 (224.0.0.251) and IPv6 (ff02::fb) multicast, the IPv6 ones once per interface (RFC 6762 §5, §20): a host that only answers over IPv6 is found too, and our names are announced and answered on both. A question for the family a name does not have is answered with NSEC (§6.1).

Options: group ({IP, Port} the queries go to), listen ({IP, Port} of the multicast socket, false for none), group6 and listen6 the same for IPv6 (group6 defaults to {ff02::fb, 5353}, or false, no IPv6, when group is given), schedule, max_queries, max_cache (see webrtc_mdns_resolver), fqdn_timeout (ms, default 3000) and check_source (default true). Tests point group and listen at loopback ports.

Summary

Functions

Name an address with a random <uuid>.local name and answer queries for it. The same address keeps its name.

Resolve a host name. The result is sent to the caller as {webrtc_mdns, Ref, Result}.

Start a resolver for the calling process. It stops when the caller exits.

Stop without waiting (goodbye packets are still sent).

Functions

handle_call(_, From, St)

handle_cast(_, St)

handle_info(_, St)

init(Opts)

register_name(Pid, IP)

-spec register_name(pid(), inet:ip_address()) -> {ok, binary()} | {error, term()}.

Name an address with a random <uuid>.local name and answer queries for it. The same address keeps its name.

resolve(Pid, Name)

-spec resolve(pid(), binary()) -> reference().

Resolve a host name. The result is sent to the caller as {webrtc_mdns, Ref, Result}.

start(Opts)

-spec start(map()) -> {ok, pid()} | {error, term()}.

Start a resolver for the calling process. It stops when the caller exits.

stop(Pid)

-spec stop(pid()) -> ok.

stop_async(Pid)

-spec stop_async(pid()) -> ok.

Stop without waiting (goodbye packets are still sent).

terminate(Reason, St)