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

Commit

Permalink
feat: add tag, update deps and change constructor to respect the same…
Browse files Browse the repository at this point in the history
… format as the others
  • Loading branch information
daviddias committed Mar 20, 2018
1 parent d572205 commit d7fb05c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
},
"homepage": "https://github.com/libp2p/js-libp2p-mdns",
"devDependencies": {
"aegir": "^13.0.0",
"aegir": "^13.0.6",
"async": "^2.6.0",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"pre-commit": "^1.2.2"
},
"dependencies": {
"libp2p-tcp": "~0.11.5",
"libp2p-tcp": "~0.11.6",
"multiaddr": "^3.0.2",
"multicast-dns": "^7.0.0",
"peer-id": "~0.10.6",
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 d7fb05c

Please sign in to comment.