From ee86685e0bf7b1ff548fadbd45ad821a2f479d58 Mon Sep 17 00:00:00 2001 From: Cnly Date: Sat, 24 Aug 2019 02:17:34 +0800 Subject: [PATCH] Don't send federation queries to ourselves. Signed-off-by: Alex Chen --- clientapi/routing/directory.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/clientapi/routing/directory.go b/clientapi/routing/directory.go index a35f66020..ed8ee2316 100644 --- a/clientapi/routing/directory.go +++ b/clientapi/routing/directory.go @@ -71,18 +71,24 @@ func DirectoryRoom( if res.RoomID == "" { // If we don't know it locally, do a federation query. - fedRes, fedErr := federation.LookupRoomAlias(req.Context(), domain, roomAlias) - if fedErr != nil { - switch fedErr.(type) { - case gomatrix.HTTPError: - // TODO: Return 502 if the remote server errored. - // TODO: Return 504 if the remote server timed out. - return httputil.LogThenError(req, fedErr) - default: - return httputil.LogThenError(req, fedErr) + // But don't send the query to ourselves. + if domain != cfg.Matrix.ServerName { + fedRes, fedErr := federation.LookupRoomAlias(req.Context(), domain, roomAlias) + if fedErr != nil { + switch fedErr.(type) { + case gomatrix.HTTPError: + // TODO: Return 502 if the remote server errored. + // TODO: Return 504 if the remote server timed out. + return httputil.LogThenError(req, fedErr) + default: + return httputil.LogThenError(req, fedErr) + } } + res.RoomID = fedRes.RoomID + res.fillServers(fedRes.Servers) } - if fedRes.RoomID == "" { + + if res.RoomID == "" { return util.JSONResponse{ Code: http.StatusNotFound, JSON: jsonerror.NotFound( @@ -90,9 +96,6 @@ func DirectoryRoom( ), } } - - res.RoomID = fedRes.RoomID - res.fillServers(fedRes.Servers) } else { joinedHostsReq := federationSenderAPI.QueryJoinedHostServerNamesInRoomRequest{RoomID: res.RoomID} var joinedHostsRes federationSenderAPI.QueryJoinedHostServerNamesInRoomResponse