Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MSC4040 #492

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading