Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions lib/mdns-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var deepEqual = require('deep-equal')

module.exports = Server

const WILDCARD = '_services._dns-sd._udp.local'

function Server (opts) {
this.mdns = multicastdns(opts)
this.mdns.setMaxListeners(0)
Expand Down Expand Up @@ -50,9 +52,15 @@ Server.prototype._respondToQuery = function (query) {
var name = question.name

// generate the answers section
var answers = type === 'ANY'
? flatten.depth(Object.keys(self.registry).map(self._recordsFor.bind(self, name)), 1)
: self._recordsFor(name, type)
var answers = []
if (type === 'PTR' && name === WILDCARD) {
// Handle Service Type Enumeration (http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt section 9)
answers = self._wildcard()
} else {
answers = type === 'ANY'
? flatten.depth(Object.keys(self.registry).map(self._recordsFor.bind(self, name)), 1)
: self._recordsFor(name, type)
}

if (answers.length === 0) return

Expand Down Expand Up @@ -98,6 +106,21 @@ Server.prototype._recordsFor = function (name, type) {
})
}

Server.prototype._wildcard = function () {
if (!('PTR' in this.registry)) return []

return this.registry['PTR'].map(function (entry) {
return {
name: WILDCARD,
type: 'PTR',
class: 1, // TODO: Should these be dynamic?
ttl: 4500, // TODO: Should these be dynamic?
flush: false, // TODO: Should these be dynamic?
data: entry.name
}
})
}

function isDuplicateRecord (a) {
return function (b) {
return a.type === b.type &&
Expand Down
Loading