added actual port to the mDNS response

This commit is contained in:
tigerbot 2017-06-08 13:21:58 -06:00
parent 027494cd1d
commit ec07b6fcdb
2 changed files with 7 additions and 6 deletions

View File

@ -232,7 +232,8 @@ module.exports.create = function (deps, config) {
addPorts(config.tls.bind); addPorts(config.tls.bind);
addPorts(config.http.bind); addPorts(config.http.bind);
Object.keys(tcpPortMap).forEach(function (port) { var portList = Object.keys(tcpPortMap).map(Number).sort();
portList.forEach(function (port) {
listenPromises.push(listeners.tcp.add(port, netHandler)); listenPromises.push(listeners.tcp.add(port, netHandler));
}); });
@ -247,7 +248,7 @@ module.exports.create = function (deps, config) {
} }
if (!config.mdns.disabled) { if (!config.mdns.disabled) {
require('./mdns').start(deps, config); require('./mdns').start(deps, config, portList[0]);
} }
return PromiseA.all(listenPromises); return PromiseA.all(listenPromises);

View File

@ -31,7 +31,7 @@ var randomId = {
} }
}; };
function createResponse(name, packet, ttl) { function createResponse(name, packet, ttl, mainPort) {
var rpacket = { var rpacket = {
header: { header: {
id: packet.header.id id: packet.header.id
@ -93,7 +93,7 @@ function createResponse(name, packet, ttl) {
, className: 'IN' , className: 'IN'
, priority: 1 , priority: 1
, weight: 0 , weight: 0
, port: 443 , port: mainPort
, target: name + ".local" , target: name + ".local"
}); });
rpacket.additional.push({ rpacket.additional.push({
@ -107,7 +107,7 @@ function createResponse(name, packet, ttl) {
return require('dns-suite').DNSPacket.write(rpacket); return require('dns-suite').DNSPacket.write(rpacket);
} }
module.exports.start = function (deps, config) { module.exports.start = function (deps, config, mainPort) {
var socket = require('dgram').createSocket({ type: 'udp4', reuseAddr: true }); var socket = require('dgram').createSocket({ type: 'udp4', reuseAddr: true });
var dns = require('dns-suite'); var dns = require('dns-suite');
var nextBroadcast = -1; var nextBroadcast = -1;
@ -136,7 +136,7 @@ module.exports.start = function (deps, config) {
} }
randomId.get().then(function (name) { randomId.get().then(function (name) {
var resp = createResponse(name, packet, config.mdns.ttl); var resp = createResponse(name, packet, config.mdns.ttl, mainPort);
var now = Date.now(); var now = Date.now();
if (now > nextBroadcast) { if (now > nextBroadcast) {
socket.send(resp, config.mdns.port, config.mdns.broadcast); socket.send(resp, config.mdns.port, config.mdns.broadcast);