From 04ae20f2cd4126c284f2eabce7a5d296d5dbdce7 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Mon, 8 Jan 2024 11:05:31 +0000 Subject: [PATCH] Update SRV checker to support _matrix-fed._tcp. --- src/utils/matrix-host-resolver.ts | 39 ++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/utils/matrix-host-resolver.ts b/src/utils/matrix-host-resolver.ts index 70a53c3a..89dc8c21 100644 --- a/src/utils/matrix-host-resolver.ts +++ b/src/utils/matrix-host-resolver.ts @@ -199,9 +199,10 @@ export class MatrixHostResolver { cacheFor, } } + // 3.3 try { - const [srvResult] = (await this.dns.resolveSrv(`_matrix._tcp.${hostname}`)) + const [srvResult] = (await this.dns.resolveSrv(`_matrix-fed._tcp.${hostname}`)) .sort(MatrixHostResolver.sortSrvRecords); return { host: srvResult.name, @@ -211,9 +212,26 @@ export class MatrixHostResolver { }; } catch (ex) { - log.debug(`No well-known SRV found for ${hostname}: ${ex instanceof Error ? ex.message : ex}`); + log.debug(`No well-known SRV (_matrix-fed) found for ${hostname}: ${ex instanceof Error ? ex.message : ex}`); } + // 3.4 + try { + // legacy + const [srvResult] = (await this.dns.resolveSrv(`_matrix._tcp.${hostname}`)) + .sort(MatrixHostResolver.sortSrvRecords); + return { + host: srvResult.name, + port: srvResult.port, + hostname: mServer, + cacheFor, + }; + } + catch (ex) { + log.debug(`No well-known SRV (_matrix) found for ${hostname}: ${ex instanceof Error ? ex.message : ex}`); + } + + // 3.5 return { host: wkHost.host, port: wkHost.port || DefaultMatrixServerPort, @@ -225,6 +243,21 @@ export class MatrixHostResolver { // Step 4 - SRV try { + const [srvResult] = (await this.dns.resolveSrv(`_matrix-fed._tcp.${hostname}`)) + .sort(MatrixHostResolver.sortSrvRecords); + return { + host: srvResult.name, + port: srvResult.port, + hostname: hostname, + cacheFor: DefaultCacheForMs, + }; + } + catch (ex) { + log.debug(`No SRV (_matrix-fed) found for ${hostname}: ${ex instanceof Error ? ex.message : ex}`); + } + + try { + // legacy const [srvResult] = (await this.dns.resolveSrv(`_matrix._tcp.${hostname}`)) .sort(MatrixHostResolver.sortSrvRecords); return { @@ -235,7 +268,7 @@ export class MatrixHostResolver { }; } catch (ex) { - log.debug(`No SRV found for ${hostname}: ${ex instanceof Error ? ex.message : ex}`); + log.debug(`No SRV (_matrix) found for ${hostname}: ${ex instanceof Error ? ex.message : ex}`); } // Step 5 - Normal resolve