Comparing version 0.1.2 to 0.1.3
@@ -20,5 +20,5 @@ var mdns = require('../'); | ||
//stop after 60 seconds | ||
//stop after timeout | ||
setTimeout(function onTimeout() { | ||
browser.stop(); | ||
}, TIMEOUT); |
17
index.js
@@ -30,2 +30,19 @@ | ||
/* @borrows Advertisement as Advertisement */ | ||
module.exports.Advertisement = require('./lib/advertisement'); //just for convenience | ||
/** | ||
* Create a service instance | ||
* @method | ||
* @param {string|ServiceType} serviceType - The service type to register | ||
* @param {number} [port] - The port number for the service | ||
* @param {object} [options] - ... | ||
* @return {Advertisement} | ||
*/ | ||
module.exports.createAdvertisement = | ||
function advertisementCreated(serviceType, port, options) { | ||
return new module.exports.Advertisement(serviceType, port, options); | ||
}; | ||
/** @property {module:ServiceType~ServiceType} */ | ||
@@ -32,0 +49,0 @@ module.exports.ServiceType = st.ServiceType; |
@@ -96,3 +96,3 @@ | ||
function createSocket(interfaceIndex, networkInterface, address, port, callback) { | ||
function createSocket(interfaceIndex, networkInterface, address, port, cb) { | ||
var sock = dgram.createSocket('udp4'); | ||
@@ -102,3 +102,3 @@ debug('creating socket for interface %s', address); | ||
sock.bind(port, address, function (err) { | ||
callback(err, interfaceIndex, networkInterface, sock); | ||
cb(err, interfaceIndex, networkInterface, sock); | ||
}); | ||
@@ -105,0 +105,0 @@ } |
@@ -6,2 +6,16 @@ var BufferWriter = module.exports = function (size) { | ||
BufferWriter.prototype.buffer = function (v) { | ||
this.buf.writeUInt16BE(v.length, this.offset); | ||
this.offset += 2; | ||
v.copy(this.buf, this.offset); | ||
this.offset += v.length; | ||
return this; | ||
}; | ||
BufferWriter.prototype.long = function (v) { | ||
this.buf.writeInt32BE(v, this.offset); | ||
this.offset += 4; | ||
return this; | ||
}; | ||
BufferWriter.prototype.short = function (v) { | ||
@@ -8,0 +22,0 @@ this.buf.writeUInt16BE(v, this.offset); |
@@ -45,3 +45,6 @@ var debug = require('debug')('mdns:lib:decoder'); | ||
data.port = srv.port; | ||
data.host = srv.target + '.local'; | ||
data.host = srv.target; | ||
if (data.host.indexOf('.local', data.host.length - 6) === -1) { | ||
data.host += '.local'; | ||
} | ||
}); | ||
@@ -48,0 +51,0 @@ |
@@ -7,13 +7,2 @@ var debug = require('debug')('mdns:lib:dnspacket'); | ||
/** | ||
* This callback is used for "each" methods | ||
* @callback DNSPacket~eachCallback | ||
* @param {DNSRecord} rec - DNSRecord that was found | ||
*/ | ||
var FLAG_RESPONSE = 0x8000; | ||
var FLAG_AUTHORATIVE = 0x400; | ||
var FLAG_TRUNCATED = 0x200; | ||
var FLAG_RECURSION = 0x100; | ||
/** | ||
* DNSPacket holds the state of a DNS packet. It can be modified or serialized | ||
@@ -28,10 +17,26 @@ * in-place. | ||
debug('Response', (flags & FLAG_RESPONSE) === FLAG_RESPONSE); | ||
debug('Authorative', (flags & FLAG_AUTHORATIVE) === FLAG_AUTHORATIVE); | ||
debug('Truncated', (flags & FLAG_TRUNCATED) === FLAG_TRUNCATED); | ||
debug('Recursion', (flags & FLAG_RECURSION) === FLAG_RECURSION); | ||
debug('Response', | ||
(flags & DNSPacket.Flag.RESPONSE) === DNSPacket.Flag.RESPONSE); | ||
debug('Authorative', | ||
(flags & DNSPacket.Flag.AUTHORATIVE) === DNSPacket.Flag.AUTHORATIVE); | ||
debug('Truncated', | ||
(flags & DNSPacket.Flag.TRUNCATED) === DNSPacket.Flag.TRUNCATED); | ||
debug('Recursion', | ||
(flags & DNSPacket.Flag.RECURSION) === DNSPacket.Flag.RECURSION); | ||
}; | ||
/** | ||
* Enum identifying DNSPacket flags | ||
* @readonly | ||
* @enum {number} | ||
*/ | ||
DNSPacket.Flag = { | ||
RESPONSE: 0x8000, | ||
AUTHORATIVE: 0x400, | ||
TRUNCATED: 0x200, | ||
RECURSION: 0x100, | ||
}; | ||
/** | ||
@@ -146,7 +151,12 @@ * Enum identifying DNSPacket sections | ||
s.forEach(function (section) { | ||
debug('filling section: %s', section); | ||
this.data_[section].forEach(function (rec) { | ||
debug('filling record: %s', rec.name); | ||
out.name(rec.name).short(rec.type).short(rec.cl); | ||
if (rec.isQD && section !== 'qd') { | ||
throw new Error('unexpected QD record in non QD section.'); | ||
} | ||
if (section !== 'qd') { | ||
throw new Error('can\'t yet serialize non-QD records'); | ||
out.long(rec.ttl).buffer(rec.data_); | ||
} | ||
@@ -153,0 +163,0 @@ }); |
@@ -0,2 +1,5 @@ | ||
var debug = require('debug')('mdns:lib:dnsrecord'); | ||
var DataConsumer = require('./bufferconsumer'); | ||
var BufferWriter = require('./bufferwriter'); | ||
/** | ||
@@ -22,2 +25,4 @@ * DNSRecord is a record inside a DNS packet; e.g. a QUESTION, or an ANSWER, | ||
this.data_ = optData; | ||
debug('create non-QD record: %s, ttl: %d, data.len: %d', | ||
name, optTTL, optData.length); | ||
} | ||
@@ -39,3 +44,12 @@ }; | ||
DNSRecord.TTL = 60 * 60; // one hour default TTL | ||
DNSRecord.toName = function (name) { | ||
var out = new BufferWriter(); | ||
out.name(name); | ||
return out.buf.slice(0, out.offset); | ||
}; | ||
DNSRecord.prototype.asName = function () { | ||
@@ -46,2 +60,9 @@ return new DataConsumer(this.data_).name(); | ||
DNSRecord.toSrv = function (priority, weigth, port, target) { | ||
var out = new BufferWriter(); | ||
out.short(priority).short(weigth).short(port).name(target); | ||
return out.buf.slice(0, out.offset); | ||
}; | ||
DNSRecord.prototype.asSrv = function () { | ||
@@ -58,2 +79,11 @@ var consumer = new DataConsumer(this.data_); | ||
DNSRecord.toTxt = function (text) { | ||
var out = new BufferWriter(); | ||
for (var key in text) { | ||
out.name(key + '=' + text[key]); | ||
} | ||
return out.buf.slice(0, out.offset); | ||
}; | ||
DNSRecord.prototype.asTxt = function () { | ||
@@ -60,0 +90,0 @@ var consumer = new DataConsumer(this.data_); |
{ | ||
"name": "mdns-js", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -28,3 +28,3 @@ mDNS-js | ||
```javascript | ||
var Mdns = require('mdns-js'); | ||
var mdns = require('mdns-js'); | ||
@@ -34,3 +34,3 @@ var browser = new mdns.createBrowser(); | ||
browser.on('ready', function () { | ||
mdns.discover(); | ||
browser.discover(); | ||
}); | ||
@@ -94,2 +94,3 @@ | ||
* James Sigurðarson, @jamiees2 | ||
* James Sigurðarson, @jamiees2 | ||
* Stefan Sauer, @ensonic |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58802
21
1281
94
2