Skip to content

Commit

Permalink
refactor: use latest GMSL which splits fed client from matrix room lo…
Browse files Browse the repository at this point in the history
…gic (matrix-org#3051)

Part of a series of refactors on GMSL.
  • Loading branch information
kegsay authored Apr 6, 2023
1 parent e093005 commit 0db43f1
Show file tree
Hide file tree
Showing 86 changed files with 493 additions and 414 deletions.
3 changes: 2 additions & 1 deletion clientapi/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/matrix-org/dendrite/setup/jetstream"
"github.com/matrix-org/dendrite/syncapi"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/util"
"github.com/tidwall/gjson"

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

routers := httputil.NewRouters()
Expand Down
4 changes: 2 additions & 2 deletions clientapi/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

package api

import "github.com/matrix-org/gomatrixserverlib"
import "github.com/matrix-org/gomatrixserverlib/fclient"

// ExtraPublicRoomsProvider provides a way to inject extra published rooms into /publicRooms requests.
type ExtraPublicRoomsProvider interface {
// Rooms returns the extra rooms. This is called on-demand by clients, so cache appropriately.
Rooms() []gomatrixserverlib.PublicRoom
Rooms() []fclient.PublicRoom
}
6 changes: 3 additions & 3 deletions clientapi/auth/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/userutil"
"github.com/matrix-org/dendrite/setup/config"
uapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/util"
)

