Skip to content

API Proposal Service Discovery

dietrich ayala edited this page Sep 28, 2018 · 6 revisions

Webextensions Service Discovery API Proposal

Background

The Service Discovery API provides a DNS-based API for broadcasting and discovering services on the local network per rfc6763.

The current implementation in mozilla-central was originally landed for FlyWeb and is located at https://dxr.mozilla.org/mozilla-central/source/netwerk/dns/mdns.

Other current uses of MDNs/DNS-SD at Mozilla are in the IoT group in Emerging Technology, where communication between the Gateway and compatible devices happens through local network discovery.

This document is a proposal for offering a similar API for webextensions.

Compatibility and Standardization

The W3C Discovery API, which would provide similar functionality to web content, is no longer in development, and was replaced by new APIs that address specific display and media use-cases.

Chrome implemented a subset of the W3C Discovery API for Chrome Apps, which are being deprecated in favor of PWA features for the web, according to Alex Russel.

Chrome's continued public efforts to make this feature available in a variety of contexts is a strong signal for eventual standardization across implementations, whether WebExtension or web API.

Proposal

This section details a proposed webextensions API for Service Discovery.

This proposal is specifically about discovery and broadcast of services, and does not extend to making or receiving connections. That functionality is done separately through Request, and TCP/UDP Socket APIs.

The example implementation as a WebExtension Experiment API is in the libdweb repository.

Permissions

As with most existing webextension APIs, this API will have a new top-level permissions:

"dns-sd:discover:*"

Web extension may request permission to discover services for all supported protocols on the local network via "dns-sd:discover:*" permission, or request permission to discover serviced for a specific protocol that is "dns-sd:discover:tcp" or "dns-sd:discover:udp".

"dns-sd:announce:*"

Web extension may request permission to announce services for all supported protocols on the local network via "dns-sd:announce:*" permission, or request permission to announce service for a specific protocol that is "dns-sd:announce:tcp" or "dns-sd:announce:udp".

Functions outlined below will not appear in an extension’s browser namespace unless one or more permissions from the above list is included in the extension manifest.

In this way, a user who installs an extension that uses this API can be offered a prompt (either at install time or at use time, see https://github.com/mozilla/addons/issues/51 for that debate) with a message such as:

“This extension may advertise your IP address with and/or lookup IP addresses of other devices on the local network, do you want to proceed?”

API

Everything provided by this API will be in the browser.ServiceDiscovery namespace. Note that, unlike nearly all other existing webextensions interfaces, this is a brand-new interface, so there is no need to includes these methods in the chrome namespace for compatibility.

ServiceDiscovery.ServiceOptions interface

Name Description
name The name of the service, e.g. "Apple TV".
type The type of the service, e.g. "http".
protocol The protocol used by the service. Either "tcp" or "udp"
port The port on which the service listens, e.g. 5000.
attributes The TXT record advertised by the service (a {[string]:string} object)

ServiceDiscovery.announce method

Announces a service that others on the local network can discover. Lack of corresponding permission causes returned promise to fail with "permission denied" error.

Name Returns
ServiceDiscover.announce(ServiceDiscovery.ServiceOptions) Promise<ServiceDiscovery.Service>

ServiceDiscovery.Service Object

Represents an active service announcement. Object contains same fields as ServiceDiscovery.ServiceOptions passed in addition to following

Name type description
expire() void Expires service announcement. Service will stop being discoverable over time.
domain string Will always be "local"
addresses string[] Network addresses ipv4, ipv6 or both were service could reached
host string Hostname of the machine doing announcement

ServiceDiscovery.ServiceQuery inerface

Represents a query that can be used to discover services on the local network.

Name Description
type The type of the service, e.g. "http".
protocol The protocol used by the service. Either "tcp" or "udp"

ServiceDiscovery.discover method

Queries local network for available services. Lack of corresponding permission causes returned AsyncIterator to fail with "permission denied" error.

Name Returns
ServiceDiscover.discover(ServiceDiscovery.ServiceQuery) AsyncIterator<ServiceDiscovery.DiscoveredService>

ServiceDiscovery.DiscoveredService Object

Object contains all the same properties as above described ServiceDiscovery.Service except expire() method and in addition to following:

Name type description
lost boolean Is true if service announcement expried