# Discovery

_(c) AMWA 2018, CC Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0)_

NMOS Discovery makes use of the DNS Service Discovery protocol as described in [RFC 6763](https://tools.ietf.org/html/rfc6763). DNS-SD specifies a mechanism for the use of Unicast or Multicast DNS for the purpose of identifying one or more endpoints on a network associated with a named service.

One DNS-SD service type is defined by this specification:

* **_nmos-system._tcp:** A logical host which advertises a System API.

Advertisements of the above type are accompanied by DNS TXT records as specified within the following specification pages.

## Unicast vs. Multicast DNS-SD

Dependent on the architecture of a network, it may make sense to use one or both of unicast or multicast DNS for advertisement and discovery. The preferred method of advertisement is via unicast DNS-SD. Nodes may optionally be configured to support just one of unicast or multicast service discovery, however it is recommended that both are used by default in order to make initial device configuration as configuration free as possible.

When performing a DNS-SD browse, clients should proceed as follows:

1. Identify whether the client has been configured with DNS server addresses and a default search domain either manually or automatically via DHCP.
2. If such configuration exists and the discovery mechanism is not explicitly set to mDNS, perform a unicast DNS browse for services of the required type via the search domain.
3. If no unicast responses are received and the discovery mechanism is not explicitly set to unicast DNS, perform a multicast DNS browse for services of the required type in the '.local' domain.
   * Note that if a unicast response is received, multicast browsing should not be performed even if the unicast-discovered API is unresponsive.
4. Where both unicast and multicast DNS are used, merge the results of the above operations into a single list.
5. Sort the list of discovered services using the priority values associated with each record, and discard any advertisements which do not meet the Node's requirements.
6. The above list should be maintained via the methods defined by the DNS-SD specification.

## Implementation Notes

It is expected that timeouts specified by DNS-SD and DNS specifications will be abided by when maintaining a cache, however clients may wish to temporarily mark particular advertisements as invalid where they have timed out or produced HTTP 5xx errors during API interactions. In the case of multicast DNS the re-query mechanism should be used, and is particularly important for servers which cannot unregister their mDNS announcements before going offline.

Due to the caching mechanisms present within mDNS implementations, if a service disappears from the network without cleanly removing its mDNS announcement, it will still be present in the caches of browsing systems until the defined expiry time (120 seconds to 75 minutes dependent on record type). When mDNS advertised data is found to be invalid (for example by performing an HTTP request to an advertised service API and seeing a timeout), the procedure defined in [RFC 6762](https://tools.ietf.org/html/rfc6762) section 10.2 should be followed. Additionally, [RFC 6762](https://tools.ietf.org/html/rfc6762) section 10.5 may be used to pre-empt these failures.
