Skip to content

Commit 740f742

Browse files
turt2livedevonh
andauthored
1 parent e5cb0de commit 740f742

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

fclient/resolve.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func resolveServer(ctx context.Context, serverName spec.ServerName, checkWellKno
108108
// well as 3.3 and 3.4)
109109
func handleNoWellKnown(ctx context.Context, serverName spec.ServerName) (results []ResolutionResult) {
110110
// 4. If the /.well-known request resulted in an error response
111-
_, records, err := net.DefaultResolver.LookupSRV(ctx, "matrix", "tcp", string(serverName))
111+
records, err := lookupSRV(ctx, serverName)
112112
if err == nil && len(records) > 0 {
113113
for _, rec := range records {
114114
// If the domain is a FQDN, remove the trailing dot at the end. This
@@ -142,3 +142,24 @@ func handleNoWellKnown(ctx context.Context, serverName spec.ServerName) (results
142142

143143
return
144144
}
145+
146+
func lookupSRV(ctx context.Context, serverName spec.ServerName) ([]*net.SRV, error) {
147+
// Check matrix-fed service first, as of Matrix 1.8
148+
_, records, err := net.DefaultResolver.LookupSRV(ctx, "matrix-fed", "tcp", string(serverName))
149+
if err != nil {
150+
if dnserr, ok := err.(*net.DNSError); ok {
151+
if !dnserr.IsNotFound {
152+
// not found errors are expected, but everything else is very much not
153+
return records, err
154+
}
155+
} else {
156+
return records, err
157+
}
158+
} else {
159+
return records, nil // we got a hit on the matrix-fed service, so use that
160+
}
161+
162+
// we didn't get a hit on matrix-fed, so try deprecated matrix service
163+
_, records, err = net.DefaultResolver.LookupSRV(ctx, "matrix", "tcp", string(serverName))
164+
return records, err // we don't need to process this here
165+
}

0 commit comments

Comments
 (0)