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

Support MSC4040 SRV lookups #411

Merged
merged 2 commits into from
Aug 22, 2023
Merged
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
23 changes: 22 additions & 1 deletion fclient/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
// well as 3.3 and 3.4)
func handleNoWellKnown(ctx context.Context, serverName spec.ServerName) (results []ResolutionResult) {
// 4. If the /.well-known request resulted in an error response
_, records, err := net.DefaultResolver.LookupSRV(ctx, "matrix", "tcp", string(serverName))
records, err := lookupSRV(ctx, serverName)
if err == nil && len(records) > 0 {
for _, rec := range records {
// If the domain is a FQDN, remove the trailing dot at the end. This
Expand Down Expand Up @@ -142,3 +142,24 @@

return
}

func lookupSRV(ctx context.Context, serverName spec.ServerName) ([]*net.SRV, error) {
// Check matrix-fed service first, as of Matrix 1.8
_, records, err := net.DefaultResolver.LookupSRV(ctx, "matrix-fed", "tcp", string(serverName))
if err != nil {
if dnserr, ok := err.(*net.DNSError); ok {
if !dnserr.IsNotFound {
// not found errors are expected, but everything else is very much not
return records, err
}
} else {
return records, err
}

Check warning on line 157 in fclient/resolve.go

View check run for this annotation

Codecov / codecov/patch

fclient/resolve.go#L155-L157

Added lines #L155 - L157 were not covered by tests
} else {
return records, nil // we got a hit on the matrix-fed service, so use that
}

// we didn't get a hit on matrix-fed, so try deprecated matrix service
_, records, err = net.DefaultResolver.LookupSRV(ctx, "matrix", "tcp", string(serverName))
return records, err // we don't need to process this here

Check warning on line 164 in fclient/resolve.go

View check run for this annotation

Codecov / codecov/patch

fclient/resolve.go#L163-L164

Added lines #L163 - L164 were not covered by tests
}