Comparing version 0.0.2 to 0.0.3
var debug = require('debug')('mdns:lib:dns'); | ||
var BufferWriter = require('./bufferwriter'); | ||
//var DataConsumer = require('./dataconsumer'); | ||
var DataConsumer = require('./bufferconsumer'); | ||
@@ -19,3 +18,3 @@ var DNSRecord = require('./dnsrecord'); | ||
/** | ||
* Parse a DNSPacket from an ArrayBuffer (or Uint8Array). | ||
* Parse a DNSPacket from an Buffer | ||
*/ | ||
@@ -105,5 +104,3 @@ DNSPacket.parse = function(buffer) { | ||
if (section != 'qd') { | ||
// TODO: implement .bytes() | ||
throw new Error('can\'t yet serialize non-QD records'); | ||
// out.long(rec.ttl).bytes(rec.data_); | ||
} | ||
@@ -110,0 +107,0 @@ }); |
@@ -30,3 +30,3 @@ var debug = require('debug')('mdns:mdns'); | ||
var sockets = []; | ||
var connections = []; | ||
var created = 0; | ||
@@ -68,5 +68,9 @@ process.nextTick(function () { | ||
var info = sock.address(); | ||
sockets.push(sock); | ||
var connection = {socket:sock, hasTraffic: false}; | ||
connections.push(connection); | ||
//sock.on('listening', this._onListening.bind(this)); | ||
sock.on('message', this._onMessage.bind(this)); | ||
sock.on('message', function () { | ||
connection.hasTraffic = true; | ||
}); | ||
sock.on('error', this._onError.bind(this)); | ||
@@ -82,4 +86,4 @@ sock.on('close', function () { | ||
if(created == sockets.length) { | ||
this.emit('ready', sockets.length); | ||
if(created == connections.length) { | ||
this.emit('ready', connections.length); | ||
} | ||
@@ -90,9 +94,27 @@ } | ||
debug('shutting down'); | ||
for(var i=0; i < sockets.length; i++) { | ||
var socket = sockets[i]; | ||
for(var i=0; i < connections.length; i++) { | ||
var socket = connections[i].socket; | ||
socket.close(); | ||
socket.unref(); | ||
} | ||
sockets = []; | ||
connections = []; | ||
}; | ||
this.closeUnused = function () { | ||
debug('closing sockets without traffic'); | ||
var closed = []; | ||
for(var i=0; i < connections.length; i++) { | ||
var connection = connections[i]; | ||
if (!connection.hasTraffic) { | ||
connection.socket.close(); | ||
connection.socket.unref(); | ||
closed.push(connection); | ||
} | ||
} | ||
for(var i=0; i<closed.length; i++) { | ||
var index = connections.indexOf(closed[i]); | ||
connections.splice(index, 1); | ||
} | ||
closed = []; | ||
}; | ||
};//--Mdns constructor | ||
@@ -99,0 +121,0 @@ |
{ | ||
"name": "mdns-js", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -6,3 +6,4 @@ mDNS-js | ||
A lot of the functionality is copied from https://github.com/GoogleChrome/chrome-app-samples/tree/master/mdns-browser | ||
A lot of the functionality is copied from | ||
https://github.com/GoogleChrome/chrome-app-samples/tree/master/mdns-browser | ||
but adapted for node. | ||
@@ -31,2 +32,14 @@ | ||
}); | ||
``` | ||
``` | ||
Debugging | ||
--------- | ||
This library is using the [debug](https://github.com/visionmedia/debug) module from TJ Holowaychuk and can be used like this. | ||
```bash | ||
DEBUG=mdns* node examples/simple.js | ||
``` | ||
This will spit out a lot of information that might be useful. |
@@ -24,7 +24,4 @@ /*global describe: true, it: true, before: true, after: true */ | ||
it('should automatically create new Mdns', function () { | ||
}); | ||
it('shoud .discover()', function (done) { | ||
it('should .discover()', function (done) { | ||
mdns.once('update', function () { | ||
@@ -44,2 +41,8 @@ mdns._byService.should.have.property('_workstation._tcp'); | ||
}); | ||
it('should close unused', function (done) { | ||
mdns.closeUnused(); | ||
setTimeout(done, 500); | ||
}); | ||
}); |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
30633
479
43
2