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

Commit 0db43f1

Browse files
authored
refactor: use latest GMSL which splits fed client from matrix room logic (#3051)
Part of a series of refactors on GMSL.
1 parent e093005 commit 0db43f1

File tree

86 files changed

+493
-414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+493
-414
lines changed

clientapi/admin_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/matrix-org/dendrite/setup/jetstream"
2020
"github.com/matrix-org/dendrite/syncapi"
2121
"github.com/matrix-org/gomatrixserverlib"
22+
"github.com/matrix-org/gomatrixserverlib/fclient"
2223
"github.com/matrix-org/util"
2324
"github.com/tidwall/gjson"
2425

@@ -40,7 +41,7 @@ func TestAdminResetPassword(t *testing.T) {
4041
natsInstance := jetstream.NATSInstance{}
4142
// add a vhost
4243
cfg.Global.VirtualHosts = append(cfg.Global.VirtualHosts, &config.VirtualHost{
43-
SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"},
44+
SigningIdentity: fclient.SigningIdentity{ServerName: "vh1"},
4445
})
4546

4647
routers := httputil.NewRouters()

clientapi/api/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
package api
1616

17-
import "github.com/matrix-org/gomatrixserverlib"
17+
import "github.com/matrix-org/gomatrixserverlib/fclient"
1818

1919
// ExtraPublicRoomsProvider provides a way to inject extra published rooms into /publicRooms requests.
2020
type ExtraPublicRoomsProvider interface {
2121
// Rooms returns the extra rooms. This is called on-demand by clients, so cache appropriately.
22-
Rooms() []gomatrixserverlib.PublicRoom
22+
Rooms() []fclient.PublicRoom
2323
}

clientapi/auth/login_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/matrix-org/dendrite/clientapi/userutil"
2626
"github.com/matrix-org/dendrite/setup/config"
2727
uapi "github.com/matrix-org/dendrite/userapi/api"
28-
"github.com/matrix-org/gomatrixserverlib"
28+
"github.com/matrix-org/gomatrixserverlib/fclient"
2929
"github.com/matrix-org/util"
3030
)
3131

@@ -68,7 +68,7 @@ func TestLoginFromJSONReader(t *testing.T) {
6868
var userAPI fakeUserInternalAPI
6969
cfg := &config.ClientAPI{
7070
Matrix: &config.Global{
71-
SigningIdentity: gomatrixserverlib.SigningIdentity{
71+
SigningIdentity: fclient.SigningIdentity{
7272
ServerName: serverName,
7373
},
7474
},
@@ -148,7 +148,7 @@ func TestBadLoginFromJSONReader(t *testing.T) {
148148
var userAPI fakeUserInternalAPI
149149
cfg := &config.ClientAPI{
150150
Matrix: &config.Global{
151-
SigningIdentity: gomatrixserverlib.SigningIdentity{
151+
SigningIdentity: fclient.SigningIdentity{
152152
ServerName: serverName,
153153
},
154154
},

clientapi/auth/user_interactive_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/matrix-org/dendrite/setup/config"
1010
"github.com/matrix-org/dendrite/userapi/api"
1111
"github.com/matrix-org/gomatrixserverlib"
12+
"github.com/matrix-org/gomatrixserverlib/fclient"
1213
"github.com/matrix-org/util"
1314
)
1415

@@ -47,7 +48,7 @@ func (d *fakeAccountDatabase) QueryAccountByPassword(ctx context.Context, req *a
4748
func setup() *UserInteractive {
4849
cfg := &config.ClientAPI{
4950
Matrix: &config.Global{
50-
SigningIdentity: gomatrixserverlib.SigningIdentity{
51+
SigningIdentity: fclient.SigningIdentity{
5152
ServerName: serverName,
5253
},
5354
},

clientapi/clientapi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/matrix-org/dendrite/setup/config"
2020
"github.com/matrix-org/dendrite/setup/process"
2121
userapi "github.com/matrix-org/dendrite/userapi/api"
22-
"github.com/matrix-org/gomatrixserverlib"
22+
"github.com/matrix-org/gomatrixserverlib/fclient"
2323

2424
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
2525
"github.com/matrix-org/dendrite/clientapi/api"
@@ -37,7 +37,7 @@ func AddPublicRoutes(
3737
routers httputil.Routers,
3838
cfg *config.Dendrite,
3939
natsInstance *jetstream.NATSInstance,
40-
federation *gomatrixserverlib.FederationClient,
40+
federation *fclient.FederationClient,
4141
rsAPI roomserverAPI.ClientRoomserverAPI,
4242
asAPI appserviceAPI.AppServiceInternalAPI,
4343
transactionsCache *transactions.Cache,

clientapi/routing/directory.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"net/http"
2020

2121
"github.com/matrix-org/gomatrixserverlib"
22+
"github.com/matrix-org/gomatrixserverlib/fclient"
2223
"github.com/matrix-org/util"
2324

2425
"github.com/matrix-org/dendrite/clientapi/httputil"
@@ -45,7 +46,7 @@ func (r *roomDirectoryResponse) fillServers(servers []gomatrixserverlib.ServerNa
4546
func DirectoryRoom(
4647
req *http.Request,
4748
roomAlias string,
48-
federation *gomatrixserverlib.FederationClient,
49+
federation *fclient.FederationClient,
4950
cfg *config.ClientAPI,
5051
rsAPI roomserverAPI.ClientRoomserverAPI,
5152
fedSenderAPI federationAPI.ClientFederationAPI,

clientapi/routing/directory_public.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"sync"
2525

2626
"github.com/matrix-org/gomatrixserverlib"
27+
"github.com/matrix-org/gomatrixserverlib/fclient"
2728
"github.com/matrix-org/util"
2829

2930
"github.com/matrix-org/dendrite/clientapi/api"
@@ -35,7 +36,7 @@ import (
3536

3637
var (
3738
cacheMu sync.Mutex
38-
publicRoomsCache []gomatrixserverlib.PublicRoom
39+
publicRoomsCache []fclient.PublicRoom
3940
)
4041

4142
type PublicRoomReq struct {
@@ -56,7 +57,7 @@ type filter struct {
5657
func GetPostPublicRooms(
5758
req *http.Request, rsAPI roomserverAPI.ClientRoomserverAPI,
5859
extRoomsProvider api.ExtraPublicRoomsProvider,
59-
federation *gomatrixserverlib.FederationClient,
60+
federation *fclient.FederationClient,
6061
cfg *config.ClientAPI,
6162
) util.JSONResponse {
6263
var request PublicRoomReq
@@ -102,10 +103,10 @@ func GetPostPublicRooms(
102103

103104
func publicRooms(
104105
ctx context.Context, request PublicRoomReq, rsAPI roomserverAPI.ClientRoomserverAPI, extRoomsProvider api.ExtraPublicRoomsProvider,
105-
) (*gomatrixserverlib.RespPublicRooms, error) {
106+
) (*fclient.RespPublicRooms, error) {
106107

107-
response := gomatrixserverlib.RespPublicRooms{
108-
Chunk: []gomatrixserverlib.PublicRoom{},
108+
response := fclient.RespPublicRooms{
109+
Chunk: []fclient.PublicRoom{},
109110
}
110111
var limit int64
111112
var offset int64
@@ -122,7 +123,7 @@ func publicRooms(
122123
}
123124
err = nil
124125

125-
var rooms []gomatrixserverlib.PublicRoom
126+
var rooms []fclient.PublicRoom
126127
if request.Since == "" {
127128
rooms = refreshPublicRoomCache(ctx, rsAPI, extRoomsProvider, request)
128129
} else {
@@ -146,14 +147,14 @@ func publicRooms(
146147
return &response, err
147148
}
148149

149-
func filterRooms(rooms []gomatrixserverlib.PublicRoom, searchTerm string) []gomatrixserverlib.PublicRoom {
150+
func filterRooms(rooms []fclient.PublicRoom, searchTerm string) []fclient.PublicRoom {
150151
if searchTerm == "" {
151152
return rooms
152153
}
153154

154155
normalizedTerm := strings.ToLower(searchTerm)
155156

156-
result := make([]gomatrixserverlib.PublicRoom, 0)
157+
result := make([]fclient.PublicRoom, 0)
157158
for _, room := range rooms {
158159
if strings.Contains(strings.ToLower(room.Name), normalizedTerm) ||
159160
strings.Contains(strings.ToLower(room.Topic), normalizedTerm) ||
@@ -214,7 +215,7 @@ func fillPublicRoomsReq(httpReq *http.Request, request *PublicRoomReq) *util.JSO
214215
// limit=3&since=6 => G (prev='3', next='')
215216
//
216217
// A value of '-1' for prev/next indicates no position.
217-
func sliceInto(slice []gomatrixserverlib.PublicRoom, since int64, limit int64) (subset []gomatrixserverlib.PublicRoom, prev, next int) {
218+
func sliceInto(slice []fclient.PublicRoom, since int64, limit int64) (subset []fclient.PublicRoom, prev, next int) {
218219
prev = -1
219220
next = -1
220221

@@ -241,10 +242,10 @@ func sliceInto(slice []gomatrixserverlib.PublicRoom, since int64, limit int64) (
241242
func refreshPublicRoomCache(
242243
ctx context.Context, rsAPI roomserverAPI.ClientRoomserverAPI, extRoomsProvider api.ExtraPublicRoomsProvider,
243244
request PublicRoomReq,
244-
) []gomatrixserverlib.PublicRoom {
245+
) []fclient.PublicRoom {
245246
cacheMu.Lock()
246247
defer cacheMu.Unlock()
247-
var extraRooms []gomatrixserverlib.PublicRoom
248+
var extraRooms []fclient.PublicRoom
248249
if extRoomsProvider != nil {
249250
extraRooms = extRoomsProvider.Rooms()
250251
}
@@ -269,7 +270,7 @@ func refreshPublicRoomCache(
269270
util.GetLogger(ctx).WithError(err).Error("PopulatePublicRooms failed")
270271
return publicRoomsCache
271272
}
272-
publicRoomsCache = []gomatrixserverlib.PublicRoom{}
273+
publicRoomsCache = []fclient.PublicRoom{}
273274
publicRoomsCache = append(publicRoomsCache, pubRooms...)
274275
publicRoomsCache = append(publicRoomsCache, extraRooms...)
275276
publicRoomsCache = dedupeAndShuffle(publicRoomsCache)
@@ -281,16 +282,16 @@ func refreshPublicRoomCache(
281282
return publicRoomsCache
282283
}
283284

284-
func getPublicRoomsFromCache() []gomatrixserverlib.PublicRoom {
285+
func getPublicRoomsFromCache() []fclient.PublicRoom {
285286
cacheMu.Lock()
286287
defer cacheMu.Unlock()
287288
return publicRoomsCache
288289
}
289290

290-
func dedupeAndShuffle(in []gomatrixserverlib.PublicRoom) []gomatrixserverlib.PublicRoom {
291+
func dedupeAndShuffle(in []fclient.PublicRoom) []fclient.PublicRoom {
291292
// de-duplicate rooms with the same room ID. We can join the room via any of these aliases as we know these servers
292293
// are alive and well, so we arbitrarily pick one (purposefully shuffling them to spread the load a bit)
293-
var publicRooms []gomatrixserverlib.PublicRoom
294+
var publicRooms []fclient.PublicRoom
294295
haveRoomIDs := make(map[string]bool)
295296
rand.Shuffle(len(in), func(i, j int) {
296297
in[i], in[j] = in[j], in[i]

clientapi/routing/directory_public_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ import (
44
"reflect"
55
"testing"
66

7-
"github.com/matrix-org/gomatrixserverlib"
7+
"github.com/matrix-org/gomatrixserverlib/fclient"
88
)
99

10-
func pubRoom(name string) gomatrixserverlib.PublicRoom {
11-
return gomatrixserverlib.PublicRoom{
10+
func pubRoom(name string) fclient.PublicRoom {
11+
return fclient.PublicRoom{
1212
Name: name,
1313
}
1414
}
1515

1616
func TestSliceInto(t *testing.T) {
17-
slice := []gomatrixserverlib.PublicRoom{
17+
slice := []fclient.PublicRoom{
1818
pubRoom("a"), pubRoom("b"), pubRoom("c"), pubRoom("d"), pubRoom("e"), pubRoom("f"), pubRoom("g"),
1919
}
2020
limit := int64(3)
2121
testCases := []struct {
2222
since int64
2323
wantPrev int
2424
wantNext int
25-
wantSubset []gomatrixserverlib.PublicRoom
25+
wantSubset []fclient.PublicRoom
2626
}{
2727
{
2828
since: 0,

clientapi/routing/login_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/matrix-org/dendrite/setup/config"
1818
"github.com/matrix-org/dendrite/setup/jetstream"
1919
"github.com/matrix-org/gomatrixserverlib"
20+
"github.com/matrix-org/gomatrixserverlib/fclient"
2021
"github.com/matrix-org/util"
2122

2223
"github.com/matrix-org/dendrite/test"
@@ -39,7 +40,7 @@ func TestLogin(t *testing.T) {
3940
natsInstance := jetstream.NATSInstance{}
4041
// add a vhost
4142
cfg.Global.VirtualHosts = append(cfg.Global.VirtualHosts, &config.VirtualHost{
42-
SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"},
43+
SigningIdentity: fclient.SigningIdentity{ServerName: "vh1"},
4344
})
4445

4546
cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)

clientapi/routing/profile.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"time"
2121

2222
"github.com/matrix-org/gomatrixserverlib"
23+
"github.com/matrix-org/gomatrixserverlib/fclient"
2324

2425
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
2526
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
@@ -39,7 +40,7 @@ func GetProfile(
3940
req *http.Request, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
4041
userID string,
4142
asAPI appserviceAPI.AppServiceInternalAPI,
42-
federation *gomatrixserverlib.FederationClient,
43+
federation *fclient.FederationClient,
4344
) util.JSONResponse {
4445
profile, err := getProfile(req.Context(), profileAPI, cfg, userID, asAPI, federation)
4546
if err != nil {
@@ -67,7 +68,7 @@ func GetProfile(
6768
func GetAvatarURL(
6869
req *http.Request, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
6970
userID string, asAPI appserviceAPI.AppServiceInternalAPI,
70-
federation *gomatrixserverlib.FederationClient,
71+
federation *fclient.FederationClient,
7172
) util.JSONResponse {
7273
profile := GetProfile(req, profileAPI, cfg, userID, asAPI, federation)
7374
p, ok := profile.JSON.(eventutil.UserProfile)
@@ -156,7 +157,7 @@ func SetAvatarURL(
156157
func GetDisplayName(
157158
req *http.Request, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
158159
userID string, asAPI appserviceAPI.AppServiceInternalAPI,
159-
federation *gomatrixserverlib.FederationClient,
160+
federation *fclient.FederationClient,
160161
) util.JSONResponse {
161162
profile := GetProfile(req, profileAPI, cfg, userID, asAPI, federation)
162163
p, ok := profile.JSON.(eventutil.UserProfile)
@@ -292,7 +293,7 @@ func getProfile(
292293
ctx context.Context, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
293294
userID string,
294295
asAPI appserviceAPI.AppServiceInternalAPI,
295-
federation *gomatrixserverlib.FederationClient,
296+
federation *fclient.FederationClient,
296297
) (*authtypes.Profile, error) {
297298
localpart, domain, err := gomatrixserverlib.SplitID('@', userID)
298299
if err != nil {

0 commit comments

Comments
 (0)