Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Fix appsevice alias queries part 2 #1684

Merged
merged 31 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6ca7fa8
Check membership of room
Half-Shot Jan 4, 2021
9814e71
Use QueryStateAfterEventsResponse
Half-Shot Jan 4, 2021
50ba0cc
Merge branch 'master' into hs/as-transaction-send-if-in-room
Half-Shot Jan 4, 2021
a5ba01e
Fix complexity
Half-Shot Jan 5, 2021
85c564e
Add field ShouldHitAppservice to GetRoomIDForAlias
Half-Shot Jan 5, 2021
3a66d3c
Hit appservice when trying to join a non-existent alias
Half-Shot Jan 5, 2021
b7a9da8
remove unused
Half-Shot Jan 5, 2021
600a058
Merge branch 'master' into hs/fix-appsevice-alias-queries-part-2
Half-Shot Jan 5, 2021
2fbe66d
Merge branch 'master' into hs/fix-appsevice-alias-queries-part-2
Half-Shot Feb 3, 2021
1da0a21
Changes that I made a long time ago
Half-Shot Feb 26, 2021
768bd93
Merge remote-tracking branch 'origin/master' into hs/as-transaction-s…
Half-Shot Feb 26, 2021
ea0eae2
Rename to appserviceJoinedAtEvent
Half-Shot Feb 26, 2021
5058157
Check membership in GetMemberships
Half-Shot Feb 26, 2021
7834682
Merge branch 'master' into hs/as-transaction-send-if-in-room
neilalexander Mar 3, 2021
078aa09
Update QueryMembershipsForRoom
neilalexander Mar 3, 2021
1b580b3
Tweaks in client API
neilalexander Mar 3, 2021
f241ec5
Update appserviceJoinedAtEvent
neilalexander Mar 3, 2021
1c5de02
Comments
neilalexander Mar 3, 2021
74cfc37
Try QueryMembershipForUser instead
neilalexander Mar 3, 2021
441ccf0
Undo some changes to client API that shouldn't be needed
neilalexander Mar 3, 2021
f6bac26
More /event tweaks
neilalexander Mar 3, 2021
3391e4c
Refactor /event bit
neilalexander Mar 3, 2021
e379155
Go back to QueryMembershipsForRoom because appservices are hard
neilalexander Mar 3, 2021
d0138fe
Merge branch 'master' into hs/as-transaction-send-if-in-room
neilalexander Mar 3, 2021
0157af5
Merge branch 'master' into hs/as-transaction-send-if-in-room
neilalexander Mar 3, 2021
7535f88
Merge branch 'master' into hs/fix-appsevice-alias-queries-part-2
neilalexander Mar 3, 2021
09bbedd
Fix bugs in onMessage
neilalexander Mar 3, 2021
d37f160
Add comments
neilalexander Mar 3, 2021
f1f4255
Merge branch 'hs/as-transaction-send-if-in-room' into hs/fix-appsevic…
Half-Shot Mar 3, 2021
6a880df
Merge branch 'master' into hs/fix-appsevice-alias-queries-part-2
Half-Shot Mar 3, 2021
b50694e
More logical naming, clean up a bit
neilalexander Mar 3, 2021
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
3 changes: 2 additions & 1 deletion clientapi/routing/createroom.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ func createRoom(
roomAlias = fmt.Sprintf("#%s:%s", r.RoomAliasName, cfg.Matrix.ServerName)
// check it's free TODO: This races but is better than nothing
hasAliasReq := roomserverAPI.GetRoomIDForAliasRequest{
Alias: roomAlias,
Alias: roomAlias,
IncludeAppservices: false,
}

var aliasResp roomserverAPI.GetRoomIDForAliasResponse
Expand Down
9 changes: 6 additions & 3 deletions clientapi/routing/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ func DirectoryRoom(
var res roomDirectoryResponse

// Query the roomserver API to check if the alias exists locally.
queryReq := roomserverAPI.GetRoomIDForAliasRequest{Alias: roomAlias}
var queryRes roomserverAPI.GetRoomIDForAliasResponse
if err = rsAPI.GetRoomIDForAlias(req.Context(), &queryReq, &queryRes); err != nil {
queryReq := &roomserverAPI.GetRoomIDForAliasRequest{
Alias: roomAlias,
IncludeAppservices: true,
}
queryRes := &roomserverAPI.GetRoomIDForAliasResponse{}
if err = rsAPI.GetRoomIDForAlias(req.Context(), queryReq, queryRes); err != nil {
util.GetLogger(req.Context()).WithError(err).Error("rsAPI.GetRoomIDForAlias failed")
return jsonerror.InternalServerError()
}
Expand Down
9 changes: 6 additions & 3 deletions federationapi/routing/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ func RoomAliasToID(
var resp gomatrixserverlib.RespDirectory

if domain == cfg.Matrix.ServerName {
queryReq := roomserverAPI.GetRoomIDForAliasRequest{Alias: roomAlias}
var queryRes roomserverAPI.GetRoomIDForAliasResponse
if err = rsAPI.GetRoomIDForAlias(httpReq.Context(), &queryReq, &queryRes); err != nil {
queryReq := &roomserverAPI.GetRoomIDForAliasRequest{
Alias: roomAlias,
IncludeAppservices: true,
}
queryRes := &roomserverAPI.GetRoomIDForAliasResponse{}
if err = rsAPI.GetRoomIDForAlias(httpReq.Context(), queryReq, queryRes); err != nil {
util.GetLogger(httpReq.Context()).WithError(err).Error("aliasAPI.GetRoomIDForAlias failed")
return jsonerror.InternalServerError()
}
Expand Down
3 changes: 3 additions & 0 deletions roomserver/api/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type SetRoomAliasResponse struct {
type GetRoomIDForAliasRequest struct {
// Alias we want to lookup
Alias string `json:"alias"`
// Should we ask appservices for their aliases as a part of
// the request?
IncludeAppservices bool `json:"include_appservices"`
}

// GetRoomIDForAliasResponse is a response to GetRoomIDForAlias
Expand Down
40 changes: 22 additions & 18 deletions roomserver/internal/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,35 @@ func (r *RoomserverInternalAPI) GetRoomIDForAlias(
) error {
// Look up the room ID in the database
roomID, err := r.DB.GetRoomIDForAlias(ctx, request.Alias)
if err != nil {
return err
if err == nil && roomID != "" {
response.RoomID = roomID
return nil
}

if r.asAPI != nil { // appservice component is wired in
if roomID == "" {
// No room found locally, try our application services by making a call to
// the appservice component
aliasReq := asAPI.RoomAliasExistsRequest{Alias: request.Alias}
var aliasResp asAPI.RoomAliasExistsResponse
if err = r.asAPI.RoomAliasExists(ctx, &aliasReq, &aliasResp); err != nil {
return err
}
// Check appservice on err, but only if the appservice API is
// wired in and no room ID was found.
if r.asAPI != nil && request.IncludeAppservices && roomID == "" {
// No room found locally, try our application services by making a call to
// the appservice component
aliasReq := &asAPI.RoomAliasExistsRequest{
Alias: request.Alias,
}
aliasRes := &asAPI.RoomAliasExistsResponse{}
if err = r.asAPI.RoomAliasExists(ctx, aliasReq, aliasRes); err != nil {
return err
}

if aliasResp.AliasExists {
roomID, err = r.DB.GetRoomIDForAlias(ctx, request.Alias)
if err != nil {
return err
}
if aliasRes.AliasExists {
roomID, err = r.DB.GetRoomIDForAlias(ctx, request.Alias)
if err != nil {
return err
}
response.RoomID = roomID
return nil
}
}

response.RoomID = roomID
return nil
return err
}

// GetAliasesForRoomID implements alias.RoomserverInternalAPI
Expand Down
1 change: 1 addition & 0 deletions roomserver/internal/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (r *RoomserverInternalAPI) SetFederationSenderAPI(fsAPI fsAPI.FederationSen
Cfg: r.Cfg,
DB: r.DB,
FSAPI: r.fsAPI,
RSAPI: r,
Inputer: r.Inputer,
}
r.Peeker = &perform.Peeker{
Expand Down
10 changes: 9 additions & 1 deletion roomserver/internal/perform/perform_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/internal/eventutil"
"github.com/matrix-org/dendrite/roomserver/api"
rsAPI "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/roomserver/internal/helpers"
"github.com/matrix-org/dendrite/roomserver/internal/input"
"github.com/matrix-org/dendrite/roomserver/storage"
Expand All @@ -36,6 +37,7 @@ type Joiner struct {
ServerName gomatrixserverlib.ServerName
Cfg *config.RoomServer
FSAPI fsAPI.FederationSenderInternalAPI
RSAPI rsAPI.RoomserverInternalAPI
DB storage.Database

Inputer *input.Inputer
Expand Down Expand Up @@ -121,11 +123,17 @@ func (r *Joiner) performJoinRoomByAlias(
roomID = dirRes.RoomID
req.ServerNames = append(req.ServerNames, dirRes.ServerNames...)
} else {
var getRoomReq = rsAPI.GetRoomIDForAliasRequest{
Alias: req.RoomIDOrAlias,
IncludeAppservices: true,
}
var getRoomRes = rsAPI.GetRoomIDForAliasResponse{}
// Otherwise, look up if we know this room alias locally.
roomID, err = r.DB.GetRoomIDForAlias(ctx, req.RoomIDOrAlias)
err = r.RSAPI.GetRoomIDForAlias(ctx, &getRoomReq, &getRoomRes)
if err != nil {
return "", "", fmt.Errorf("Lookup room alias %q failed: %w", req.RoomIDOrAlias, err)
}
roomID = getRoomRes.RoomID
}

// If the room ID is empty then we failed to look up the alias.
Expand Down