@libp2p/mdns 3.0.1 → 5.0.0

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.
@@ -1,19 +1,18 @@
1
1
  import { EventEmitter } from '@libp2p/interfaces/events';
2
2
  import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery';
3
- import type { Components, Initializable } from '@libp2p/components';
4
3
  import { symbol } from '@libp2p/interface-peer-discovery';
4
+ import type { MulticastDNSComponents } from '../index.js';
5
5
  export interface GoMulticastDNSInit {
6
6
  queryPeriod?: number;
7
7
  queryInterval?: number;
8
8
  }
9
- export declare class GoMulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Initializable {
9
+ export declare class GoMulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery {
10
10
  private _started;
11
11
  private readonly _responder;
12
12
  private readonly _querier;
13
- constructor(options?: GoMulticastDNSInit);
13
+ constructor(components: MulticastDNSComponents, options?: GoMulticastDNSInit);
14
14
  get [symbol](): true;
15
15
  get [Symbol.toStringTag](): string;
16
- init(components: Components): void;
17
16
  isStarted(): boolean;
18
17
  start(): Promise<void>;
19
18
  stop(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/compat/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAe,MAAM,2BAA2B,CAAA;AAGrE,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AAEzD,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,qBAAa,cAAe,SAAQ,YAAY,CAAC,mBAAmB,CAAE,YAAW,aAAa,EAAE,aAAa;IAC3G,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAErB,OAAO,GAAE,kBAAuB;IAiB7C,IAAI,CAAC,MAAM,CAAC,IAAK,IAAI,CAEpB;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;IAED,IAAI,CAAE,UAAU,EAAE,UAAU,GAAG,IAAI;IAKnC,SAAS;IAIH,KAAK;IAaL,IAAI;CAYX"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/compat/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAe,MAAM,2BAA2B,CAAA;AAGrE,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAC1F,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AACzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,qBAAa,cAAe,SAAQ,YAAY,CAAC,mBAAmB,CAAE,YAAW,aAAa;IAC5F,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAErB,UAAU,EAAE,sBAAsB,EAAE,OAAO,GAAE,kBAAuB;IAiBjF,IAAI,CAAC,MAAM,CAAC,IAAK,IAAI,CAEpB;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;IAED,SAAS;IAIH,KAAK;IAaL,IAAI;CAYX"}
@@ -4,12 +4,12 @@ import { Responder } from './responder.js';
4
4
  import { Querier } from './querier.js';
5
5
  import { symbol } from '@libp2p/interface-peer-discovery';
6
6
  export class GoMulticastDNS extends EventEmitter {
7
- constructor(options = {}) {
7
+ constructor(components, options = {}) {
8
8
  super();
9
9
  const { queryPeriod, queryInterval } = options;
10
10
  this._started = false;
11
- this._responder = new Responder();
12
- this._querier = new Querier({
11
+ this._responder = new Responder(components);
12
+ this._querier = new Querier(components, {
13
13
  queryInterval,
14
14
  queryPeriod
15
15
  });
@@ -23,10 +23,6 @@ export class GoMulticastDNS extends EventEmitter {
23
23
  get [Symbol.toStringTag]() {
24
24
  return '@libp2p/go-mdns';
25
25
  }
26
- init(components) {
27
- this._responder.init(components);
28
- this._querier.init(components);
29
- }
30
26
  isStarted() {
31
27
  return this._started;
32
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/compat/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AAOzD,MAAM,OAAO,cAAe,SAAQ,YAAiC;IAKnE,YAAa,UAA8B,EAAE;QAC3C,KAAK,EAAE,CAAA;QACP,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,OAAO,CAAA;QAE9C,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;QAErB,IAAI,CAAC,UAAU,GAAG,IAAI,SAAS,EAAE,CAAA;QACjC,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAC;YAC1B,aAAa;YACb,WAAW;SACZ,CAAC,CAAA;QAEF,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;YAC7C,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,MAA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,CAAC,SAAS,EAAE,EAAE;YACrB,OAAM;SACP;QAED,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;QAErB,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;YACtB,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;SACrB,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -3,23 +3,26 @@ import { EventEmitter } from '@libp2p/interfaces/events';
3
3
  import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery';
4
4
  import type { ResponsePacket } from 'multicast-dns';
5
5
  import type { RemoteInfo } from 'dgram';
6
- import { Components, Initializable } from '@libp2p/components';
7
6
  import { symbol } from '@libp2p/interface-peer-discovery';
7
+ import type { Startable } from '@libp2p/interfaces/dist/src/startable.js';
8
+ import type { PeerId } from '@libp2p/interface-peer-id';
8
9
  export interface QuerierInit {
9
10
  queryInterval?: number;
10
11
  queryPeriod?: number;
11
12
  }
13
+ export interface QuerierComponents {
14
+ peerId: PeerId;
15
+ }
12
16
  export interface Handle {
13
17
  stop: () => Promise<void>;
14
18
  }
15
- export declare class Querier extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Initializable {
19
+ export declare class Querier extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Startable {
16
20
  private readonly _init;
17
21
  private _handle?;
18
- private components;
19
- constructor(init?: QuerierInit);
22
+ private readonly components;
23
+ constructor(components: QuerierComponents, init?: QuerierInit);
20
24
  get [symbol](): true;
21
25
  get [Symbol.toStringTag](): string;
22
- init(components: Components): void;
23
26
  isStarted(): boolean;
24
27
  start(): void;
25
28
  _onResponse(event: ResponsePacket, info: RemoteInfo): void;
@@ -1 +1 @@
1
- {"version":3,"file":"querier.d.ts","sourceRoot":"","sources":["../../../src/compat/querier.ts"],"names":[],"mappings":";AAAA,OAAO,EAAe,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAIrE,OAAO,KAAK,EAAE,a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CAAA;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAIvD,MAAM,WAAW,WAAW;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1B;AAED,qBAAa,OAAQ,SAAQ,YAAY,CAAC,mBAAmB,CAAE,YAAW,aAAa,EAAE,SAAS;IAChG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuB;IAC7C,OAAO,CAAC,OAAO,CAAC,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;gBAEjC,UAAU,EAAE,iBAAiB,EAAE,IAAI,GAAE,WAAgB;IAmBlE,IAAI,CAAC,MAAM,CAAC,IAAK,IAAI,CAEpB;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;IAED,SAAS;IAIT,KAAK;IAgCL,WAAW,CAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU;IAuB9C,IAAI;CAKX"}
@@ -2,15 +2,14 @@ import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events';
2
2
  import MDNS from 'multicast-dns';
3
3
  import { logger } from '@libp2p/logger';
4
4
  import { SERVICE_TAG_LOCAL, MULTICAST_IP, MULTICAST_PORT } from './constants.js';
5
- import { Components } from '@libp2p/components';
6
5
  import { findPeerInfoInAnswers } from './utils.js';
7
6
  import { symbol } from '@libp2p/interface-peer-discovery';
8
7
  const log = logger('libp2p:mdns:compat:querier');
9
8
  export class Querier extends EventEmitter {
10
- constructor(init = {}) {
9
+ constructor(components, init = {}) {
11
10
  super();
12
- this.components = new Components();
13
11
  const { queryInterval, queryPeriod } = init;
12
+ this.components = components;
14
13
  this._init = {
15
14
  // Re-query in leu of network change detection (every 60s by default)
16
15
  queryInterval: queryInterval ?? 60000,
@@ -26,9 +25,6 @@ export class Querier extends EventEmitter {
26
25
  get [Symbol.toStringTag]() {
27
26
  return '@libp2p/go-mdns-querier';
28
27
  }
29
- init(components) {
30
- this.components = components;
31
- }
32
28
  isStarted() {
33
29
  return Boolean(this._handle);
34
30
  }
@@ -63,7 +59,7 @@ export class Querier extends EventEmitter {
63
59
  _onResponse(event, info) {
64
60
  log.trace('received mDNS query response');
65
61
  const answers = event.answers ?? [];
66
- const peerInfo = findPeerInfoInAnswers(answers, this.components.getPeerId());
62
+ const peerInfo = findPeerInfoInAnswers(answers, this.components.peerId);
67
63
  if (peerInfo == null) {
68
64
  log('could not read peer data from query response');
69
65
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"querier.js","sourceRoot":"","sources":["../../../src/compat/querier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,IAAI,MAAM,eAAe,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAIhF,OAAO,EAAE,UAAU,EAAiB,MAAM,oBAAoB,CAAA;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AAEzD,MAAM,GAAG,GAAG,MAAM,CAAC,4BAA4B,CAAC,CAAA;AAWhD,MAAM,OAAO,OAAQ,SAAQ,YAAiC;IAK5D,YAAa,OAAoB,EAAE;QACjC,KAAK,EAAE,CAAA;QAHD,eAAU,GAAe,IAAI,UAAU,EAAE,CAAA;QAK/C,MA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BAAgB;YAAE,EAAE,GAAG,CAAC,CAAA;QAC1C,OAAO,EAAE,CAAA;IACX,CAAC,CAAA;AACH,CAAC,CAAC,EAAE,CAAA"}
@@ -1,12 +1,11 @@
1
1
  /// <reference types="node" />
2
2
  import { QueryPacket } from 'multicast-dns';
3
3
  import type { RemoteInfo } from 'dgram';
4
- import { Components, Initializable } from '@libp2p/components';
5
- export declare class Responder implements Initializable {
6
- private components;
4
+ import type { MulticastDNSComponents } from '../index.js';
5
+ export declare class Responder {
6
+ private readonly components;
7
7
  private _mdns?;
8
- constructor();
9
- init(components: Components): void;
8
+ constructor(components: MulticastDNSComponents);
10
9
  start(): void;
11
10
  _onQuery(event: QueryPacket, info: RemoteInfo): void;
12
11
  stop(): Promise<void> | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"responder.d.ts","sourceRoot":"","sources":["../../../src/compat/responder.ts"],"names":[],"mappings":";AACA,OAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAIjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAEvC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAI9D,qBAAa,SAAU,YAAW,aAAa;IAC7C,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,KAAK,CAAC,CAAmB;;IAMjC,IAAI,CAAE,UAAU,EAAE,UAAU,GAAG,IAAI;IAInC,KAAK;IAKL,QAAQ,CAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU;IA8E9C,IAAI;CAYL"}
1
+ {"version":3,"file":"responder.d.ts","sourceRoot":"","sources":["../../../src/compat/responder.ts"],"names":[],"mappings":";AACA,OAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAIjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAEvC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAwB;IACnD,OAAO,CAAC,KAAK,CAAC,CAAmB;gBAEpB,UAAU,EAAE,sBAAsB;IAK/C,KAAK;IAKL,QAAQ,CAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU;IA8E9C,IAAI;CAYL"}
@@ -3,22 +3,18 @@ import MDNS from 'multicast-dns';
3
3
  import { logger } from '@libp2p/logger';
4
4
  import { SERVICE_TAG_LOCAL } from './constants.js';
5
5
  import { protocols } from '@multiformats/multiaddr';
6
- import { Components } from '@libp2p/components';
7
6
  const log = logger('libp2p:mdns:compat:responder');
8
7
  export class Responder {
9
- constructor() {
10
- this.components = new Components();
11
- this._onQuery = this._onQuery.bind(this);
12
- }
13
- init(components) {
8
+ constructor(components) {
14
9
  this.components = components;
10
+ this._onQuery = this._onQuery.bind(this);
15
11
  }
16
12
  start() {
17
13
  this._mdns = MDNS();
18
14
  this._mdns.on('query', this._onQuery);
19
15
  }
20
16
  _onQuery(event, info) {
21
- const addresses = this.components.getAddressManager().getAddresses().reduce((acc, addr) => {
17
+ const addresses = this.components.addressManager.getAddresses().reduce((acc, addr) => {
22
18
  addr = addr.decapsulateCode(protocols('p2p').code);
23
19
  if (addr.isThinWaistAddress()) {
24
20
  acc.push(addr.toOptions());
@@ -36,7 +32,7 @@ export class Responder {
36
32
  return;
37
33
  log.trace('got query', event, info);
38
34
  const answers = [];
39
- const peerServiceTagLocal = `${this.components.getPeerId().toString()}.${SERVICE_TAG_LOCAL}`;
35
+ const peerServiceTagLocal = `${this.components.peerId.toString()}.${SERVICE_TAG_LOCAL}`;
40
36
  answers.push({
41
37
  name: SERVICE_TAG_LOCAL,
42
38
  type: 'PTR',
@@ -49,7 +45,7 @@ export class Responder {
49
45
  type: 'TXT',
50
46
  class: 'IN',
51
47
  ttl: 120,
52
- data: [Buffer.from(this.components.getPeerId().toString())]
48
+ data: [Buffer.from(this.components.peerId.toString())]
53
49
  });
54
50
  addresses.forEach(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E,EAAE,CAAC,IAAI;oBACb,MAAM,EAAE,EAAE,CAAC,QAAQ,EAAE;iBACtB;aACF,CAAC,CAAA;YAEF,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,EAAE,CAAC,QAAQ,EAAE;gBACnB,IAAI,EAAE,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM;gBACpC,KAAK,EAAE,IAAI;gBACX,GAAG,EAAE,GAAG;gBACR,IAAI,EAAE,EAAE,CAAC,IAAI;aACd,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE;YACtB,GAAG,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAA;YAChC,GAAG,CAAC,KAAK,CAAC,eAAe,EAAE,OAAO,CAAC,CAAA;YAEnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;SAClC;IACH,CAAC;IAED,IAAI;QACF,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE;YACtB,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;YACjD,OAAO,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE;gBACjC,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE;oBACtB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;iBAC5B;qBAAM;oBACL,OAAO,EAAE,CAAA;iBACV;YACH,CAAC,CAAC,CAAA;SACH;IACH,CAAC;CACF"}
@@ -1,10 +1,7 @@
1
- import multicastDNS from 'multicast-dns';
2
- import { EventEmitter } from '@libp2p/interfaces/events';
3
- import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery';
4
- import type { PeerInfo } from '@libp2p/interface-peer-info';
5
- import { Components, Initializable } from '@libp2p/components';
6
- import { symbol } from '@libp2p/interface-peer-discovery';
7
- export interface MulticastDNSOptions {
1
+ import type { PeerDiscovery } from '@libp2p/interface-peer-discovery';
2
+ import type { PeerId } from '@libp2p/interface-peer-id';
3
+ import type { AddressManager } from '@libp2p/interface-address-manager';
4
+ export interface MulticastDNSInit {
8
5
  broadcast?: boolean;
9
6
  interval?: number;
10
7
  serviceTag?: string;
@@ -13,34 +10,9 @@ export interface MulticastDNSOptions {
13
10
  compatQueryPeriod?: number;
14
11
  compatQueryInterval?: number;
15
12
  }
16
- export declare class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Initializable {
17
- mdns?: multicastDNS.MulticastDNS;
18
- private readonly broadcast;
19
- private readonly interval;
20
- private readonly serviceTag;
21
- private readonly port;
22
- private _queryInterval;
23
- private readonly _goMdns?;
24
- private components;
25
- constructor(options?: MulticastDNSOptions);
26
- get [symbol](): true;
27
- get [Symbol.toStringTag](): string;
28
- init(components: Components): void;
29
- isStarted(): boolean;
30
- /**
31
- * Start sending queries to the LAN.
32
- *
33
- * @returns {void}
34
- */
35
- start(): Promise<void>;
36
- _onMdnsQuery(event: multicastDNS.QueryPacket): void;
37
- _onMdnsResponse(event: multicastDNS.ResponsePacket): void;
38
- _onPeer(evt: CustomEvent<PeerInfo>): void;
39
- /**
40
- * Stop sending queries to the LAN.
41
- *
42
- * @returns {Promise}
43
- */
44
- stop(): Promise<void>;
13
+ export interface MulticastDNSComponents {
14
+ peerId: PeerId;
15
+ addressManager: AddressManager;
45
16
  }
17
+ export declare function mdns(init?: MulticastDNSInit): (components: MulticastDNSComponents) => PeerDiscovery;
46
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,EAAe,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAIrE,OAAO,KAAK,EAAE,aAAa,E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C,cAAc;IAkBnD,OAAO,CAAE,GAAG,EAAE,WAAW,CAAC,QAAQ,CAAC;IAUnC;;;;OAIG;IACG,IAAI;CA2BX"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAuB,MAAM,kCAAkC,CAAA;AAG1F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAIvE,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC7B;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,cAAc,CAAA;CAC/B;AA2ID,wBAAgB,IAAI,CAAE,IAAI,GAAE,gBAAqB,GAAG,CAAC,UAAU,EAAE,sBAAsB,KAAK,aAAa,CAExG"}
package/dist/src/index.js CHANGED
@@ -3,25 +3,24 @@ import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events';
3
3
  import { logger } from '@libp2p/logger';
4
4
  import * as query from './query.js';
5
5
  import { GoMulticastDNS } from './compat/index.js';
6
- import { Components } from '@libp2p/components';
7
6
  import { symbol } from '@libp2p/interface-peer-discovery';
8
7
  const log = logger('libp2p:mdns');
9
- export class MulticastDNS extends EventEmitter {
10
- constructor(options = {}) {
8
+ class MulticastDNS extends EventEmitter {
9
+ constructor(components, init = {}) {
11
10
  super();
12
- this.components = new Components();
13
- this.broadcast = options.broadcast !== false;
14
- this.interval = options.interval ?? (1e3 * 10);
15
- this.serviceTag = options.serviceTag ?? 'ipfs.local';
16
- this.port = options.port ?? 5353;
11
+ this.components = components;
12
+ this.broadcast = init.broadcast !== false;
13
+ this.interval = init.interval ?? (1e3 * 10);
14
+ this.serviceTag = init.serviceTag ?? 'ipfs.local';
15
+ this.port = init.port ?? 5353;
17
16
  this._queryInterval = null;
18
17
  this._onPeer = this._onPeer.bind(this);
19
18
  this._onMdnsQuery = this._onMdnsQuery.bind(this);
20
19
  this._onMdnsResponse = this._onMdnsResponse.bind(this);
21
- if (options.compat !== false) {
22
- this._goMdns = new GoMulticastDNS({
23
- queryPeriod: options.compatQueryPeriod,
24
- queryInterval: options.compatQueryInterval
20
+ if (init.compat !== false) {
21
+ this._goMdns = new GoMulticastDNS(components, {
22
+ queryPeriod: init.compatQueryPeriod,
23
+ queryInterval: init.compatQueryInterval
25
24
  });
26
25
  this._goMdns.addEventListener('peer', this._onPeer);
27
26
  }
@@ -32,10 +31,6 @@ export class MulticastDNS extends EventEmitter {
32
31
  get [Symbol.toStringTag]() {
33
32
  return '@libp2p/mdns';
34
33
  }
35
- init(components) {
36
- this.components = components;
37
- this._goMdns?.init(components);
38
- }
39
34
  isStarted() {
40
35
  return Boolean(this.mdns);
41
36
  }
@@ -61,12 +56,12 @@ export class MulticastDNS extends EventEmitter {
61
56
  return;
62
57
  }
63
58
  log.trace('received incoming mDNS query');
64
- query.gotQuery(event, this.mdns, this.components.getPeerId(), this.components.getAddressManager().getAddresses(), this.serviceTag, this.broadcast);
59
+ query.gotQuery(event, this.mdns, this.components.peerId, this.components.addressManager.getAddresses(), this.serviceTag, this.broadcast);
65
60
  }
66
61
  _onMdnsResponse(event) {
67
62
  log.trace('received mDNS query response');
68
63
  try {
69
- const foundPeer = query.gotResponse(event, this.components.getPeerId(), this.serviceTag);
64
+ const foundPeer = query.gotResponse(event, this.components.peerId, this.serviceTag);
70
65
  if (foundPeer != null) {
71
66
  log('discovered peer in mDNS qeury response %p', foundPeer.id);
72
67
  this.dispatchEvent(new CustomEvent('peer', {
@@ -116,6 +111,9 @@ export class MulticastDNS extends EventEmitter {
116
111
  this.mdns = undefined;
117
112
  }
118
113
  }
114
+ export function mdns(init = {}) {
115
+ return (components) => new MulticastDNS(components, init);
116
+ }
119
117
  /* for reference
120
118
 
121
119
  [ { name: 'discovery.ipfs.io.local',
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAGlD,OAAO,EAAE,UAAU,EAAiB,MAAM,oBAAoB,CAAA;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AAEzD,MAAM,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AAYjC,MAAM,OAAO,YAAa,SAAQ,YAAiC;IAWjE,YAAa,UAA+B,EAAE;QAC5C,KAAK,EAAE,CAAA;QAHD,eAAU,GAAe,IAAI,UAAU,EAAE,CAAA;QAK/C,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,KAAK,KAAK,CAAA;QAC5C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,CAAA;QAC9C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,YAAY,CAAA;QACpD,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAA;QAChC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CA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AAC,cAAc,CAAC,CAAA;YAClC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA;SAC3B;QAED,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE;YACpB,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBAC5B,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE;oBACrB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;iBAC3B;qBAAM;oBACL,OAAO,EAAE,CAAA;iBACV;YACH,CAAC,CAAC;SACH,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsCE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/mdns",
3
- "version": "3.0.1",
3
+ "version": "5.0.0",
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-mdns#readme",
@@ -134,7 +134,6 @@
134
134
  "release": "aegir release"
135
135
  },
136
136
  "dependencies": {
137
- "@libp2p/components": "^2.1.0",
138
137
  "@libp2p/interface-peer-discovery": "^1.0.1",
139
138
  "@libp2p/interface-peer-id": "^1.0.4",
140
139
  "@libp2p/interface-peer-info": "^1.0.3",
@@ -144,11 +143,11 @@
144
143
  "@multiformats/multiaddr": "^11.0.0",
145
144
  "@types/multicast-dns": "^7.2.1",
146
145
  "multicast-dns": "^7.2.0",
147
- "multiformats": "^9.6.3"
146
+ "multiformats": "^10.0.0"
148
147
  },
149
148
  "devDependencies": {
150
- "@libp2p/interface-address-manager": "^1.0.3",
151
- "@libp2p/interface-peer-discovery-compliance-tests": "^1.0.2",
149
+ "@libp2p/interface-address-manager": "^2.0.0",
150
+ "@libp2p/interface-peer-discovery-compliance-tests": "^2.0.0",
152
151
  "@libp2p/peer-id-factory": "^1.0.18",
153
152
  "aegir": "^37.5.3",
154
153
  "delay": "^5.0.0",
@@ -3,27 +3,27 @@ import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
3
3
  import { Responder } from './responder.js'
4
4
  import { Querier } from './querier.js'
5
5
  import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
6
- import type { Components, Initializable } from '@libp2p/components'
7
6
  import { symbol } from '@libp2p/interface-peer-discovery'
7
+ import type { MulticastDNSComponents } from '../index.js'
8
8
 
9
9
  export interface GoMulticastDNSInit {
10
10
  queryPeriod?: number
11
11
  queryInterval?: number
12
12
  }
13
13
 
14
- export class GoMulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Initializable {
14
+ export class GoMulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery {
15
15
  private _started: boolean
16
16
  private readonly _responder: Responder
17
17
  private readonly _querier: Querier
18
18
 
19
- constructor (options: GoMulticastDNSInit = {}) {
19
+ constructor (components: MulticastDNSComponents, options: GoMulticastDNSInit = {}) {
20
20
  super()
21
21
  const { queryPeriod, queryInterval } = options
22
22
 
23
23
  this._started = false
24
24
 
25
- this._responder = new Responder()
26
- this._querier = new Querier({
25
+ this._responder = new Responder(components)
26
+ this._querier = new Querier(components, {
27
27
  queryInterval,
28
28
  queryPeriod
29
29
  })
@@ -41,11 +41,6 @@ export class GoMulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements
41
41
  return '@libp2p/go-mdns'
42
42
  }
43
43
 
44
- init (components: Components): void {
45
- this._responder.init(components)
46
- this._querier.init(components)
47
- }
48
-
49
44
  isStarted () {
50
45
  return this._started
51
46
  }
@@ -5,9 +5,10 @@ import { SERVICE_TAG_LOCAL, MULTICAST_IP, MULTICAST_PORT } from './constants.js'
5
5
  import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
6
6
  import type { ResponsePacket } from 'multicast-dns'
7
7
  import type { RemoteInfo } from 'dgram'
8
- import { Components, Initializable } from '@libp2p/components'
9
8
  import { findPeerInfoInAnswers } from './utils.js'
10
9
  import { symbol } from '@libp2p/interface-peer-discovery'
10
+ import type { Startable } from '@libp2p/interfaces/dist/src/startable.js'
11
+ import type { PeerId } from '@libp2p/interface-peer-id'
11
12
 
12
13
  const log = logger('libp2p:mdns:compat:querier')
13
14
 
@@ -16,20 +17,25 @@ export interface QuerierInit {
16
17
  queryPeriod?: number
17
18
  }
18
19
 
20
+ export interface QuerierComponents {
21
+ peerId: PeerId
22
+ }
23
+
19
24
  export interface Handle {
20
25
  stop: () => Promise<void>
21
26
  }
22
27
 
23
- export class Querier extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Initializable {
28
+ export class Querier extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Startable {
24
29
  private readonly _init: Required<QuerierInit>
25
30
  private _handle?: Handle
26
- private components: Components = new Components()
31
+ private readonly components: QuerierComponents
27
32
 
28
- constructor (init: QuerierInit = {}) {
33
+ constructor (components: QuerierComponents, init: QuerierInit = {}) {
29
34
  super()
30
35
 
31
36
  const { queryInterval, queryPeriod } = init
32
37
 
38
+ this.components = components
33
39
  this._init = {
34
40
  // Re-query in leu of network change detection (every 60s by default)
35
41
  queryInterval: queryInterval ?? 60000,
@@ -51,10 +57,6 @@ export class Querier extends EventEmitter<PeerDiscoveryEvents> implements PeerDi
51
57
  return '@libp2p/go-mdns-querier'
52
58
  }
53
59
 
54
- init (components: Components): void {
55
- this.components = components
56
- }
57
-
58
60
  isStarted () {
59
61
  return Boolean(this._handle)
60
62
  }
@@ -95,7 +97,7 @@ export class Querier extends EventEmitter<PeerDiscoveryEvents> implements PeerDi
95
97
  log.trace('received mDNS query response')
96
98
  const answers = event.answers ?? []
97
99
 
98
- const peerInfo = findPeerInfoInAnswers(answers, this.components.getPeerId())
100
+ const peerInfo = findPeerInfoInAnswers(answers, this.components.peerId)
99
101
 
100
102
  if (peerInfo == null) {
101
103
  log('could not read peer data from query response')
@@ -5,20 +5,17 @@ import { SERVICE_TAG_LOCAL } from './constants.js'
5
5
  import { MultiaddrObject, protocols } from '@multiformats/multiaddr'
6
6
  import type { RemoteInfo } from 'dgram'
7
7
  import type { Answer } from 'dns-packet'
8
- import { Components, Initializable } from '@libp2p/components'
8
+ import type { MulticastDNSComponents } from '../index.js'
9
9
 
10
10
  const log = logger('libp2p:mdns:compat:responder')
11
11
 
12
- export class Responder implements Initializable {
13
- private components: Components = new Components()
12
+ export class Responder {
13
+ private readonly components: MulticastDNSComponents
14
14
  private _mdns?: MDNS.MulticastDNS
15
15
 
16
- constructor () {
17
- this._onQuery = this._onQuery.bind(this)
18
- }
19
-
20
- init (components: Components): void {
16
+ constructor (components: MulticastDNSComponents) {
21
17
  this.components = components
18
+ this._onQuery = this._onQuery.bind(this)
22
19
  }
23
20
 
24
21
  start () {
@@ -27,7 +24,7 @@ export class Responder implements Initializable {
27
24
  }
28
25
 
29
26
  _onQuery (event: QueryPacket, info: RemoteInfo) {
30
- const addresses = this.components.getAddressManager().getAddresses().reduce<MultiaddrObject[]>((acc, addr) => {
27
+ const addresses = this.components.addressManager.getAddresses().reduce<MultiaddrObject[]>((acc, addr) => {
31
28
  addr = addr.decapsulateCode(protocols('p2p').code)
32
29
 
33
30
  if (addr.isThinWaistAddress()) {
@@ -51,7 +48,7 @@ export class Responder implements Initializable {
51
48
  log.trace('got query', event, info)
52
49
 
53
50
  const answers: Answer[] = []
54
- const peerServiceTagLocal = `${this.components.getPeerId().toString()}.${SERVICE_TAG_LOCAL}`
51
+ const peerServiceTagLocal = `${this.components.peerId.toString()}.${SERVICE_TAG_LOCAL}`
55
52
 
56
53
  answers.push({
57
54
  name: SERVICE_TAG_LOCAL,
@@ -66,7 +63,7 @@ export class Responder implements Initializable {
66
63
  type: 'TXT',
67
64
  class: 'IN',
68
65
  ttl: 120,
69
- data: [Buffer.from(this.components.getPeerId().toString())]
66
+ data: [Buffer.from(this.components.peerId.toString())]
70
67
  })
71
68
 
72
69
  addresses.forEach(ma => {
package/src/index.ts CHANGED
@@ -5,12 +5,13 @@ import * as query from './query.js'
5
5
  import { GoMulticastDNS } from './compat/index.js'
6
6
  import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
7
7
  import type { PeerInfo } from '@libp2p/interface-peer-info'
8
- import { Components, Initializable } from '@libp2p/components'
9
8
  import { symbol } from '@libp2p/interface-peer-discovery'
9
+ import type { PeerId } from '@libp2p/interface-peer-id'
10
+ import type { AddressManager } from '@libp2p/interface-address-manager'
10
11
 
11
12
  const log = logger('libp2p:mdns')
12
13
 
13
- export interface MulticastDNSOptions {
14
+ export interface MulticastDNSInit {
14
15
  broadcast?: boolean
15
16
  interval?: number
16
17
  serviceTag?: string
@@ -20,7 +21,12 @@ export interface MulticastDNSOptions {
20
21
  compatQueryInterval?: number
21
22
  }
22
23
 
23
- export class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Initializable {
24
+ export interface MulticastDNSComponents {
25
+ peerId: PeerId
26
+ addressManager: AddressManager
27
+ }
28
+
29
+ class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery {
24
30
  public mdns?: multicastDNS.MulticastDNS
25
31
 
26
32
  private readonly broadcast: boolean
@@ -29,24 +35,25 @@ export class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements P
29
35
  private readonly port: number
30
36
  private _queryInterval: ReturnType<typeof setInterval> | null
31
37
  private readonly _goMdns?: GoMulticastDNS
32
- private components: Components = new Components()
38
+ private readonly components: MulticastDNSComponents
33
39
 
34
- constructor (options: MulticastDNSOptions = {}) {
40
+ constructor (components: MulticastDNSComponents, init: MulticastDNSInit = {}) {
35
41
  super()
36
42
 
37
- this.broadcast = options.broadcast !== false
38
- this.interval = options.interval ?? (1e3 * 10)
39
- this.serviceTag = options.serviceTag ?? 'ipfs.local'
40
- this.port = options.port ?? 5353
43
+ this.components = components
44
+ this.broadcast = init.broadcast !== false
45
+ this.interval = init.interval ?? (1e3 * 10)
46
+ this.serviceTag = init.serviceTag ?? 'ipfs.local'
47
+ this.port = init.port ?? 5353
41
48
  this._queryInterval = null
42
49
  this._onPeer = this._onPeer.bind(this)
43
50
  this._onMdnsQuery = this._onMdnsQuery.bind(this)
44
51
  this._onMdnsResponse = this._onMdnsResponse.bind(this)
45
52
 
46
- if (options.compat !== false) {
47
- this._goMdns = new GoMulticastDNS({
48
- queryPeriod: options.compatQueryPeriod,
49
- queryInterval: options.compatQueryInterval
53
+ if (init.compat !== false) {
54
+ this._goMdns = new GoMulticastDNS(components, {
55
+ queryPeriod: init.compatQueryPeriod,
56
+ queryInterval: init.compatQueryInterval
50
57
  })
51
58
  this._goMdns.addEventListener('peer', this._onPeer)
52
59
  }
@@ -60,12 +67,6 @@ export class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements P
60
67
  return '@libp2p/mdns'
61
68
  }
62
69
 
63
- init (components: Components): void {
64
- this.components = components
65
-
66
- this._goMdns?.init(components)
67
- }
68
-
69
70
  isStarted () {
70
71
  return Boolean(this.mdns)
71
72
  }
@@ -97,14 +98,14 @@ export class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements P
97
98
  }
98
99
 
99
100
  log.trace('received incoming mDNS query')
100
- query.gotQuery(event, this.mdns, this.components.getPeerId(), this.components.getAddressManager().getAddresses(), this.serviceTag, this.broadcast)
101
+ query.gotQuery(event, this.mdns, this.components.peerId, this.components.addressManager.getAddresses(), this.serviceTag, this.broadcast)
101
102
  }
102
103
 
103
104
  _onMdnsResponse (event: multicastDNS.ResponsePacket) {
104
105
  log.trace('received mDNS query response')
105
106
 
106
107
  try {
107
- const foundPeer = query.gotResponse(event, this.components.getPeerId(), this.serviceTag)
108
+ const foundPeer = query.gotResponse(event, this.components.peerId, this.serviceTag)
108
109
 
109
110
  if (foundPeer != null) {
110
111
  log('discovered peer in mDNS qeury response %p', foundPeer.id)
@@ -162,6 +163,10 @@ export class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements P
162
163
  }
163
164
  }
164
165
 
166
+ export function mdns (init: MulticastDNSInit = {}): (components: MulticastDNSComponents) => PeerDiscovery {
167
+ return (components: MulticastDNSComponents) => new MulticastDNS(components, init)
168
+ }
169
+
165
170
  /* for reference
166
171
 
167
172
  [ { name: 'discovery.ipfs.io.local',