re-implemented personal mDNS responses

This commit is contained in:
tigerbot 2017-06-16 13:21:20 -06:00
parent 72ff8ebf15
commit 0a0f06094e
1 changed files with 11 additions and 8 deletions

View File

@ -137,15 +137,13 @@ module.exports.start = function (deps, config, mainPort) {
randomId.get().then(function (name) { randomId.get().then(function (name) {
var resp = createResponse(name, packet, config.mdns.ttl, mainPort); var resp = createResponse(name, packet, config.mdns.ttl, mainPort);
// TODO: uncomment the lines below after the demo and fix the installer so that var now = Date.now();
// it can get the direct responses even on macOS. if (now > nextBroadcast) {
// var now = Date.now();
// if (now > nextBroadcast) {
socket.send(resp, config.mdns.port, config.mdns.broadcast); socket.send(resp, config.mdns.port, config.mdns.broadcast);
// nextBroadcast = now + config.mdns.ttl * 1000; nextBroadcast = now + config.mdns.ttl * 1000;
// } else { } else {
// socket.send(resp, rinfo.port, rinfo.address); socket.send(resp, rinfo.port, rinfo.address);
// } }
}); });
}); });
@ -155,5 +153,10 @@ module.exports.start = function (deps, config, mainPort) {
socket.setBroadcast(true); socket.setBroadcast(true);
socket.addMembership(config.mdns.broadcast); socket.addMembership(config.mdns.broadcast);
// This is supposed to be a local device discovery mechanism, so we shouldn't
// need to hop through any gateways. This helps with security by making it
// much more difficult for someone to use us as part of a DDoS attack by
// spoofing the UDP address a request came from.
socket.setTTL(1);
}); });
}; };