Skip to content

Commit

Permalink
split packet parsing into its own library
Browse files Browse the repository at this point in the history
  • Loading branch information
tjfontaine committed Mar 24, 2013
1 parent 8123c37 commit 313df7b
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 746 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2013-03-23 Timothy J Fontaine <[email protected]>
* Add SPF record type, same as TXT
* Emit platform ready on windows (Oleg Elifantiev)
* Split packet parsing into its own library

2013-03-03 Timothy J Fontaine <[email protected]>
* Assert missing fields
Expand Down
2 changes: 1 addition & 1 deletion dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports.resolveNs = client.resolveNs;
exports.resolveCname = client.resolveCname;
exports.reverse = client.reverse;

var consts = require('./lib/consts');
var consts = require('native-dns-packet').consts;
exports.BADNAME = consts.BADNAME;
exports.BADRESP = consts.BADRESP;
exports.CONNREFUSED = consts.CONNREFUSED;
Expand Down
2 changes: 1 addition & 1 deletion examples/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ request = dns.resolveNs('linode.com', function (err, results) {
});
});

request = dns.resolveCname('www.google.com', function (err, results) {
request = dns.resolveCname('www.nodejs.org', function (err, results) {
results.forEach(function (result) {
console.log('www.google.com -->', result);
});
Expand Down
32 changes: 26 additions & 6 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var ipaddr = require('ipaddr.js'),
EventEmitter = require('events').EventEmitter,
PendingRequests = require('./pending'),
Packet = require('./packet'),
consts = require('./consts'),
consts = require('native-dns-packet').consts,
utils = require('./utils'),
platform = require('./platform');

Expand Down Expand Up @@ -109,7 +109,7 @@ Request.prototype.handleTimeout = function() {

Request.prototype.error = function(err) {
if (!this.fired) {
debug('request error', this.id, this.question);
debug('request error', err, this.id, this.question);
this.emit('error', err);
this.done();
}
Expand Down Expand Up @@ -179,7 +179,20 @@ var Resolve = function(opts) {

this._started = false;
this._current_server = undefined;

this._server_list = [];
if (opts.remote) {
this._server_list.push({
address: opts.remote,
port: 53,
type: 'tcp',
});
this._server_list.push({
address: opts.remote,
port: 53,
type: 'udp',
});
}

this._request = undefined;
this._type = 'getHostByName';
Expand Down Expand Up @@ -258,7 +271,8 @@ Resolve.prototype._preStart = function() {
this._started = new Date().getTime();
this.try_edns = platform.edns;

this._fillServers();
if (!this._server_list.length)
this._fillServers();
}
};

Expand Down Expand Up @@ -376,23 +390,29 @@ Resolve.prototype._handleTimeout = function() {
}
};

var resolve = function(domain, rrtype, callback) {
var resolve = function(domain, rrtype, ip, callback) {
var res;

if (!callback) {
callback = ip;
ip = undefined;
}

if (!callback) {
callback = rrtype;
rrtype = undefined;
}

rrtype = consts.NAME_TO_QTYPE[rrtype || A];
rrtype = consts.NAME_TO_QTYPE[rrtype || 'A'];

if (rrtype === PTR) {
return reverse(domain, callback);
}

var opts = {
domain: domain,
rrtype: rrtype
rrtype: rrtype,
remote: ip,
};

res = new Resolve(opts);
Expand Down
167 changes: 0 additions & 167 deletions lib/consts.js

This file was deleted.

Loading

0 comments on commit 313df7b

Please sign in to comment.