Skip to content
Snippets Groups Projects
Commit e543d8ad authored by Randy Sommerfeld's avatar Randy Sommerfeld
Browse files

Allow IPv{4,6} only queries while retaining backwards compatibility.

parent d79ad1b8
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -587,12 +587,26 @@ DNS.prototype.synchronous_query = function(queries, callback, thisObj, recursive ...@@ -587,12 +587,26 @@ DNS.prototype.synchronous_query = function(queries, callback, thisObj, recursive
return ret; return ret;
}; };
DNS.prototype.resolve = function(host, callback, thisObj) DNS.prototype.resolveIPv4 = function(host, callback, thisObj) {
this.resolveProcess(host, callback, [{query:host, type:'A'}], thisObj);
}
DNS.prototype.resolveIPv6 = function(host, callback, thisObj) {
this.resolveProcess(host, callback, [{query:host, type:'AAAA'}], thisObj);
}
DNS.prototype.resolve = function(host, callback, thisObj) {
this.resolveProcess(host, callback, [{query:host, type:'AAAA'},{query:host, type:'A'}], thisObj);
}
DNS.prototype.resolveProcess = function(host, callback, dnstype, thisObj)
{ {
var ctx = {A:{}, AAAA:{}, unique_id:'DNS.prototype.resolve'}; var ctx = {A:{}, AAAA:{}, unique_id:'DNS.prototype.resolve'};
var final; var final;
var respA; var respA;
var respAAAA; var respAAAA;
var queries;
var queries_done;
this.sockets.forEach(function(sock) { this.sockets.forEach(function(sock) {
ctx.unique_id += '.'+sock.local_port; ctx.unique_id += '.'+sock.local_port;
...@@ -612,12 +626,16 @@ DNS.prototype.resolve = function(host, callback, thisObj) ...@@ -612,12 +626,16 @@ DNS.prototype.resolve = function(host, callback, thisObj)
ctx.final_callback = function() { ctx.final_callback = function() {
this.ret = []; this.ret = [];
this.AAAA.addrs.forEach(function(addr) { if (this.AAAA.addrs !== undefined) {
this.ret.push(addr); this.AAAA.addrs.forEach(function(addr) {
}, this); this.ret.push(addr);
this.A.addrs.forEach(function(addr) { }, this);
this.ret.push(addr); }
}, this); if (this.A.addrs !== undefined) {
this.A.addrs.forEach(function(addr) {
this.ret.push(addr);
}, this);
}
if (this.callback !== undefined) { if (this.callback !== undefined) {
js.removeEventListener(this.final); js.removeEventListener(this.final);
js.removeEventListener(this.respA); js.removeEventListener(this.respA);
...@@ -629,8 +647,8 @@ DNS.prototype.resolve = function(host, callback, thisObj) ...@@ -629,8 +647,8 @@ DNS.prototype.resolve = function(host, callback, thisObj)
ctx.final = js.addEventListener(ctx.unique_id+'.final', ctx.final_callback); ctx.final = js.addEventListener(ctx.unique_id+'.final', ctx.final_callback);
ctx.respA_callback = function() { ctx.respA_callback = function() {
this.A.done = true; this.queries_done++;
if (this.AAAA.done) { if (this.queries_done >= this.queries) {
if (this.final !== undefined) if (this.final !== undefined)
js.dispatchEvent(this.unique_id + '.final', this); js.dispatchEvent(this.unique_id + '.final', this);
else else
...@@ -641,8 +659,8 @@ DNS.prototype.resolve = function(host, callback, thisObj) ...@@ -641,8 +659,8 @@ DNS.prototype.resolve = function(host, callback, thisObj)
ctx.respA = js.addEventListener(ctx.unique_id+'.respA', ctx.respA_callback); ctx.respA = js.addEventListener(ctx.unique_id+'.respA', ctx.respA_callback);
ctx.respAAAA_callback = function() { ctx.respAAAA_callback = function() {
this.AAAA.done = true; this.queries_done++;
if (this.A.done) { if (this.queries_done >= this.queries) {
if (this.final !== undefined) if (this.final !== undefined)
js.dispatchEvent(this.unique_id + '.final', this); js.dispatchEvent(this.unique_id + '.final', this);
else else
...@@ -684,7 +702,10 @@ DNS.prototype.resolve = function(host, callback, thisObj) ...@@ -684,7 +702,10 @@ DNS.prototype.resolve = function(host, callback, thisObj)
this['resp'+rectype+'_callback'](); this['resp'+rectype+'_callback']();
} }
this.query([{query:host, type:'AAAA'},{query:host, type:'A'}], handle_response, ctx); ctx.queries = dnstype.length;
ctx.queries_done = 0;
this.query(dnstype, handle_response, ctx);
return ctx.ret; return ctx.ret;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment