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

Commit

Permalink
feat: update to that new peer-info everyone is talking about
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Mar 30, 2017
1 parent d29da66 commit 3fd3602
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@
},
"homepage": "https://github.com/libp2p/js-libp2p-mdns",
"devDependencies": {
"aegir": "^10.0.0",
"async": "^2.1.4",
"aegir": "^11.0.1",
"async": "^2.2.0",
"chai": "^3.5.0",
"dirty-chai": "^1.2.2",
"pre-commit": "^1.2.2"
},
"dependencies": {
"libp2p-tcp": "~0.9.3",
"multiaddr": "^2.2.1",
"multicast-dns": "^6.1.0",
"peer-id": "~0.8.2",
"peer-info": "~0.8.3"
"libp2p-tcp": "~0.10.0",
"multiaddr": "^2.3.0",
"multicast-dns": "^6.1.1",
"peer-id": "~0.8.6",
"peer-info": "~0.9.0"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
Expand All @@ -50,4 +51,4 @@
"emersion <contact@emersion.fr>",
"greenkeeperio-bot <support@greenkeeper.io>"
]
}
}
7 changes: 2 additions & 5 deletions src/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ module.exports = {
return log('Error creating PeerInfo from new found peer', err)
}

multiaddrs.forEach((addr) => {
peerFound.multiaddr.add(addr)
})
multiaddrs.forEach((addr) => peerFound.multiaddrs.add(addr))

callback(null, peerFound)
})
Expand All @@ -82,7 +80,7 @@ module.exports = {
gotQuery: function (qry, mdns, peerInfo, serviceTag, broadcast) {
if (!broadcast) { return }

const multiaddrs = tcp.filter(peerInfo.multiaddrs)
const multiaddrs = tcp.filter(peerInfo.multiaddrs.toArray())
// Only announce TCP for now
if (multiaddrs.length === 0) { return }

Expand Down Expand Up @@ -140,7 +138,6 @@ module.exports = {
ttl: 120,
data: ma.toString().split('/')[2]
})
return
}
})

Expand Down
25 changes: 15 additions & 10 deletions test/multicast-dns.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const multiaddr = require('multiaddr')
const PeerInfo = require('peer-info')
const parallel = require('async/parallel')
Expand All @@ -18,34 +21,36 @@ describe('MulticastDNS', () => {
parallel([
(cb) => {
PeerInfo.create((err, peer) => {
if (err) { cb(err) }
expect(err).to.not.exist()

pA = peer
pA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/20001'))
pA.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/20001'))
cb()
})
},
(cb) => {
PeerInfo.create((err, peer) => {
if (err) { cb(err) }
expect(err).to.not.exist()

pB = peer
pB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/20002'))
pB.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/20002'))
cb()
})
},
(cb) => {
PeerInfo.create((err, peer) => {
if (err) { cb(err) }
expect(err).to.not.exist()
pC = peer
pC.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/20003'))
pC.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/30003/ws'))
pC.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/20003'))
pC.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/30003/ws'))
cb()
})
},
(cb) => {
PeerInfo.create((err, peer) => {
if (err) { cb(err) }
pD = peer
pD.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/30003/ws'))
pD.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/30003/ws'))
cb()
})
}
Expand Down Expand Up @@ -89,7 +94,7 @@ describe('MulticastDNS', () => {
], () => {
mdnsA.once('peer', (peerInfo) => {
expect(pC.id.toB58String()).to.eql(peerInfo.id.toB58String())
expect(peerInfo.multiaddrs.length).to.equal(1)
expect(peerInfo.multiaddrs.size).to.equal(1)
done()
})

Expand Down

0 comments on commit 3fd3602

Please sign in to comment.