Skip to content

Commit 5db2774

Browse files
authored
Add support for MSC4040 (#492)
* Update SRV checker to support _matrix-fed._tcp.<hostname> * changelog * Lint
1 parent 1befabe commit 5db2774

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

changelog.d/492.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support MSC4040 a.ka. _matrix-fed.<hostname> SRV records in the host resolver.

src/utils/matrix-host-resolver.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ export class MatrixHostResolver {
199199
cacheFor,
200200
}
201201
}
202+
202203
// 3.3
203204
try {
204-
const [srvResult] = (await this.dns.resolveSrv(`_matrix._tcp.${hostname}`))
205+
const [srvResult] = (await this.dns.resolveSrv(`_matrix-fed._tcp.${hostname}`))
205206
.sort(MatrixHostResolver.sortSrvRecords);
206207
return {
207208
host: srvResult.name,
@@ -211,9 +212,30 @@ export class MatrixHostResolver {
211212
};
212213
}
213214
catch (ex) {
214-
log.debug(`No well-known SRV found for ${hostname}: ${ex instanceof Error ? ex.message : ex}`);
215+
log.debug(
216+
`No well-known SRV (_matrix-fed) found for ${hostname}: ${ex instanceof Error ? ex.message : ex}`
217+
);
215218
}
219+
216220
// 3.4
221+
try {
222+
// legacy
223+
const [srvResult] = (await this.dns.resolveSrv(`_matrix._tcp.${hostname}`))
224+
.sort(MatrixHostResolver.sortSrvRecords);
225+
return {
226+
host: srvResult.name,
227+
port: srvResult.port,
228+
hostname: mServer,
229+
cacheFor,
230+
};
231+
}
232+
catch (ex) {
233+
log.debug(
234+
`No well-known SRV (_matrix) found for ${hostname}: ${ex instanceof Error ? ex.message : ex}`
235+
);
236+
}
237+
238+
// 3.5
217239
return {
218240
host: wkHost.host,
219241
port: wkHost.port || DefaultMatrixServerPort,
@@ -225,6 +247,21 @@ export class MatrixHostResolver {
225247

226248
// Step 4 - SRV
227249
try {
250+
const [srvResult] = (await this.dns.resolveSrv(`_matrix-fed._tcp.${hostname}`))
251+
.sort(MatrixHostResolver.sortSrvRecords);
252+
return {
253+
host: srvResult.name,
254+
port: srvResult.port,
255+
hostname: hostname,
256+
cacheFor: DefaultCacheForMs,
257+
};
258+
}
259+
catch (ex) {
260+
log.debug(`No SRV (_matrix-fed) found for ${hostname}: ${ex instanceof Error ? ex.message : ex}`);
261+
}
262+
263+
try {
264+
// legacy
228265
const [srvResult] = (await this.dns.resolveSrv(`_matrix._tcp.${hostname}`))
229266
.sort(MatrixHostResolver.sortSrvRecords);
230267
return {
@@ -235,7 +272,7 @@ export class MatrixHostResolver {
235272
};
236273
}
237274
catch (ex) {
238-
log.debug(`No SRV found for ${hostname}: ${ex instanceof Error ? ex.message : ex}`);
275+
log.debug(`No SRV (_matrix) found for ${hostname}: ${ex instanceof Error ? ex.message : ex}`);
239276
}
240277

241278
// Step 5 - Normal resolve

0 commit comments

Comments
 (0)