-
Notifications
You must be signed in to change notification settings - Fork 292
[RFC] peer discovery with mDNS #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a4626ef
feat: initial description of peer discovery with MDNS
richardschneider 9e0e1f5
fix: grammar
richardschneider 154424f
fix: typos
richardschneider b2c450e
docs: multiaddress
richardschneider 105fd2b
fix: '_ipfs' => '_p2p'
richardschneider a9c587c
fix: use TXT dnsaddr for multi address
richardschneider 2e0219a
feat: open issues
richardschneider 8cc1297
fix: names are case insensitive
richardschneider 53d9faf
doc: long peer names
richardschneider 409c019
docs: link to discovery/mdns.md
richardschneider 59e0793
docs: worked example
richardschneider 2f3e55d
docs: few edits to the structure
daviddias 479f07c
editorial refinements.
raulk 4c5a459
feat: private networks
richardschneider File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| # Multicast DNS (mDNS) | ||
|
|
||
| Author: Richard Schneider ([email protected]) | ||
|
|
||
| ## Overview | ||
|
|
||
| The goal is to allow peers to discover each other when on the same local network with zero configuration. mDNS uses a multicast system of DNS records; this allows all peers on the local network to see all query responses. | ||
|
|
||
| Conceptually, it is very simple. When a peer starts (or detects a network change), it sends a query for all peers. As responses come in, the peer adds the other peers' information into its local database of peers. | ||
|
|
||
| ## Definitions | ||
|
|
||
| - `service-name` is the DNS Service Discovery (DNS-SD) service name for all peers. It is defined as `_p2p._udp.local`. | ||
| - `host-name` is the fully qualified name of the peer. It is derived from the peer's name and `p2p.local`. | ||
| - `peer-name` is the case-insensitive unique identifier of the peer, and is less than 64 characters. It is normally the base-32 encoding of the peer's ID. | ||
|
|
||
| If the encoding of the peer's ID exceeds 63 characters, then the [Split at 63rd character](https://github.com/ipfs/in-web-browsers/issues/89#issue-341357014) workaround can be used. | ||
|
|
||
| If a [private network](https://github.com/libp2p/specs/blob/master/pnet/Private-Networks-PSK-V1.md) is in use, then the `service-name` contains the base-16 encoding of the network's fingerprint as in `_p2p-X._udp.local`. | ||
| The prevents public and private networks from discovering each other's peers. | ||
|
|
||
| ## Peer Discovery | ||
|
|
||
| ### Request | ||
|
|
||
| To find all peers, a DNS message is sent with the question `_p2p._udp.local PTR`. Peers will then start responding with their details. | ||
|
|
||
| Note that a peer must respond to its own query. This allows other peers to passively discover it. | ||
|
|
||
| ### Response | ||
|
|
||
| On receipt of a `find all peers` query, a peer sends a DNS response message (QR = 1) that contains the **answer** | ||
|
|
||
| ``` | ||
| <service-name> PTR <peer-name>.<service-name> | ||
| ``` | ||
|
|
||
| The **additional records** of the response contain the peer's discovery details: | ||
|
|
||
| ``` | ||
| <peer-name>.<service-name> TXT "dnsaddr=..." | ||
| ``` | ||
|
|
||
| The TXT record contains the multiaddresses that the peer is listening on. Each multiaddress is a TXT attribute with the form `dnsaddr=/.../p2p/QmId`. Multiple `dnsaddr` attributes and/or TXT records are allowed. | ||
|
|
||
| ## DNS Service Discovery | ||
|
|
||
| DNS-SD support is not needed for peers to discover each other. However, it is extremely useful for network administrators to discover what is running on the network. | ||
|
|
||
| ### Meta Query | ||
|
|
||
| This allows discovery of all services. The question is `_services._dns-sd._udp.local PTR`. | ||
|
|
||
| A peer responds with the answer | ||
|
|
||
| ``` | ||
| _services._dns-sd._udp.local PTR <service-name> | ||
| ``` | ||
|
|
||
| ### Find All Response | ||
|
|
||
| On receipt of a `find all peers` query, the following **additional records** should be included | ||
|
|
||
| ``` | ||
| <peer-name>.<service-name> SRV ... <host-name> | ||
| <host-name> A <ipv4 address> | ||
| <host-name> AAAA <ipv6 address> | ||
| ``` | ||
|
|
||
| ### Gotchas | ||
|
|
||
| Many existing tools ignore the Additional Records, and always send individual queries for the peer's discovery details. To accomodate this, a peer should respond to the following queries: | ||
|
|
||
| - `<peer-name>.<service-name> SRV` | ||
| - `<peer-name>.<service-name> TXT` | ||
| - `<host-name> A` | ||
| - `<host-name> AAAA` | ||
|
|
||
| ## Issues | ||
|
|
||
| [ ] mDNS requires link-local addresses. Loopback and "NAT busting" addresses should not sent and must be ignored on receipt? | ||
|
|
||
| ## References | ||
|
|
||
| - [RFC 1035 - Domain Names (DNS)](https://tools.ietf.org/html/rfc1035) | ||
| - [RFC 6762 - Multicast DNS](https://tools.ietf.org/html/rfc6762) | ||
| - [RFC 6763 - DNS-Based Service Discovery](https://tools.ietf.org/html/rfc6763) | ||
| - [Multiaddr](https://github.com/multiformats/multiaddr) | ||
|
|
||
| ## Worked Examples | ||
|
|
||
| Asumming that `peer-id` is `QmQusTXc1Z9C1mzxsqC9ZTFXCgSkpBRGgW4Jk2QYHxKE22`, then the `peer-name` is `ciqcmoputolsfsigvm7nx5fwkko2eq26h46qhbj6o4co7uyn2f2srdy` (base32 encoding of the peer ID). | ||
|
|
||
| To make the examples more readable `id` and `name` are used. | ||
|
|
||
| ### Meta Query | ||
|
|
||
| Goal: find all services on the local network. | ||
|
|
||
| #### Question | ||
|
|
||
| ``` | ||
| _services._dns-sd._udp.local PTR | ||
| ``` | ||
|
|
||
| #### Answer | ||
|
|
||
| ``` | ||
| _services._dns-sd._udp.local IN PTR _p2p._udp.local | ||
| ``` | ||
|
|
||
| ### Find All Peers | ||
|
|
||
| Goal: find all peers on the local network. | ||
|
|
||
| #### Question | ||
|
|
||
| ``` | ||
| _p2p._udp.local PTR | ||
| ``` | ||
|
|
||
| #### Answer | ||
|
|
||
| ``` | ||
| _p2p._udp.local IN PTR `name`._p2p._udp.local | ||
| ``` | ||
|
|
||
| #### Additional Records | ||
|
|
||
| - `name`._p2p._udp.local IN TXT dnsaddr=/ip6/fe80::7573:b0a8:46b0:bfea/tcp/4001/ipfs/`id` | ||
| - `name`._p2p._udp.local IN TXT dnsaddr=/ip4/192.168.178.21/tcp/4001/ipfs/'id' | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.