Skip to content

Commit

Permalink
Add support for MSC4040 (#492)
Browse files Browse the repository at this point in the history
* Update SRV checker to support _matrix-fed._tcp.<hostname>

* changelog

* Lint
  • Loading branch information
Half-Shot authored Jan 8, 2024
1 parent 1befabe commit 5db2774
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/492.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support MSC4040 a.ka. _matrix-fed.<hostname> SRV records in the host resolver.
43 changes: 40 additions & 3 deletions src/utils/matrix-host-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -211,9 +212,30 @@ 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,
Expand All @@ -225,6 +247,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 {
Expand All @@ -235,7 +272,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
Expand Down

0 comments on commit 5db2774

Please sign in to comment.