Refactor PerformJoin to use the new gmsl interface

This commit is contained in:
Devon Hudson 2023-04-25 15:19:12 -06:00
parent 53787d539d
commit 2f7d4cb2d2
No known key found for this signature in database
GPG key ID: CD06B18E77F6A628
4 changed files with 35 additions and 2 deletions

View file

@ -16,6 +16,7 @@ import (
// FederationInternalAPI is used to query information from the federation sender.
type FederationInternalAPI interface {
gomatrixserverlib.FederatedStateClient
gomatrixserverlib.FederatedJoinClient
KeyserverFederationAPI
gomatrixserverlib.KeyDatabase
ClientFederationAPI

View file

@ -107,6 +107,8 @@ func (f *fedClient) GetServerKeys(ctx context.Context, matrixServer spec.ServerN
}
func (f *fedClient) MakeJoin(ctx context.Context, origin, s spec.ServerName, roomID, userID string) (res fclient.RespMakeJoin, err error) {
f.fedClientMutex.Lock()
defer f.fedClientMutex.Unlock()
for _, r := range f.allowJoins {
if r.ID == roomID {
res.RoomVersion = r.Version

View file

@ -12,6 +12,36 @@ import (
// Functions here are "proxying" calls to the gomatrixserverlib federation
// client.
func (a *FederationInternalAPI) MakeJoin(
ctx context.Context, origin, s spec.ServerName, roomID, userID string,
) (res gomatrixserverlib.MakeJoinResponse, err error) {
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
return a.federation.MakeJoin(ctx, origin, s, roomID, userID)
})
if err != nil {
return &fclient.RespMakeJoin{}, err
}
r := ires.(fclient.RespMakeJoin)
return &r, nil
}
func (a *FederationInternalAPI) SendJoin(
ctx context.Context, origin, s spec.ServerName, event *gomatrixserverlib.Event,
) (res gomatrixserverlib.SendJoinResponse, err error) {
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
return a.federation.SendJoin(ctx, origin, s, event)
})
if err != nil {
return &fclient.RespSendJoin{}, err
}
r := ires.(fclient.RespSendJoin)
return &r, nil
}
func (a *FederationInternalAPI) GetEventAuth(
ctx context.Context, origin, s spec.ServerName,
roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string,

View file

@ -150,7 +150,7 @@ func (r *FederationInternalAPI) performJoinUsingServer(
return err
}
joinInput := fclient.PerformJoinInput{
joinInput := gomatrixserverlib.PerformJoinInput{
UserID: user,
RoomID: roomID,
ServerName: serverName,
@ -161,7 +161,7 @@ func (r *FederationInternalAPI) performJoinUsingServer(
KeyRing: r.keyRing,
EventProvider: federatedEventProvider(ctx, r.federation, r.keyRing, user.Domain(), serverName),
}
response, joinErr := fclient.PerformJoin(ctx, r.federation, joinInput)
response, joinErr := gomatrixserverlib.PerformJoin(ctx, r, joinInput)
if err != nil {
if !joinErr.Reachable {