From e04485231d1b6f5aca97d1284c0af3e6e248e1dd Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Fri, 22 Jan 2021 23:24:02 +0000 Subject: [PATCH] fix(core): update --- package-lock.json | 5 +++++ package.json | 4 +++- ts/dnsly.plugins.ts | 15 +++++++++++++-- ts/index.ts | 31 +++++++------------------------ 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index f2d5865..43cd814 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4495,6 +4495,11 @@ "dns-packet": "^5.1.2" } }, + "dns2": { + "version": "1.4.2", + "resolved": "https://verdaccio.lossless.one/dns2/-/dns2-1.4.2.tgz", + "integrity": "sha512-cRapXqyLsCW5HMBQg2pTkDnSe3KXjysWnU756epw554HJZRrqo4cD3xghCOFmZIgVzxhotiGsLGEH8QCq5cKnw==" + }, "dom-serializer": { "version": "0.2.2", "resolved": "https://verdaccio.lossless.one/dom-serializer/-/dom-serializer-0.2.2.tgz", diff --git a/package.json b/package.json index 85f58ea..fb68f20 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,11 @@ "homepage": "https://gitlab.com/pushrocks/dnsly#README", "dependencies": { "@pushrocks/smartdelay": "^2.0.10", + "@pushrocks/smartenv": "^4.0.16", "@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartrequest": "^1.1.47", - "@tsclass/tsclass": "^3.0.21" + "@tsclass/tsclass": "^3.0.21", + "dns2": "^1.4.2" }, "devDependencies": { "@gitzone/tsbuild": "^2.1.24", diff --git a/ts/dnsly.plugins.ts b/ts/dnsly.plugins.ts index e99876e..3233a8d 100644 --- a/ts/dnsly.plugins.ts +++ b/ts/dnsly.plugins.ts @@ -1,5 +1,8 @@ +import * as smartenv from '@pushrocks/smartenv'; +const smartenvInstance = new smartenv.Smartenv(); // node native scope -import * as dns from 'dns'; +import type dnsType from 'dns'; +const dns: typeof dnsType = smartenvInstance.getSafeNodeModule('dns'); export { dns }; @@ -8,8 +11,16 @@ import * as smartdelay from '@pushrocks/smartdelay'; import * as smartpromise from '@pushrocks/smartpromise'; import * as smartrequest from '@pushrocks/smartrequest'; -export { smartdelay, smartpromise, smartrequest }; +export { smartdelay, smartenv, smartpromise, smartrequest }; import * as tsclass from '@tsclass/tsclass'; export { tsclass }; + +// third party scope + +const dns2 = smartenvInstance.getSafeNodeModule('dns2'); + +export { + dns2 +} diff --git a/ts/index.ts b/ts/index.ts index 4004bfa..d732a2b 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -56,7 +56,12 @@ export class Smartdns { if (runCycles < cyclesArg) { runCycles++; try { - const myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg); + let myRecordArray: plugins.tsclass.network.IDnsRecord[]; + if (runCycles % 2 === 0 || !plugins.dns) { + myRecordArray = await this.getRecord(recordNameArg, recordTypeArg); + } else { + myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg); + } const myRecord = myRecordArray[0].value; if (myRecord === expectedValue) { console.log( @@ -68,6 +73,7 @@ export class Smartdns { return await doCheck(); } } catch (err) { + // console.log(err); await plugins.smartdelay.delayFor(intervalArg); return await doCheck(); } @@ -140,7 +146,6 @@ export class Smartdns { recordNameArg: string, recordTypeArg: plugins.tsclass.network.TDnsRecordType ): Promise { - this.setNodeDnsProvider('cloudflare'); const done = plugins.smartpromise.defer(); plugins.dns.resolve(recordNameArg, recordTypeArg, (err, recordsArg) => { if (err) { @@ -174,28 +179,6 @@ export class Smartdns { return await done.promise; } - /** - * set the DNS provider - */ - public setNodeDnsProvider(dnsProvider: TDnsProvider) { - if (!this.dnsServerIp) { - console.log( - `Warning: Setting the nodejs dns authority to ${dnsProvider}. Only do this if you know what you are doing.` - ); - } - if (dnsProvider === 'google' && this.dnsServerIp !== '8.8.8.8') { - this.dnsServerIp = '8.8.8.8'; - this.dnsServerPort = 53; - plugins.dns.setServers(['8.8.8.8', '8.8.4.4']); - } else if (dnsProvider === 'cloudflare' && this.dnsServerIp !== '1.1.1.1') { - this.dnsServerIp = '1.1.1.1'; - this.dnsServerPort = 53; - plugins.dns.setServers(['1.1.1.1', '1.0.0.1']); - } else { - throw new Error('unknown dns provider'); - } - } - public convertDnsTypeNameToTypeNumber(dnsTypeNameArg: string): number { return this.dnsTypeMap[dnsTypeNameArg]; }