Revert "Use integrated URL instead of split-host"

This reverts commit dc54c50c39.
This commit is contained in:
Tony Stipanic 2021-09-01 00:01:32 +02:00
parent 5ffb65861a
commit 64596f863d
No known key found for this signature in database
GPG Key ID: 3026BCCB6C9CC6BD
3 changed files with 12 additions and 5 deletions

5
package-lock.json generated
View File

@ -15497,6 +15497,11 @@
"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

@ -73,6 +73,7 @@
"sequelize": "6.6.2",
"sequelize-typescript": "^2.1.0",
"sharp": "^0.29.0",
"split-host": "^0.1.1",
"spotify-uri": "^2.2.0",
"sqlite3": "^5.0.2",
"telegraf": "^4.4.1",
@ -142,4 +143,4 @@
"webpack-cli": "^4.8.0",
"webpack-dev-server": "^4.0.0"
}
}
}

View File

@ -3,6 +3,7 @@ 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";
@ -36,12 +37,12 @@ export async function getFederationConnInfo(serverName: string): Promise<IFedera
// Dev note: The remainder of this is largely transcribed from matrix-media-repo
const hp = new URL(serverName);
const hp = splitHost(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
@ -68,7 +69,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 = new URL(wkServerAddr);
const wkHp = splitHost(wkServerAddr);
if (!wkHp.host) {
// noinspection ExceptionCaughtLocallyJS
throw new Error("No hostname provided for m.server");
@ -76,7 +77,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)