Expand Down Expand Up @@ -68,7 +68,7 @@ func TestLoginFromJSONReader(t *testing.T) {
var userAPI fakeUserInternalAPI
cfg := &config.ClientAPI{
Matrix: &config.Global{
SigningIdentity: gomatrixserverlib.SigningIdentity{
SigningIdentity: fclient.SigningIdentity{
ServerName: serverName,
},
},
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestBadLoginFromJSONReader(t *testing.T) {
var userAPI fakeUserInternalAPI
cfg := &config.ClientAPI{
Matrix: &config.Global{
SigningIdentity: gomatrixserverlib.SigningIdentity{
SigningIdentity: fclient.SigningIdentity{
ServerName: serverName,
},
},
Expand Down
3 changes: 2 additions & 1 deletion clientapi/auth/user_interactive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/util"
)

Expand Down Expand Up @@ -47,7 +48,7 @@ func (d *fakeAccountDatabase) QueryAccountByPassword(ctx context.Context, req *a
func setup() *UserInteractive {
cfg := &config.ClientAPI{
Matrix: &config.Global{
SigningIdentity: gomatrixserverlib.SigningIdentity{
SigningIdentity: fclient.SigningIdentity{
ServerName: serverName,
},
},
Expand Down
4 changes: 2 additions & 2 deletions clientapi/clientapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/setup/process"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"

appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
"github.com/matrix-org/dendrite/clientapi/api"
Expand All @@ -37,7 +37,7 @@ func AddPublicRoutes(
routers httputil.Routers,
cfg *config.Dendrite,
natsInstance *jetstream.NATSInstance,
federation *gomatrixserverlib.FederationClient,
federation *fclient.FederationClient,
rsAPI roomserverAPI.ClientRoomserverAPI,
asAPI appserviceAPI.AppServiceInternalAPI,
transactionsCache *transactions.Cache,
Expand Down
3 changes: 2 additions & 1 deletion clientapi/routing/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"net/http"

"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/util"

"github.com/matrix-org/dendrite/clientapi/httputil"
Expand All @@ -45,7 +46,7 @@ func (r *roomDirectoryResponse) fillServers(servers []gomatrixserverlib.ServerNa
func DirectoryRoom(
req *http.Request,
roomAlias string,
federation *gomatrixserverlib.FederationClient,
federation *fclient.FederationClient,
cfg *config.ClientAPI,
rsAPI roomserverAPI.ClientRoomserverAPI,
fedSenderAPI federationAPI.ClientFederationAPI,
Expand Down
31 changes: 16 additions & 15 deletions clientapi/routing/directory_public.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sync"

"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/util"

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

var (
cacheMu sync.Mutex
publicRoomsCache []gomatrixserverlib.PublicRoom
publicRoomsCache []fclient.PublicRoom
)

type PublicRoomReq struct {
Expand All @@ -56,7 +57,7 @@ type filter struct {
func GetPostPublicRooms(
req *http.Request, rsAPI roomserverAPI.ClientRoomserverAPI,
extRoomsProvider api.ExtraPublicRoomsProvider,
federation *gomatrixserverlib.FederationClient,
federation *fclient.FederationClient,
cfg *config.ClientAPI,
) util.JSONResponse {
var request PublicRoomReq
Expand Down Expand Up @@ -102,10 +103,10 @@ func GetPostPublicRooms(

func publicRooms(
ctx context.Context, request PublicRoomReq, rsAPI roomserverAPI.ClientRoomserverAPI, extRoomsProvider api.ExtraPublicRoomsProvider,
) (*gomatrixserverlib.RespPublicRooms, error) {
) (*fclient.RespPublicRooms, error) {

response := gomatrixserverlib.RespPublicRooms{
Chunk: []gomatrixserverlib.PublicRoom{},
response := fclient.RespPublicRooms{
Chunk: []fclient.PublicRoom{},
}
var limit int64
var offset int64
Expand All @@ -122,7 +123,7 @@ func publicRooms(
}
err = nil

var rooms []gomatrixserverlib.PublicRoom
var rooms []fclient.PublicRoom
if request.Since == "" {
rooms = refreshPublicRoomCache(ctx, rsAPI, extRoomsProvider, request)
} else {
Expand All @@ -146,14 +147,14 @@ func publicRooms(
return &response, err
}

func filterRooms(rooms []gomatrixserverlib.PublicRoom, searchTerm string) []gomatrixserverlib.PublicRoom {
func filterRooms(rooms []fclient.PublicRoom, searchTerm string) []fclient.PublicRoom {
if searchTerm == "" {
return rooms
}

normalizedTerm := strings.ToLower(searchTerm)

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

Expand All @@ -241,10 +242,10 @@ func sliceInto(slice []gomatrixserverlib.PublicRoom, since int64, limit int64) (
func refreshPublicRoomCache(
ctx context.Context, rsAPI roomserverAPI.ClientRoomserverAPI, extRoomsProvider api.ExtraPublicRoomsProvider,
request PublicRoomReq,
) []gomatrixserverlib.PublicRoom {
) []fclient.PublicRoom {
cacheMu.Lock()
defer cacheMu.Unlock()
var extraRooms []gomatrixserverlib.PublicRoom
var extraRooms []fclient.PublicRoom
if extRoomsProvider != nil {
extraRooms = extRoomsProvider.Rooms()
}
Expand All @@ -269,7 +270,7 @@ func refreshPublicRoomCache(
util.GetLogger(ctx).WithError(err).Error("PopulatePublicRooms failed")
return publicRoomsCache
}
publicRoomsCache = []gomatrixserverlib.PublicRoom{}
publicRoomsCache = []fclient.PublicRoom{}
publicRoomsCache = append(publicRoomsCache, pubRooms...)
publicRoomsCache = append(publicRoomsCache, extraRooms...)
publicRoomsCache = dedupeAndShuffle(publicRoomsCache)
Expand All @@ -281,16 +282,16 @@ func refreshPublicRoomCache(
return publicRoomsCache
}

func getPublicRoomsFromCache() []gomatrixserverlib.PublicRoom {
func getPublicRoomsFromCache() []fclient.PublicRoom {
cacheMu.Lock()
defer cacheMu.Unlock()
return publicRoomsCache
}

func dedupeAndShuffle(in []gomatrixserverlib.PublicRoom) []gomatrixserverlib.PublicRoom {
func dedupeAndShuffle(in []fclient.PublicRoom) []fclient.PublicRoom {
// de-duplicate rooms with the same room ID. We can join the room via any of these aliases as we know these servers
// are alive and well, so we arbitrarily pick one (purposefully shuffling them to spread the load a bit)
var publicRooms []gomatrixserverlib.PublicRoom
var publicRooms []fclient.PublicRoom
haveRoomIDs := make(map[string]bool)
rand.Shuffle(len(in), func(i, j int) {
in[i], in[j] = in[j], in[i]
Expand Down
10 changes: 5 additions & 5 deletions clientapi/routing/directory_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import (
"reflect"
"testing"

"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
)

func pubRoom(name string) gomatrixserverlib.PublicRoom {
return gomatrixserverlib.PublicRoom{
func pubRoom(name string) fclient.PublicRoom {
return fclient.PublicRoom{
Name: name,
}
}

func TestSliceInto(t *testing.T) {
slice := []gomatrixserverlib.PublicRoom{
slice := []fclient.PublicRoom{
pubRoom("a"), pubRoom("b"), pubRoom("c"), pubRoom("d"), pubRoom("e"), pubRoom("f"), pubRoom("g"),
}
limit := int64(3)
testCases := []struct {
since int64
wantPrev int
wantNext int
wantSubset []gomatrixserverlib.PublicRoom
wantSubset []fclient.PublicRoom
}{
{
since: 0,
Expand Down
3 changes: 2 additions & 1 deletion clientapi/routing/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/setup/jetstream"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/util"

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

cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)
Expand Down
9 changes: 5 additions & 4 deletions clientapi/routing/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"

appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
Expand All @@ -39,7 +40,7 @@ func GetProfile(
req *http.Request, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
userID string,
asAPI appserviceAPI.AppServiceInternalAPI,
federation *gomatrixserverlib.FederationClient,
federation *fclient.FederationClient,
) util.JSONResponse {
profile, err := getProfile(req.Context(), profileAPI, cfg, userID, asAPI, federation)
if err != nil {
Expand Down Expand Up @@ -67,7 +68,7 @@ func GetProfile(
func GetAvatarURL(
req *http.Request, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
userID string, asAPI appserviceAPI.AppServiceInternalAPI,
federation *gomatrixserverlib.FederationClient,
federation *fclient.FederationClient,
) util.JSONResponse {
profile := GetProfile(req, profileAPI, cfg, userID, asAPI, federation)
p, ok := profile.JSON.(eventutil.UserProfile)
Expand Down Expand Up @@ -156,7 +157,7 @@ func SetAvatarURL(
func GetDisplayName(
req *http.Request, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
userID string, asAPI appserviceAPI.AppServiceInternalAPI,
federation *gomatrixserverlib.FederationClient,
federation *fclient.FederationClient,
) util.JSONResponse {
profile := GetProfile(req, profileAPI, cfg, userID, asAPI, federation)
p, ok := profile.JSON.(eventutil.UserProfile)
Expand Down Expand Up @@ -292,7 +293,7 @@ func getProfile(
ctx context.Context, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
userID string,
asAPI appserviceAPI.AppServiceInternalAPI,
federation *gomatrixserverlib.FederationClient,
federation *fclient.FederationClient,
) (*authtypes.Profile, error) {
localpart, domain, err := gomatrixserverlib.SplitID('@', userID)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion clientapi/routing/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/matrix-org/dendrite/setup/base"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/util"
"github.com/nats-io/nats.go"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -55,7 +56,7 @@ func Setup(
asAPI appserviceAPI.AppServiceInternalAPI,
userAPI userapi.ClientUserAPI,
userDirectoryProvider userapi.QuerySearchProfilesAPI,
federation *gomatrixserverlib.FederationClient,
federation *fclient.FederationClient,
syncProducer *producers.SyncAPIProducer,
transactionsCache *transactions.Cache,
federationSender federationAPI.ClientFederationAPI,
Expand Down
5 changes: 3 additions & 2 deletions clientapi/routing/threepid.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/userapi/api"
userdb "github.com/matrix-org/dendrite/userapi/storage"
"github.com/matrix-org/gomatrixserverlib/fclient"

"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
Expand All @@ -41,7 +42,7 @@ type ThreePIDsResponse struct {
//
// POST /account/3pid/email/requestToken
// POST /register/email/requestToken
func RequestEmailToken(req *http.Request, threePIDAPI api.ClientUserAPI, cfg *config.ClientAPI, client *gomatrixserverlib.Client) util.JSONResponse {
func RequestEmailToken(req *http.Request, threePIDAPI api.ClientUserAPI, cfg *config.ClientAPI, client *fclient.Client) util.JSONResponse {
var body threepid.EmailAssociationRequest
if reqErr := httputil.UnmarshalJSONRequest(req, &body); reqErr != nil {
return *reqErr
Expand Down Expand Up @@ -92,7 +93,7 @@ func RequestEmailToken(req *http.Request, threePIDAPI api.ClientUserAPI, cfg *co
// CheckAndSave3PIDAssociation implements POST /account/3pid
func CheckAndSave3PIDAssociation(
req *http.Request, threePIDAPI api.ClientUserAPI, device *api.Device,
cfg *config.ClientAPI, client *gomatrixserverlib.Client,
cfg *config.ClientAPI, client *fclient.Client,
) util.JSONResponse {
var body threepid.EmailAssociationCheckRequest
if reqErr := httputil.UnmarshalJSONRequest(req, &body); reqErr != nil {
Expand Down
3 changes: 2 additions & 1 deletion clientapi/routing/userdirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrix"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/util"
)

Expand All @@ -41,7 +42,7 @@ func SearchUserDirectory(
provider userapi.QuerySearchProfilesAPI,
searchString string,
limit int,
federation *gomatrixserverlib.FederationClient,
federation *fclient.FederationClient,
localServerName gomatrixserverlib.ServerName,
) util.JSONResponse {
if limit < 10 {
Expand Down
Loading

0 comments on commit 0db43f1

Please sign in to comment.