Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: actually check tcp multiaddrs (#94)
Browse files Browse the repository at this point in the history
* chore: update deps

* fix: only use actual tcp addresses
  • Loading branch information
jacobheun authored Jul 2, 2020
1 parent 60a0dbe commit 9f45f73
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"homepage": "https://github.com/libp2p/js-libp2p-mdns",
"devDependencies": {
"aegir": "^21.0.2",
"aegir": "^25.0.0",
"chai": "^4.2.0",
"delay": "^4.3.0",
"dirty-chai": "^2.0.1",
Expand All @@ -44,9 +44,9 @@
},
"dependencies": {
"debug": "^4.1.1",
"multiaddr": "^7.1.0",
"multiaddr": "^7.5.0",
"multicast-dns": "^7.2.0",
"peer-id": "~0.13.3"
"peer-id": "^0.13.13"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
Expand Down
8 changes: 7 additions & 1 deletion src/compat/responder.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ class Responder {
}

_onQuery (event, info) {
const addresses = this._multiaddrs.map(ma => ma.toOptions())
const addresses = this._multiaddrs.reduce((acc, addr) => {
if (addr.isThinWaistAddress()) {
acc.push(addr.toOptions())
}
return acc
}, [])

// Only announce TCP for now
if (!addresses.length) return

Expand Down
8 changes: 7 additions & 1 deletion src/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ module.exports = {
gotQuery: function (qry, mdns, peerId, multiaddrs, serviceTag, broadcast) {
if (!broadcast) { return }

const addresses = multiaddrs.map(ma => ma.toOptions())
const addresses = multiaddrs.reduce((acc, addr) => {
if (addr.isThinWaistAddress()) {
acc.push(addr.toOptions())
}
return acc
}, [])

// Only announce TCP for now
if (addresses.length === 0) { return }

Expand Down
10 changes: 7 additions & 3 deletions test/multicast-dns.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ describe('MulticastDNS', () => {
])

aMultiaddrs = [
multiaddr('/ip4/127.0.0.1/tcp/20001')
multiaddr('/ip4/127.0.0.1/tcp/20001'),
multiaddr('/dns4/webrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star'),
multiaddr('/dns4/discovery.libp2p.io/tcp/8443')
]

bMultiaddrs = [
multiaddr('/ip4/127.0.0.1/tcp/20002'),
multiaddr('/ip6/::1/tcp/20002')
multiaddr('/ip6/::1/tcp/20002'),
multiaddr('/dnsaddr/discovery.libp2p.io')
]

cMultiaddrs = [
multiaddr('/ip4/127.0.0.1/tcp/20003'),
multiaddr('/ip4/127.0.0.1/tcp/30003/ws')
multiaddr('/ip4/127.0.0.1/tcp/30003/ws'),
multiaddr('/dns4/discovery.libp2p.io')
]

dMultiaddrs = [
Expand Down

0 comments on commit 9f45f73

Please sign in to comment.