Skip to content

Commit

Permalink
fix #84
Browse files Browse the repository at this point in the history
  • Loading branch information
lsongdev committed Dec 23, 2024
1 parent 67e7889 commit 059cc68
Show file tree
Hide file tree
Showing 7 changed files with 2,296 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x]
node-version: [22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

yarn.lock
package-lock.json

node_modules
4 changes: 2 additions & 2 deletions client/udp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const { debuglog } = require('util');
const debug = debuglog('dns2');

module.exports = ({ dns = '8.8.8.8', port = 53, socketType = 'udp4' } = {}) => {
return (name, type = 'A', cls = Packet.CLASS.IN, { clientIp, recursive = true } = {}) => {
return (name, type = 'A', cls = Packet.CLASS.IN, options = {}) => {
const { clientIp, recursive = true } = options;
const query = new Packet();
query.header.id = (Math.random() * 1e4) | 0;

// see https://github.com/song940/node-dns/issues/29
if (recursive) {
query.header.rd = 1;
Expand Down
22 changes: 7 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,19 @@ class DNS extends EventEmitter {
}, options);
}

/**
* query
* @param {*} questions
*/
query(name, type, cls, clientIp) {
const { port, nameServers, recursive, resolverProtocol = 'UDP' } = this;
const createResolver = DNS[resolverProtocol + 'Client'];
return Promise.race(nameServers.map(address => {
const resolve = createResolver({ dns: address, port, recursive });
return resolve(name, type, cls, clientIp);
}));
}

/**
* resolve
* @param {*} domain
* @param {*} type
* @param {*} cls
*/
resolve(domain, type = 'ANY', cls = DNS.Packet.CLASS.IN, clientIp = undefined) {
return this.query(domain, type, cls, clientIp);
resolve(domain, type = 'ANY', cls = DNS.Packet.CLASS.IN, options = {}) {
const { port, nameServers, resolverProtocol = 'UDP' } = this;
const createResolver = DNS[resolverProtocol + 'Client'];
return Promise.race(nameServers.map(address => {
const resolve = createResolver({ dns: address, port });
return resolve(domain, type, cls, options);
}));
}

resolveA(domain, clientIp) {
Expand Down
Loading

0 comments on commit 059cc68

Please sign in to comment.