feat: Use integrated dnsPromises

This commit is contained in:
Tony Stipanic 2021-08-18 18:49:48 +02:00
parent 4878e46c9d
commit d4502a5e41
No known key found for this signature in database
GPG key ID: 3026BCCB6C9CC6BD
4 changed files with 5 additions and 27 deletions

21
package-lock.json generated
View file

@ -7076,14 +7076,6 @@
"safe-buffer": "^5.0.1"
}
},
"dns-then": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/dns-then/-/dns-then-0.1.0.tgz",
"integrity": "sha1-xXOo7RA8p0kuBwUHy/qyexXqsfQ=",
"requires": {
"node-then": "~0.1"
}
},
"dns-txt": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/dns-txt/-/dns-txt-2.0.2.tgz",
@ -11902,14 +11894,6 @@
"integrity": "sha512-uW7fodD6pyW2FZNZnp/Z3hvWKeEW1Y8R1+1CnErE8cXFXzl5blBOoVB41CvMer6P6Q0S5FXDwcHgFd1Wj0U9zg==",
"dev": true
},
"node-then": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/node-then/-/node-then-0.1.0.tgz",
"integrity": "sha1-rxqJUSyuZwCCI48fktbLgLdflNI=",
"requires": {
"when": "~2.2"
}
},
"nopt": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz",
@ -18917,11 +18901,6 @@
"integrity": "sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==",
"dev": true
},
"when": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/when/-/when-2.2.1.tgz",
"integrity": "sha1-sd75lAFzULgIf26adZarKDO9xxI="
},
"which": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",

View file

@ -32,7 +32,6 @@
"@popperjs/core": "^2.9.2",
"body-parser": "^1.19.0",
"config": "^3.3.6",
"dns-then": "^0.1.0",
"express": "^4.17.1",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",

View file

@ -1,8 +1,8 @@
import { GET, Path, PathParam, QueryParam } from "typescript-rest";
import { LogService } from "matrix-js-snippets";
import * as url from "url";
import { promises as dnsPromises } from 'dns';
import { ApiError } from "../ApiError";
import * as dns from "dns-then";
import config from "../../config";
import { Netmask } from "netmask";
import * as request from "request";
@ -59,7 +59,7 @@ export class DimensionWidgetService {
const hostname = parsed.hostname.split(":")[0];
let addresses = [];
try {
addresses = await dns.resolve(hostname);
addresses = await dnsPromises.resolve(hostname);
} catch (err) {
LogService.error("DimensionWidgetService", err);
}

View file

@ -1,4 +1,4 @@
import * as dns from "dns-then";
import { promises as dnsPromises } from 'dns';
import { LogService } from "matrix-js-snippets";
import { Cache, CACHE_FEDERATION } from "../MemoryCache";
import * as request from "request";
@ -100,7 +100,7 @@ export async function getFederationConnInfo(serverName: string): Promise<IFedera
// Step 3c: if the delegated host is not an IP and doesn't have a port, start a SRV lookup and use that
try {
const records = await dns.resolveSrv("_matrix._tcp." + hp.host);
const records = await dnsPromises.resolveSrv("_matrix._tcp." + hp.host);
if (records && records.length > 0) {
const fedUrl = `https://${records[0].name}:${records[0].port}`;
const fedObj = {url: fedUrl, hostname: wkHp.host};
@ -127,7 +127,7 @@ export async function getFederationConnInfo(serverName: string): Promise<IFedera
// Step 4: try resolving a hostname using SRV records and use that
try {
const records = await dns.resolveSrv("_matrix._tcp." + hp.host);
const records = await dnsPromises.resolveSrv("_matrix._tcp." + hp.host);
if (records && records.length > 0) {
const fedUrl = `https://${records[0].name}:${records[0].port}`;
const fedObj = {url: fedUrl, hostname: hp.host};