Skip to content

Commit

Permalink
Refactor generation of mdns rr additionals
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Jan 31, 2016
1 parent e377a17 commit 96be052
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/mdns-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,25 @@ Server.prototype._respondToQuery = function (query) {
query.questions.forEach(function (question) {
var type = question.type
var name = question.name

// generate the answers section
var answers = type === 'ANY'
? flatten(Object.keys(self.registry).map(self._recordsFor.bind(self, name)))
: self._recordsFor(name, type)

if (answers.length === 0) return

// generate the additionals section
var additionals = []
if (type !== 'ANY') {
answers.forEach(function (answer) {
if (answer.type !== 'PTR') return
additionals = additionals.concat(flatten(Object.keys(self.registry)
.filter(function (type) {
return ~['SRV', 'TXT'].indexOf(type)
})
.map(self._recordsFor.bind(self, answer.data))))
additionals = additionals
.concat(self._recordsFor(answer.data, 'SRV'))
.concat(self._recordsFor(answer.data, 'TXT'))
})
}

// TODO: When responding to PTR queries, the additionals array should be
// populated with the related SRV and TXT records
self.mdns.respond({ answers: answers, additionals: additionals }, function (err) {
if (err) throw err // TODO: Handle this (if no callback is given, the error will be ignored)
})
Expand Down

0 comments on commit 96be052

Please sign in to comment.