@libp2p/mdns 1.0.2 → 1.0.3
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/dist/src/compat/querier.js +6 -6
- package/dist/src/compat/utils.d.ts +2 -2
- package/dist/src/compat/utils.js +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/query.d.ts +2 -2
- package/package.json +3 -3
- package/src/compat/querier.ts +6 -6
- package/src/compat/utils.ts +2 -2
- package/src/index.ts +4 -4
- package/src/query.ts +2 -2
|
@@ -3,7 +3,7 @@ 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
5
|
import { Components } from '@libp2p/interfaces/components';
|
|
6
|
-
import {
|
|
6
|
+
import { findPeerInfoInAnswers } from './utils.js';
|
|
7
7
|
const log = logger('libp2p:mdns:compat:querier');
|
|
8
8
|
export class Querier extends EventEmitter {
|
|
9
9
|
constructor(init = {}) {
|
|
@@ -56,18 +56,18 @@ export class Querier extends EventEmitter {
|
|
|
56
56
|
_onResponse(event, info) {
|
|
57
57
|
log.trace('received mDNS query response');
|
|
58
58
|
const answers = event.answers ?? [];
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
59
|
+
const peerInfo = findPeerInfoInAnswers(answers, this.components.getPeerId());
|
|
60
|
+
if (peerInfo == null) {
|
|
61
61
|
log('could not read peer data from query response');
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
if (
|
|
64
|
+
if (peerInfo.multiaddrs.length === 0) {
|
|
65
65
|
log('could not parse multiaddrs from mDNS response');
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
-
log('discovered peer in mDNS qeury response %p',
|
|
68
|
+
log('discovered peer in mDNS qeury response %p', peerInfo.id);
|
|
69
69
|
this.dispatchEvent(new CustomEvent('peer', {
|
|
70
|
-
detail:
|
|
70
|
+
detail: peerInfo
|
|
71
71
|
}));
|
|
72
72
|
}
|
|
73
73
|
async stop() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PeerInfo } from '@libp2p/interfaces/peer-info';
|
|
2
2
|
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
|
3
3
|
import type { Answer } from 'dns-packet';
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function findPeerInfoInAnswers(answers: Answer[], ourPeerId: PeerId): PeerInfo | undefined;
|
|
5
5
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/src/compat/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ import { peerIdFromString } from '@libp2p/peer-id';
|
|
|
3
3
|
import { Multiaddr } from '@multiformats/multiaddr';
|
|
4
4
|
import { SERVICE_TAG_LOCAL } from './constants.js';
|
|
5
5
|
const log = logger('libp2p:mdns:compat:utils');
|
|
6
|
-
export function
|
|
6
|
+
export function findPeerInfoInAnswers(answers, ourPeerId) {
|
|
7
7
|
const ptrRecord = answers.find(a => a.type === 'PTR' && a.name === SERVICE_TAG_LOCAL);
|
|
8
8
|
// Only deal with responses for our service tag
|
|
9
9
|
if (ptrRecord == null) {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import multicastDNS from 'multicast-dns';
|
|
2
2
|
import { EventEmitter } from '@libp2p/interfaces';
|
|
3
3
|
import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interfaces/peer-discovery';
|
|
4
|
-
import type {
|
|
4
|
+
import type { PeerInfo } from '@libp2p/interfaces/peer-info';
|
|
5
5
|
import { Components, Initializable } from '@libp2p/interfaces/components';
|
|
6
6
|
export interface MulticastDNSOptions {
|
|
7
7
|
broadcast?: boolean;
|
|
@@ -33,7 +33,7 @@ export declare class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> impl
|
|
|
33
33
|
start(): Promise<void>;
|
|
34
34
|
_onMdnsQuery(event: multicastDNS.QueryPacket): void;
|
|
35
35
|
_onMdnsResponse(event: multicastDNS.ResponsePacket): void;
|
|
36
|
-
_onPeer(evt: CustomEvent<
|
|
36
|
+
_onPeer(evt: CustomEvent<PeerInfo>): void;
|
|
37
37
|
/**
|
|
38
38
|
* Stop sending queries to the LAN.
|
|
39
39
|
*
|
package/dist/src/query.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Multiaddr } from '@multiformats/multiaddr';
|
|
3
3
|
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
|
4
|
-
import type {
|
|
4
|
+
import type { PeerInfo } from '@libp2p/interfaces/peer-info';
|
|
5
5
|
import type { MulticastDNS, ResponsePacket, QueryPacket } from 'multicast-dns';
|
|
6
6
|
export declare function queryLAN(mdns: MulticastDNS, serviceTag: string, interval: number): NodeJS.Timer;
|
|
7
|
-
export declare function gotResponse(rsp: ResponsePacket, localPeerId: PeerId, serviceTag: string):
|
|
7
|
+
export declare function gotResponse(rsp: ResponsePacket, localPeerId: PeerId, serviceTag: string): PeerInfo | undefined;
|
|
8
8
|
export declare function gotQuery(qry: QueryPacket, mdns: MulticastDNS, peerId: PeerId, multiaddrs: Multiaddr[], serviceTag: string, broadcast: boolean): void;
|
|
9
9
|
//# sourceMappingURL=query.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/mdns",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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",
|
|
@@ -136,8 +136,8 @@
|
|
|
136
136
|
"multiformats": "^9.6.3"
|
|
137
137
|
},
|
|
138
138
|
"devDependencies": {
|
|
139
|
-
"@libp2p/interface-compliance-tests": "^1.1.
|
|
140
|
-
"@libp2p/interfaces": "^1.3.
|
|
139
|
+
"@libp2p/interface-compliance-tests": "^1.1.20",
|
|
140
|
+
"@libp2p/interfaces": "^1.3.18",
|
|
141
141
|
"@libp2p/peer-id-factory": "^1.0.8",
|
|
142
142
|
"@types/multicast-dns": "^7.2.1",
|
|
143
143
|
"aegir": "^36.1.3",
|
package/src/compat/querier.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interfaces/peer
|
|
|
6
6
|
import type { ResponsePacket } from 'multicast-dns'
|
|
7
7
|
import type { RemoteInfo } from 'dgram'
|
|
8
8
|
import { Components, Initializable } from '@libp2p/interfaces/components'
|
|
9
|
-
import {
|
|
9
|
+
import { findPeerInfoInAnswers } from './utils.js'
|
|
10
10
|
|
|
11
11
|
const log = logger('libp2p:mdns:compat:querier')
|
|
12
12
|
|
|
@@ -86,22 +86,22 @@ export class Querier extends EventEmitter<PeerDiscoveryEvents> implements PeerDi
|
|
|
86
86
|
log.trace('received mDNS query response')
|
|
87
87
|
const answers = event.answers ?? []
|
|
88
88
|
|
|
89
|
-
const
|
|
89
|
+
const peerInfo = findPeerInfoInAnswers(answers, this.components.getPeerId())
|
|
90
90
|
|
|
91
|
-
if (
|
|
91
|
+
if (peerInfo == null) {
|
|
92
92
|
log('could not read peer data from query response')
|
|
93
93
|
return
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
if (
|
|
96
|
+
if (peerInfo.multiaddrs.length === 0) {
|
|
97
97
|
log('could not parse multiaddrs from mDNS response')
|
|
98
98
|
return
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
log('discovered peer in mDNS qeury response %p',
|
|
101
|
+
log('discovered peer in mDNS qeury response %p', peerInfo.id)
|
|
102
102
|
|
|
103
103
|
this.dispatchEvent(new CustomEvent('peer', {
|
|
104
|
-
detail:
|
|
104
|
+
detail: peerInfo
|
|
105
105
|
}))
|
|
106
106
|
}
|
|
107
107
|
|
package/src/compat/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
|
|
2
2
|
import type { PeerId } from '@libp2p/interfaces/peer-id'
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
@@ -8,7 +8,7 @@ import { SERVICE_TAG_LOCAL } from './constants.js'
|
|
|
8
8
|
|
|
9
9
|
const log = logger('libp2p:mdns:compat:utils')
|
|
10
10
|
|
|
11
|
-
export function
|
|
11
|
+
export function findPeerInfoInAnswers (answers: Answer[], ourPeerId: PeerId): PeerInfo | undefined {
|
|
12
12
|
const ptrRecord = answers.find(a => a.type === 'PTR' && a.name === SERVICE_TAG_LOCAL)
|
|
13
13
|
|
|
14
14
|
// Only deal with responses for our service tag
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { logger } from '@libp2p/logger'
|
|
|
4
4
|
import * as query from './query.js'
|
|
5
5
|
import { GoMulticastDNS } from './compat/index.js'
|
|
6
6
|
import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interfaces/peer-discovery'
|
|
7
|
-
import type {
|
|
7
|
+
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
|
|
8
8
|
import { Components, Initializable } from '@libp2p/interfaces/components'
|
|
9
9
|
|
|
10
10
|
const log = logger('libp2p:mdns')
|
|
@@ -102,7 +102,7 @@ export class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements P
|
|
|
102
102
|
if (foundPeer != null) {
|
|
103
103
|
log('discovered peer in mDNS qeury response %p', foundPeer.id)
|
|
104
104
|
|
|
105
|
-
this.dispatchEvent(new CustomEvent<
|
|
105
|
+
this.dispatchEvent(new CustomEvent<PeerInfo>('peer', {
|
|
106
106
|
detail: foundPeer
|
|
107
107
|
}))
|
|
108
108
|
}
|
|
@@ -111,12 +111,12 @@ export class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements P
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
_onPeer (evt: CustomEvent<
|
|
114
|
+
_onPeer (evt: CustomEvent<PeerInfo>) {
|
|
115
115
|
if (this.mdns == null) {
|
|
116
116
|
return
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
this.dispatchEvent(new CustomEvent<
|
|
119
|
+
this.dispatchEvent(new CustomEvent<PeerInfo>('peer', {
|
|
120
120
|
detail: evt.detail
|
|
121
121
|
}))
|
|
122
122
|
}
|
package/src/query.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { logger } from '@libp2p/logger'
|
|
|
3
3
|
import { Multiaddr, MultiaddrObject, protocols } from '@multiformats/multiaddr'
|
|
4
4
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
5
5
|
import type { PeerId } from '@libp2p/interfaces/peer-id'
|
|
6
|
-
import type {
|
|
6
|
+
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
|
|
7
7
|
import type { MulticastDNS, ResponsePacket, QueryPacket } from 'multicast-dns'
|
|
8
8
|
import type { SrvAnswer, StringAnswer, TxtAnswer, Answer } from 'dns-packet'
|
|
9
9
|
|
|
@@ -34,7 +34,7 @@ interface Answers {
|
|
|
34
34
|
aaaa: StringAnswer[]
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export function gotResponse (rsp: ResponsePacket, localPeerId: PeerId, serviceTag: string):
|
|
37
|
+
export function gotResponse (rsp: ResponsePacket, localPeerId: PeerId, serviceTag: string): PeerInfo | undefined {
|
|
38
38
|
if (rsp.answers == null) {
|
|
39
39
|
return
|
|
40
40
|
}
|