@libp2p/mdns 9.0.10 → 9.0.11-69581367

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,3 @@
1
- # @libp2p/mdns <!-- omit in toc -->
2
-
3
1
  [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4
2
  [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
5
3
  [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
@@ -7,24 +5,13 @@
7
5
 
8
6
  > Node.js libp2p mDNS discovery implementation for peer discovery
9
7
 
10
- ## Table of contents <!-- omit in toc -->
8
+ # About
11
9
 
12
- - [Install](#install)
13
- - [Usage](#usage)
14
- - [MDNS messages](#mdns-messages)
15
- - [API Docs](#api-docs)
16
- - [License](#license)
17
- - [Contribution](#contribution)
10
+ A peer discover mechanism that uses [mDNS](https://datatracker.ietf.org/doc/html/rfc6762) to discover peers on the local network.
18
11
 
19
- ## Install
12
+ ## Example
20
13
 
21
- ```console
22
- $ npm i @libp2p/mdns
23
- ```
24
-
25
- ## Usage
26
-
27
- ```Typescript
14
+ ```ts
28
15
  import { mdns } from '@libp2p/mdns'
29
16
 
30
17
  const options = {
@@ -33,81 +20,84 @@ const options = {
33
20
  ]
34
21
  }
35
22
 
36
- async function start () {
37
- const libp2p = await createLibp2p(options)
38
-
39
- libp2p.on('peer:discovery', function (peerId) {
40
- console.log('found peer: ', peerId.toB58String())
41
- })
23
+ const libp2p = await createLibp2p(options)
42
24
 
43
- await libp2p.start()
44
- }
25
+ libp2p.on('peer:discovery', function (peerId) {
26
+ console.log('found peer: ', peerId.toB58String())
27
+ })
45
28
 
29
+ await libp2p.start()
46
30
  ```
47
31
 
48
- - options
49
- - `peerName` - Peer name to announce (should not be peeer id), default random string
50
- - `multiaddrs` - multiaddrs to announce
51
- - `broadcast` - (true/false) announce our presence through mDNS, default `true`
52
- - `interval` - query interval, default 10 \* 1000 (10 seconds)
53
- - `serviceTag` - name of the service announce , default '_p2p._udp.local\`
54
-
55
32
  ## MDNS messages
56
33
 
57
34
  A query is sent to discover the libp2p nodes on the local network
58
35
 
59
36
  ```js
60
37
  {
61
- type: 'query',
62
- questions: [ { name: '_p2p._udp.local', type: 'PTR' } ]
38
+ type: 'query',
39
+ questions: [ { name: '_p2p._udp.local', type: 'PTR' } ]
63
40
  }
64
41
  ```
65
42
 
66
43
  When a query is detected, each libp2p node sends an answer about itself
67
44
 
68
45
  ```js
69
- [ { name: '_p2p._udp.local',
70
- type: 'PTR',
71
- class: 'IN',
72
- ttl: 120,
73
- data: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local' },
74
- { name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local',
75
- type: 'SRV',
76
- class: 'IN',
77
- ttl: 120,
78
- data:
79
- { priority: 10,
80
- weight: 1,
81
- port: '20002',
82
- target: 'LAPTOP-G5LJ7VN9' } },
83
- { name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local',
84
- type: 'TXT',
85
- class: 'IN',
86
- ttl: 120,
87
- data: ['QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK'] },
88
- { name: 'LAPTOP-G5LJ7VN9',
89
- type: 'A',
90
- class: 'IN',
91
- ttl: 120,
92
- data: '127.0.0.1' },
93
- { name: 'LAPTOP-G5LJ7VN9',
94
- type: 'AAAA',
95
- class: 'IN',
96
- ttl: 120,
97
- data: '::1' } ]
46
+ [{
47
+ name: '_p2p._udp.local',
48
+ type: 'PTR',
49
+ class: 'IN',
50
+ ttl: 120,
51
+ data: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local'
52
+ }, {
53
+ name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local',
54
+ type: 'SRV',
55
+ class: 'IN',
56
+ ttl: 120,
57
+ data: {
58
+ priority: 10,
59
+ weight: 1,
60
+ port: '20002',
61
+ target: 'LAPTOP-G5LJ7VN9'
62
+ }
63
+ }, {
64
+ name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local',
65
+ type: 'TXT',
66
+ class: 'IN',
67
+ ttl: 120,
68
+ data: ['QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK']
69
+ }, {
70
+ name: 'LAPTOP-G5LJ7VN9',
71
+ type: 'A',
72
+ class: 'IN',
73
+ ttl: 120,
74
+ data: '127.0.0.1'
75
+ }, {
76
+ name: 'LAPTOP-G5LJ7VN9',
77
+ type: 'AAAA',
78
+ class: 'IN',
79
+ ttl: 120,
80
+ data: '::1'
81
+ }]
82
+ ```
83
+
84
+ # Install
85
+
86
+ ```console
87
+ $ npm i @libp2p/mdns
98
88
  ```
99
89
 
100
- ## API Docs
90
+ # API Docs
101
91
 
102
92
  - <https://libp2p.github.io/js-libp2p/modules/_libp2p_mdns.html>
103
93
 
104
- ## License
94
+ # License
105
95
 
106
96
  Licensed under either of
107
97
 
108
98
  - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
109
99
  - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
110
100
 
111
- ## Contribution
101
+ # Contribution
112
102
 
113
103
  Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
@@ -1,11 +1,106 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * A peer discover mechanism that uses [mDNS](https://datatracker.ietf.org/doc/html/rfc6762) to discover peers on the local network.
5
+ *
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import { mdns } from '@libp2p/mdns'
10
+ *
11
+ * const options = {
12
+ * peerDiscovery: [
13
+ * mdns()
14
+ * ]
15
+ * }
16
+ *
17
+ * const libp2p = await createLibp2p(options)
18
+ *
19
+ * libp2p.on('peer:discovery', function (peerId) {
20
+ * console.log('found peer: ', peerId.toB58String())
21
+ * })
22
+ *
23
+ * await libp2p.start()
24
+ * ```
25
+ *
26
+ * ## MDNS messages
27
+ *
28
+ * A query is sent to discover the libp2p nodes on the local network
29
+ *
30
+ * ```js
31
+ * {
32
+ * type: 'query',
33
+ * questions: [ { name: '_p2p._udp.local', type: 'PTR' } ]
34
+ * }
35
+ * ```
36
+ *
37
+ * When a query is detected, each libp2p node sends an answer about itself
38
+ *
39
+ * ```js
40
+ * [{
41
+ * name: '_p2p._udp.local',
42
+ * type: 'PTR',
43
+ * class: 'IN',
44
+ * ttl: 120,
45
+ * data: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local'
46
+ * }, {
47
+ * name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local',
48
+ * type: 'SRV',
49
+ * class: 'IN',
50
+ * ttl: 120,
51
+ * data: {
52
+ * priority: 10,
53
+ * weight: 1,
54
+ * port: '20002',
55
+ * target: 'LAPTOP-G5LJ7VN9'
56
+ * }
57
+ * }, {
58
+ * name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local',
59
+ * type: 'TXT',
60
+ * class: 'IN',
61
+ * ttl: 120,
62
+ * data: ['QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK']
63
+ * }, {
64
+ * name: 'LAPTOP-G5LJ7VN9',
65
+ * type: 'A',
66
+ * class: 'IN',
67
+ * ttl: 120,
68
+ * data: '127.0.0.1'
69
+ * }, {
70
+ * name: 'LAPTOP-G5LJ7VN9',
71
+ * type: 'AAAA',
72
+ * class: 'IN',
73
+ * ttl: 120,
74
+ * data: '::1'
75
+ * }]
76
+ * ```
77
+ */
1
78
  import type { PeerDiscovery } from '@libp2p/interface/peer-discovery';
2
79
  import type { AddressManager } from '@libp2p/interface-internal/address-manager';
3
80
  export interface MulticastDNSInit {
81
+ /**
82
+ * (true/false) announce our presence through mDNS, default `true`
83
+ */
4
84
  broadcast?: boolean;
85
+ /**
86
+ * query interval, default 10 \* 1000 (10 seconds)
87
+ */
5
88
  interval?: number;
89
+ /**
90
+ * name of the service announce , default '_p2p._udp.local\`
91
+ */
6
92
  serviceTag?: string;
93
+ /**
94
+ * Peer name to announce (should not be peeer id), default random string
95
+ */
7
96
  peerName?: string;
97
+ /**
98
+ * UDP port to broadcast to
99
+ */
8
100
  port?: number;
101
+ /**
102
+ * UDP IP to broadcast to
103
+ */
9
104
  ip?: string;
10
105
  }
11
106
  export interface MulticastDNSComponents {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAuB,MAAM,kCAAkC,CAAA;AAG1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAA;AAIhF,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,cAAc,CAAA;CAC/B;AAuID,wBAAgB,IAAI,CAAE,IAAI,GAAE,gBAAqB,GAAG,CAAC,UAAU,EAAE,sBAAsB,KAAK,aAAa,CAExG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AAQH,OAAO,KAAK,EAAE,aAAa,EAAuB,MAAM,kCAAkC,CAAA;AAG1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAA;AAIhF,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,cAAc,CAAA;CAC/B;AAuID,wBAAgB,IAAI,CAAE,IAAI,GAAE,gBAAqB,GAAG,CAAC,UAAU,EAAE,sBAAsB,KAAK,aAAa,CAExG"}
package/dist/src/index.js CHANGED
@@ -1,11 +1,88 @@
1
- import { CustomEvent, EventEmitter } from '@libp2p/interface/events';
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * A peer discover mechanism that uses [mDNS](https://datatracker.ietf.org/doc/html/rfc6762) to discover peers on the local network.
5
+ *
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import { mdns } from '@libp2p/mdns'
10
+ *
11
+ * const options = {
12
+ * peerDiscovery: [
13
+ * mdns()
14
+ * ]
15
+ * }
16
+ *
17
+ * const libp2p = await createLibp2p(options)
18
+ *
19
+ * libp2p.on('peer:discovery', function (peerId) {
20
+ * console.log('found peer: ', peerId.toB58String())
21
+ * })
22
+ *
23
+ * await libp2p.start()
24
+ * ```
25
+ *
26
+ * ## MDNS messages
27
+ *
28
+ * A query is sent to discover the libp2p nodes on the local network
29
+ *
30
+ * ```js
31
+ * {
32
+ * type: 'query',
33
+ * questions: [ { name: '_p2p._udp.local', type: 'PTR' } ]
34
+ * }
35
+ * ```
36
+ *
37
+ * When a query is detected, each libp2p node sends an answer about itself
38
+ *
39
+ * ```js
40
+ * [{
41
+ * name: '_p2p._udp.local',
42
+ * type: 'PTR',
43
+ * class: 'IN',
44
+ * ttl: 120,
45
+ * data: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local'
46
+ * }, {
47
+ * name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local',
48
+ * type: 'SRV',
49
+ * class: 'IN',
50
+ * ttl: 120,
51
+ * data: {
52
+ * priority: 10,
53
+ * weight: 1,
54
+ * port: '20002',
55
+ * target: 'LAPTOP-G5LJ7VN9'
56
+ * }
57
+ * }, {
58
+ * name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local',
59
+ * type: 'TXT',
60
+ * class: 'IN',
61
+ * ttl: 120,
62
+ * data: ['QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK']
63
+ * }, {
64
+ * name: 'LAPTOP-G5LJ7VN9',
65
+ * type: 'A',
66
+ * class: 'IN',
67
+ * ttl: 120,
68
+ * data: '127.0.0.1'
69
+ * }, {
70
+ * name: 'LAPTOP-G5LJ7VN9',
71
+ * type: 'AAAA',
72
+ * class: 'IN',
73
+ * ttl: 120,
74
+ * data: '::1'
75
+ * }]
76
+ * ```
77
+ */
78
+ import { CustomEvent, TypedEventEmitter } from '@libp2p/interface/events';
2
79
  import { peerDiscovery } from '@libp2p/interface/peer-discovery';
3
80
  import { logger } from '@libp2p/logger';
4
81
  import multicastDNS from 'multicast-dns';
5
82
  import * as query from './query.js';
6
83
  import { stringGen } from './utils.js';
7
84
  const log = logger('libp2p:mdns');
8
- class MulticastDNS extends EventEmitter {
85
+ class MulticastDNS extends TypedEventEmitter {
9
86
  mdns;
10
87
  broadcast;
11
88
  interval;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAMtC,MAAM,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AAejC,MAAM,YAAa,SAAQ,YAAiC;IACnD,IAAI,CAA4B;IAEtB,SAAS,CAAS;IAClB,QAAQ,CAAQ;IAChB,UAAU,CAAQ;IAClB,QAAQ,CAAQ;IAChB,IAAI,CAAQ;IACZ,EAAE,CAAQ;IACnB,cAAc,CAAuC;IAC5C,UAAU,CAAwB;IAEnD,YAAa,UAAkC,EAAE,OAAyB,EAAE;QAC1E,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,KAAK,KAAK,CAAA;QACzC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,CAAA;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,iBAAiB,CAAA;QACtD,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,aAAa,CAAA;QAClC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,SAAS,CAAC,EAAE,CAAC,CAAA;QAC9C,wBAAwB;QACxB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,IAA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KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE;YACrB,OAAM;SACP;QAED,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;QACpD,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,eAAe,CAAC,CAAA;QAC1D,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;QACxD,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;QAEpD,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,EAAE;YAC/B,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;YAClC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA;SAC3B;QAED,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YAClC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE;gBACrB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;aAC3B;iBAAM;gBACL,OAAO,EAAE,CAAA;aACV;QACH,CAAC,CAAC,CAAA;QAEF,IAAI,CAAC,IAAI,GAAG,SAAS,CAAA;IACvB,CAAC;CACF;AAED,MAAM,UAAU,IAAI,CAAE,OAAyB,EAAE;IAC/C,OAAO,CAAC,UAAkC,EAAE,EAAE,CAAC,IAAI,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACnF,CAAC;AAED;;;;;;;;;;;;;;;EAeE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/mdns",
3
- "version": "9.0.10",
3
+ "version": "9.0.11-69581367",
4
4
  "description": "Node.js libp2p mDNS discovery implementation for peer discovery",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/peer-discovery-mdns#readme",
@@ -45,19 +45,19 @@
45
45
  "test:electron-main": "aegir test -t electron-main"
46
46
  },
47
47
  "dependencies": {
48
- "@libp2p/interface": "^0.1.3",
49
- "@libp2p/logger": "^3.0.3",
50
- "@libp2p/peer-id": "^3.0.3",
51
- "@libp2p/utils": "^4.0.4",
48
+ "@libp2p/interface": "0.1.4-69581367",
49
+ "@libp2p/logger": "3.0.4-69581367",
50
+ "@libp2p/peer-id": "3.0.4-69581367",
51
+ "@libp2p/utils": "4.0.5-69581367",
52
52
  "@multiformats/multiaddr": "^12.1.5",
53
53
  "@types/multicast-dns": "^7.2.1",
54
54
  "dns-packet": "^5.4.0",
55
55
  "multicast-dns": "^7.2.5"
56
56
  },
57
57
  "devDependencies": {
58
- "@libp2p/interface-compliance-tests": "^4.1.1",
59
- "@libp2p/interface-internal": "^0.1.6",
60
- "@libp2p/peer-id-factory": "^3.0.5",
58
+ "@libp2p/interface-compliance-tests": "4.1.2-69581367",
59
+ "@libp2p/interface-internal": "0.1.7-69581367",
60
+ "@libp2p/peer-id-factory": "3.0.6-69581367",
61
61
  "aegir": "^41.0.2",
62
62
  "p-wait-for": "^5.0.2",
63
63
  "ts-sinon": "^2.0.2"
package/src/index.ts CHANGED
@@ -1,4 +1,82 @@
1
- import { CustomEvent, EventEmitter } from '@libp2p/interface/events'
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * A peer discover mechanism that uses [mDNS](https://datatracker.ietf.org/doc/html/rfc6762) to discover peers on the local network.
5
+ *
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import { mdns } from '@libp2p/mdns'
10
+ *
11
+ * const options = {
12
+ * peerDiscovery: [
13
+ * mdns()
14
+ * ]
15
+ * }
16
+ *
17
+ * const libp2p = await createLibp2p(options)
18
+ *
19
+ * libp2p.on('peer:discovery', function (peerId) {
20
+ * console.log('found peer: ', peerId.toB58String())
21
+ * })
22
+ *
23
+ * await libp2p.start()
24
+ * ```
25
+ *
26
+ * ## MDNS messages
27
+ *
28
+ * A query is sent to discover the libp2p nodes on the local network
29
+ *
30
+ * ```js
31
+ * {
32
+ * type: 'query',
33
+ * questions: [ { name: '_p2p._udp.local', type: 'PTR' } ]
34
+ * }
35
+ * ```
36
+ *
37
+ * When a query is detected, each libp2p node sends an answer about itself
38
+ *
39
+ * ```js
40
+ * [{
41
+ * name: '_p2p._udp.local',
42
+ * type: 'PTR',
43
+ * class: 'IN',
44
+ * ttl: 120,
45
+ * data: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local'
46
+ * }, {
47
+ * name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local',
48
+ * type: 'SRV',
49
+ * class: 'IN',
50
+ * ttl: 120,
51
+ * data: {
52
+ * priority: 10,
53
+ * weight: 1,
54
+ * port: '20002',
55
+ * target: 'LAPTOP-G5LJ7VN9'
56
+ * }
57
+ * }, {
58
+ * name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local',
59
+ * type: 'TXT',
60
+ * class: 'IN',
61
+ * ttl: 120,
62
+ * data: ['QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK']
63
+ * }, {
64
+ * name: 'LAPTOP-G5LJ7VN9',
65
+ * type: 'A',
66
+ * class: 'IN',
67
+ * ttl: 120,
68
+ * data: '127.0.0.1'
69
+ * }, {
70
+ * name: 'LAPTOP-G5LJ7VN9',
71
+ * type: 'AAAA',
72
+ * class: 'IN',
73
+ * ttl: 120,
74
+ * data: '::1'
75
+ * }]
76
+ * ```
77
+ */
78
+
79
+ import { CustomEvent, TypedEventEmitter } from '@libp2p/interface/events'
2
80
  import { peerDiscovery } from '@libp2p/interface/peer-discovery'
3
81
  import { logger } from '@libp2p/logger'
4
82
  import multicastDNS from 'multicast-dns'
@@ -12,11 +90,33 @@ import type { AddressManager } from '@libp2p/interface-internal/address-manager'
12
90
  const log = logger('libp2p:mdns')
13
91
 
14
92
  export interface MulticastDNSInit {
93
+ /**
94
+ * (true/false) announce our presence through mDNS, default `true`
95
+ */
15
96
  broadcast?: boolean
97
+
98
+ /**
99
+ * query interval, default 10 \* 1000 (10 seconds)
100
+ */
16
101
  interval?: number
102
+
103
+ /**
104
+ * name of the service announce , default '_p2p._udp.local\`
105
+ */
17
106
  serviceTag?: string
107
+ /**
108
+ * Peer name to announce (should not be peeer id), default random string
109
+ */
18
110
  peerName?: string
111
+
112
+ /**
113
+ * UDP port to broadcast to
114
+ */
19
115
  port?: number
116
+
117
+ /**
118
+ * UDP IP to broadcast to
119
+ */
20
120
  ip?: string
21
121
  }
22
122
 
@@ -24,7 +124,7 @@ export interface MulticastDNSComponents {
24
124
  addressManager: AddressManager
25
125
  }
26
126
 
27
- class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Startable {
127
+ class MulticastDNS extends TypedEventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Startable {
28
128
  public mdns?: multicastDNS.MulticastDNS
29
129
 
30
130
  private readonly broadcast: boolean
@@ -1,8 +0,0 @@
1
- {
2
- "MulticastDNSComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_mdns.MulticastDNSComponents.html",
3
- ".:MulticastDNSComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_mdns.MulticastDNSComponents.html",
4
- "MulticastDNSInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_mdns.MulticastDNSInit.html",
5
- ".:MulticastDNSInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_mdns.MulticastDNSInit.html",
6
- "mdns": "https://libp2p.github.io/js-libp2p/functions/_libp2p_mdns.mdns.html",
7
- ".:mdns": "https://libp2p.github.io/js-libp2p/functions/_libp2p_mdns.mdns.html"
8
- }