Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
f2b8fa57af | |||
e5b072d99b | |||
97c57b2865 | |||
e04485231d | |||
228bc88d60 | |||
811041b036 | |||
a1203366d7 | |||
0deb77cda8 |
@ -26,16 +26,28 @@ mirror:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
audit:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm audit --audit-level=high
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
|
17809
package-lock.json
generated
17809
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdns",
|
"name": "@pushrocks/smartdns",
|
||||||
"version": "4.0.5",
|
"version": "4.0.9",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "smart dns methods written in TypeScript",
|
"description": "smart dns methods written in TypeScript",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -26,6 +26,7 @@
|
|||||||
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
|
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@pushrocks/smartdelay": "^2.0.10",
|
||||||
|
"@pushrocks/smartenv": "^4.0.16",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@pushrocks/smartrequest": "^1.1.47",
|
"@pushrocks/smartrequest": "^1.1.47",
|
||||||
"@tsclass/tsclass": "^3.0.21",
|
"@tsclass/tsclass": "^3.0.21",
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
import * as smartenv from '@pushrocks/smartenv';
|
||||||
|
const smartenvInstance = new smartenv.Smartenv();
|
||||||
// node native scope
|
// node native scope
|
||||||
import * as dns from 'dns';
|
import type dnsType from 'dns';
|
||||||
|
const dns: typeof dnsType = smartenvInstance.getSafeNodeModule('dns');
|
||||||
|
|
||||||
export { dns };
|
export { dns };
|
||||||
|
|
||||||
@ -8,15 +11,14 @@ import * as smartdelay from '@pushrocks/smartdelay';
|
|||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
|
||||||
export { smartdelay, smartpromise, smartrequest };
|
export { smartdelay, smartenv, smartpromise, smartrequest };
|
||||||
|
|
||||||
import * as tsclass from '@tsclass/tsclass';
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
export { tsclass };
|
export { tsclass };
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
import dns2 from 'dns2';
|
|
||||||
|
|
||||||
export {
|
const dns2 = smartenvInstance.getSafeNodeModule('dns2');
|
||||||
dns2
|
|
||||||
}
|
export { dns2 };
|
||||||
|
55
ts/index.ts
55
ts/index.ts
@ -2,6 +2,26 @@ import * as plugins from './dnsly.plugins';
|
|||||||
|
|
||||||
export type TDnsProvider = 'google' | 'cloudflare';
|
export type TDnsProvider = 'google' | 'cloudflare';
|
||||||
|
|
||||||
|
export const makeNodeProcessUseDnsProvider = async (providerArg: TDnsProvider) => {
|
||||||
|
switch (providerArg) {
|
||||||
|
case 'cloudflare':
|
||||||
|
plugins.dns.setServers([
|
||||||
|
'1.1.1.1',
|
||||||
|
'1.0.0.1',
|
||||||
|
'[2606:4700:4700::1111]',
|
||||||
|
'[2606:4700:4700::1001]',
|
||||||
|
]);
|
||||||
|
break;
|
||||||
|
case 'google':
|
||||||
|
plugins.dns.setServers([
|
||||||
|
'8.8.8.8',
|
||||||
|
'8.8.4.4',
|
||||||
|
'[2001:4860:4860::8888]',
|
||||||
|
'[2606:4700:4700::1001]',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export interface ISmartDnsConstructorOptions {}
|
export interface ISmartDnsConstructorOptions {}
|
||||||
|
|
||||||
export interface IGoogleDNSHTTPSResponse {
|
export interface IGoogleDNSHTTPSResponse {
|
||||||
@ -24,8 +44,6 @@ export class Smartdns {
|
|||||||
public dnsServerIp: string;
|
public dnsServerIp: string;
|
||||||
public dnsServerPort: number;
|
public dnsServerPort: number;
|
||||||
|
|
||||||
public dns2 = new plugins.dns2();
|
|
||||||
|
|
||||||
public dnsTypeMap: { [key: string]: number } = {
|
public dnsTypeMap: { [key: string]: number } = {
|
||||||
A: 1,
|
A: 1,
|
||||||
AAAA: 28,
|
AAAA: 28,
|
||||||
@ -58,7 +76,12 @@ export class Smartdns {
|
|||||||
if (runCycles < cyclesArg) {
|
if (runCycles < cyclesArg) {
|
||||||
runCycles++;
|
runCycles++;
|
||||||
try {
|
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;
|
const myRecord = myRecordArray[0].value;
|
||||||
if (myRecord === expectedValue) {
|
if (myRecord === expectedValue) {
|
||||||
console.log(
|
console.log(
|
||||||
@ -67,11 +90,10 @@ export class Smartdns {
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
await plugins.smartdelay.delayFor(intervalArg);
|
await plugins.smartdelay.delayFor(intervalArg);
|
||||||
// lets try backup strategy
|
|
||||||
const backupResult = this.dns2[`resolve${recordTypeArg}`]('google.com')
|
|
||||||
return await doCheck();
|
return await doCheck();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// console.log(err);
|
||||||
await plugins.smartdelay.delayFor(intervalArg);
|
await plugins.smartdelay.delayFor(intervalArg);
|
||||||
return await doCheck();
|
return await doCheck();
|
||||||
}
|
}
|
||||||
@ -144,7 +166,6 @@ export class Smartdns {
|
|||||||
recordNameArg: string,
|
recordNameArg: string,
|
||||||
recordTypeArg: plugins.tsclass.network.TDnsRecordType
|
recordTypeArg: plugins.tsclass.network.TDnsRecordType
|
||||||
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||||
this.setNodeDnsProvider('cloudflare');
|
|
||||||
const done = plugins.smartpromise.defer<plugins.tsclass.network.IDnsRecord[]>();
|
const done = plugins.smartpromise.defer<plugins.tsclass.network.IDnsRecord[]>();
|
||||||
plugins.dns.resolve(recordNameArg, recordTypeArg, (err, recordsArg) => {
|
plugins.dns.resolve(recordNameArg, recordTypeArg, (err, recordsArg) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -178,28 +199,6 @@ export class Smartdns {
|
|||||||
return await done.promise;
|
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 {
|
public convertDnsTypeNameToTypeNumber(dnsTypeNameArg: string): number {
|
||||||
return this.dnsTypeMap[dnsTypeNameArg];
|
return this.dnsTypeMap[dnsTypeNameArg];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user