Don't send federation queries to ourselves.

Signed-off-by: Alex Chen <minecnly@gmail.com>
This commit is contained in:
Cnly 2019-08-24 02:17:34 +08:00
parent a930c0d0b1
commit ee86685e0b

View file

@ -71,6 +71,8 @@ func DirectoryRoom(
if res.RoomID == "" {
// If we don't know it locally, do a federation query.
// 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) {
@ -82,7 +84,11 @@ func DirectoryRoom(
return httputil.LogThenError(req, fedErr)
}
}
if fedRes.RoomID == "" {
res.RoomID = fedRes.RoomID
res.fillServers(fedRes.Servers)
}
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