Use integrated URL instead of split-host

This commit is contained in:
Tony Stipanic 2021-08-18 19:00:05 +02:00
parent d4502a5e41
commit dc54c50c39
No known key found for this signature in database
GPG Key ID: 3026BCCB6C9CC6BD
3 changed files with 4 additions and 11 deletions

5
package-lock.json generated
View File

@ -16765,11 +16765,6 @@
"integrity": "sha512-oYBGY0GV1H1dX+ZdKnB6JVsYC1w/Xl20H111eb+WSS8nUYmlHgGb4y5buFSkzzceEeYYh5kMhXoAmoTpiQauiA==",
"dev": true
},
"split-host": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/split-host/-/split-host-0.1.1.tgz",
"integrity": "sha512-nrlaPJMHkr3hKx7aCyr+S0OgUvAm/xKzWWMHej0IsMamWjRC52Fv+NGZwuqRE1lyu1iNWCmcrpZ1S1qvk+Uiwg=="
},
"split-string": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz",

View File

@ -53,7 +53,6 @@
"sequelize": "6.6.2",
"sequelize-typescript": "^2.1.0",
"sharp": "^0.28.3",
"split-host": "^0.1.1",
"spotify-uri": "^2.2.0",
"sqlite3": "^5.0.2",
"telegraf": "^3.30.1",

View File

@ -3,7 +3,6 @@ import { LogService } from "matrix-js-snippets";
import { Cache, CACHE_FEDERATION } from "../MemoryCache";
import * as request from "request";
import config from "../config";
import splitHost from 'split-host';
import * as requestPromise from "request-promise";
import { isIP } from "net";
@ -37,12 +36,12 @@ export async function getFederationConnInfo(serverName: string): Promise<IFedera
// Dev note: The remainder of this is largely transcribed from matrix-media-repo
const hp = splitHost(serverName);
const hp = new URL(serverName);
if (!hp.host) throw new Error("No hostname provided");
let defaultPort = false;
if (!hp.port) {
defaultPort = true;
hp.port = 8448;
hp.port = '8448';
}
// Step 1 of the discovery process: if the hostname is an IP, use that with explicit or default port
@ -69,7 +68,7 @@ export async function getFederationConnInfo(serverName: string): Promise<IFedera
if (typeof (result) === 'string') result = JSON.parse(result);
const wkServerAddr = result['m.server'];
if (wkServerAddr) {
const wkHp = splitHost(wkServerAddr);
const wkHp = new URL(wkServerAddr);
if (!wkHp.host) {
// noinspection ExceptionCaughtLocallyJS
throw new Error("No hostname provided for m.server");
@ -77,7 +76,7 @@ export async function getFederationConnInfo(serverName: string): Promise<IFedera
let wkDefaultPort = false;
if (!wkHp.port) {
wkDefaultPort = true;
wkHp.port = 8448;
wkHp.port = '8448';
}
// Step 3a: if the delegated host is an IP address, use that (regardless of port)