fix(core): update

This commit is contained in:
Philipp Kunz 2021-01-22 23:24:02 +00:00
parent 228bc88d60
commit e04485231d
4 changed files with 28 additions and 27 deletions

5
package-lock.json generated
View File

@ -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",

View File

@ -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",

View File

@ -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
}

View File

@ -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<plugins.tsclass.network.IDnsRecord[]> {
this.setNodeDnsProvider('cloudflare');
const done = plugins.smartpromise.defer<plugins.tsclass.network.IDnsRecord[]>();
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];
}