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

Commit

Permalink
feat: (BREAKING CHANGE) update constructor. add tag
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Jun 5, 2018
1 parent 526392b commit d3eeb6e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
},
"homepage": "https://github.com/libp2p/js-libp2p-mdns",
"devDependencies": {
"aegir": "^13.0.6",
"async": "^2.6.0",
"aegir": "^14.0.0",
"async": "^2.6.1",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"pre-commit": "^1.2.2"
},
"dependencies": {
"libp2p-tcp": "~0.12.0",
"multiaddr": "^4.0.0",
"multiaddr": "^5.0.0",
"multicast-dns": "^7.0.0",
"peer-id": "~0.10.7",
"peer-info": "~0.14.0"
"peer-info": "~0.14.1"
},
"contributors": [
"David Dias <[email protected]>",
Expand Down
10 changes: 6 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

const multicastDNS = require('multicast-dns')
const EventEmitter = require('events').EventEmitter
const assert = require('assert')
const debug = require('debug')
const log = debug('libp2p:mdns')
const query = require('./query')

class MulticastDNS extends EventEmitter {
constructor (peerInfo, options) {
constructor (options) {
super()
options = options || {}
assert(options.peerInfo, 'needs a PeerInfo to work')

this.broadcast = options.broadcast !== false
this.interval = options.interval || (1e3 * 10)
this.serviceTag = options.serviceTag || 'ipfs.local'
this.port = options.port || 5353
this.peerInfo = peerInfo
this.peerInfo = options.peerInfo
this._queryInterval = null
}

Expand Down Expand Up @@ -56,7 +57,8 @@ class MulticastDNS extends EventEmitter {
}
}

module.exports = MulticastDNS
exports = module.exports = MulticastDNS
exports.tag = 'mdns'

/* for reference
Expand Down
54 changes: 33 additions & 21 deletions test/multicast-dns.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('MulticastDNS', () => {

before(function (done) {
this.timeout(80 * 1000)

parallel([
(cb) => {
PeerInfo.create((err, peer) => {
Expand Down Expand Up @@ -63,14 +64,16 @@ describe('MulticastDNS', () => {
it('find another peer', function (done) {
this.timeout(40 * 1000)

const options = {
port: 50001 // port must be the same
}
const mdnsA = new MulticastDNS(pA, {
const mdnsA = new MulticastDNS({
peerInfo: pA,
broadcast: false, // do not talk to ourself
port: 50001
})
const mdnsB = new MulticastDNS(pB, options)

const mdnsB = new MulticastDNS({
peerInfo: pB,
port: 50001 // port must be the same
})

parallel([
(cb) => mdnsA.start(cb),
Expand All @@ -91,16 +94,19 @@ describe('MulticastDNS', () => {
it('only announce TCP multiaddrs', function (done) {
this.timeout(40 * 1000)

const options = {
port: 50003 // port must be the same
}

const mdnsA = new MulticastDNS(pA, {
const mdnsA = new MulticastDNS({
peerInfo: pA,
broadcast: false, // do not talk to ourself
port: 50003
})
const mdnsC = new MulticastDNS(pC, options)
const mdnsD = new MulticastDNS(pD, options)
const mdnsC = new MulticastDNS({
peerInfo: pC,
port: 50003 // port must be the same
})
const mdnsD = new MulticastDNS({
peerInfo: pD,
port: 50003 // port must be the same
})

parallel([
(cb) => mdnsA.start(cb),
Expand All @@ -125,14 +131,16 @@ describe('MulticastDNS', () => {
it('announces IP6 addresses', function (done) {
this.timeout(40 * 1000)

const options = {
port: 50001 // port must be the same
}
const mdnsA = new MulticastDNS(pA, {
const mdnsA = new MulticastDNS({
peerInfo: pA,
broadcast: false, // do not talk to ourself
port: 50001
})
const mdnsB = new MulticastDNS(pB, options)

const mdnsB = new MulticastDNS({
peerInfo: pB,
port: 50001
})

series([
(cb) => mdnsB.start(cb),
Expand All @@ -154,11 +162,15 @@ describe('MulticastDNS', () => {
it('doesn\'t emit peers after stop', function (done) {
this.timeout(40 * 1000)

const options = {
const mdnsA = new MulticastDNS({
peerInfo: pA,
port: 50004 // port must be the same
}
const mdnsA = new MulticastDNS(pA, options)
const mdnsC = new MulticastDNS(pC, options)
})

const mdnsC = new MulticastDNS({
peerInfo: pC,
port: 50004
})

series([
(cb) => mdnsA.start(cb),
Expand Down

0 comments on commit d3eeb6e

Please sign in to comment.