mDNS responder now sometimes responds directly
This commit is contained in:
parent
69d7d9e4b8
commit
810d0a8e90
|
@ -104,6 +104,7 @@ function createResponse(name, packet, ttl) {
|
||||||
module.exports.start = function (deps, config) {
|
module.exports.start = function (deps, config) {
|
||||||
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;
|
||||||
|
|
||||||
socket.on('message', function (message, rinfo) {
|
socket.on('message', function (message, rinfo) {
|
||||||
// console.log('Received %d bytes from %s:%d', message.length, rinfo.address, rinfo.port);
|
// console.log('Received %d bytes from %s:%d', message.length, rinfo.address, rinfo.port);
|
||||||
|
@ -130,7 +131,13 @@ 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);
|
||||||
socket.send(resp, config.mdns.port, config.mdns.broadcast);
|
var now = Date.now();
|
||||||
|
if (now > nextBroadcast) {
|
||||||
|
socket.send(resp, config.mdns.port, config.mdns.broadcast);
|
||||||
|
nextBroadcast = now + config.mdns.ttl * 1000;
|
||||||
|
} else {
|
||||||
|
socket.send(resp, rinfo.port, rinfo.address);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue