mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
refactor: use latest GMSL which splits fed client from matrix room logic (#3051)
Part of a series of refactors on GMSL.
This commit is contained in:
parent
e093005bc2
commit
0db43f13a6
86 changed files with 493 additions and 414 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
)
|
||||
|
||||
// Functions here are "proxying" calls to the gomatrixserverlib federation
|
||||
|
@ -13,56 +14,56 @@ import (
|
|||
func (a *FederationInternalAPI) GetEventAuth(
|
||||
ctx context.Context, origin, s gomatrixserverlib.ServerName,
|
||||
roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string,
|
||||
) (res gomatrixserverlib.RespEventAuth, err error) {
|
||||
) (res fclient.RespEventAuth, err error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||
defer cancel()
|
||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||
return a.federation.GetEventAuth(ctx, origin, s, roomVersion, roomID, eventID)
|
||||
})
|
||||
if err != nil {
|
||||
return gomatrixserverlib.RespEventAuth{}, err
|
||||
return fclient.RespEventAuth{}, err
|
||||
}
|
||||
return ires.(gomatrixserverlib.RespEventAuth), nil
|
||||
return ires.(fclient.RespEventAuth), nil
|
||||
}
|
||||
|
||||
func (a *FederationInternalAPI) GetUserDevices(
|
||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, userID string,
|
||||
) (gomatrixserverlib.RespUserDevices, error) {
|
||||
) (fclient.RespUserDevices, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||
defer cancel()
|
||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||
return a.federation.GetUserDevices(ctx, origin, s, userID)
|
||||
})
|
||||
if err != nil {
|
||||
return gomatrixserverlib.RespUserDevices{}, err
|
||||
return fclient.RespUserDevices{}, err
|
||||
}
|
||||
return ires.(gomatrixserverlib.RespUserDevices), nil
|
||||
return ires.(fclient.RespUserDevices), nil
|
||||
}
|
||||
|
||||
func (a *FederationInternalAPI) ClaimKeys(
|
||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string,
|
||||
) (gomatrixserverlib.RespClaimKeys, error) {
|
||||
) (fclient.RespClaimKeys, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||
defer cancel()
|
||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||
return a.federation.ClaimKeys(ctx, origin, s, oneTimeKeys)
|
||||
})
|
||||
if err != nil {
|
||||
return gomatrixserverlib.RespClaimKeys{}, err
|
||||
return fclient.RespClaimKeys{}, err
|
||||
}
|
||||
return ires.(gomatrixserverlib.RespClaimKeys), nil
|
||||
return ires.(fclient.RespClaimKeys), nil
|
||||
}
|
||||
|
||||
func (a *FederationInternalAPI) QueryKeys(
|
||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string,
|
||||
) (gomatrixserverlib.RespQueryKeys, error) {
|
||||
) (fclient.RespQueryKeys, error) {
|
||||
ires, err := a.doRequestIfNotBackingOffOrBlacklisted(s, func() (interface{}, error) {
|
||||
return a.federation.QueryKeys(ctx, origin, s, keys)
|
||||
})
|
||||
if err != nil {
|
||||
return gomatrixserverlib.RespQueryKeys{}, err
|
||||
return fclient.RespQueryKeys{}, err
|
||||
}
|
||||
return ires.(gomatrixserverlib.RespQueryKeys), nil
|
||||
return ires.(fclient.RespQueryKeys), nil
|
||||
}
|
||||
|
||||
func (a *FederationInternalAPI) Backfill(
|
||||
|
@ -81,45 +82,46 @@ func (a *FederationInternalAPI) Backfill(
|
|||
|
||||
func (a *FederationInternalAPI) LookupState(
|
||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, eventID string, roomVersion gomatrixserverlib.RoomVersion,
|
||||
) (res gomatrixserverlib.RespState, err error) {
|
||||
) (res gomatrixserverlib.StateResponse, err error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||
defer cancel()
|
||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||
return a.federation.LookupState(ctx, origin, s, roomID, eventID, roomVersion)
|
||||
})
|
||||
if err != nil {
|
||||
return gomatrixserverlib.RespState{}, err
|
||||
return &fclient.RespState{}, err
|
||||
}
|
||||
return ires.(gomatrixserverlib.RespState), nil
|
||||
r := ires.(fclient.RespState)
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (a *FederationInternalAPI) LookupStateIDs(
|
||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, eventID string,
|
||||
) (res gomatrixserverlib.RespStateIDs, err error) {
|
||||
) (res gomatrixserverlib.StateIDResponse, err error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||
defer cancel()
|
||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||
return a.federation.LookupStateIDs(ctx, origin, s, roomID, eventID)
|
||||
})
|
||||
if err != nil {
|
||||
return gomatrixserverlib.RespStateIDs{}, err
|
||||
return fclient.RespStateIDs{}, err
|
||||
}
|
||||
return ires.(gomatrixserverlib.RespStateIDs), nil
|
||||
return ires.(fclient.RespStateIDs), nil
|
||||
}
|
||||
|
||||
func (a *FederationInternalAPI) LookupMissingEvents(
|
||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string,
|
||||
missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion,
|
||||
) (res gomatrixserverlib.RespMissingEvents, err error) {
|
||||
missing fclient.MissingEvents, roomVersion gomatrixserverlib.RoomVersion,
|
||||
) (res fclient.RespMissingEvents, err error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||
defer cancel()
|
||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||
return a.federation.LookupMissingEvents(ctx, origin, s, roomID, missing, roomVersion)
|
||||
})
|
||||
if err != nil {
|
||||
return gomatrixserverlib.RespMissingEvents{}, err
|
||||
return fclient.RespMissingEvents{}, err
|
||||
}
|
||||
return ires.(gomatrixserverlib.RespMissingEvents), nil
|
||||
return ires.(fclient.RespMissingEvents), nil
|
||||
}
|
||||
|
||||
func (a *FederationInternalAPI) GetEvent(
|
||||
|
@ -151,9 +153,9 @@ func (a *FederationInternalAPI) LookupServerKeys(
|
|||
}
|
||||
|
||||
func (a *FederationInternalAPI) MSC2836EventRelationships(
|
||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, r gomatrixserverlib.MSC2836EventRelationshipsRequest,
|
||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, r fclient.MSC2836EventRelationshipsRequest,
|
||||
roomVersion gomatrixserverlib.RoomVersion,
|
||||
) (res gomatrixserverlib.MSC2836EventRelationshipsResponse, err error) {
|
||||
) (res fclient.MSC2836EventRelationshipsResponse, err error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||
defer cancel()
|
||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||
|
@ -162,12 +164,12 @@ func (a *FederationInternalAPI) MSC2836EventRelationships(
|
|||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return ires.(gomatrixserverlib.MSC2836EventRelationshipsResponse), nil
|
||||
return ires.(fclient.MSC2836EventRelationshipsResponse), nil
|
||||
}
|
||||
|
||||
func (a *FederationInternalAPI) MSC2946Spaces(
|
||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, suggestedOnly bool,
|
||||
) (res gomatrixserverlib.MSC2946SpacesResponse, err error) {
|
||||
) (res fclient.MSC2946SpacesResponse, err error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||
defer cancel()
|
||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||
|
@ -176,5 +178,5 @@ func (a *FederationInternalAPI) MSC2946Spaces(
|
|||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return ires.(gomatrixserverlib.MSC2946SpacesResponse), nil
|
||||
return ires.(fclient.MSC2946SpacesResponse), nil
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/setup/process"
|
||||
"github.com/matrix-org/dendrite/test"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -33,20 +34,20 @@ const (
|
|||
FailuresUntilBlacklist = 8
|
||||
)
|
||||
|
||||
func (t *testFedClient) QueryKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string) (gomatrixserverlib.RespQueryKeys, error) {
|
||||
func (t *testFedClient) QueryKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string) (fclient.RespQueryKeys, error) {
|
||||
t.queryKeysCalled = true
|
||||
if t.shouldFail {
|
||||
return gomatrixserverlib.RespQueryKeys{}, fmt.Errorf("Failure")
|
||||
return fclient.RespQueryKeys{}, fmt.Errorf("Failure")
|
||||
}
|
||||
return gomatrixserverlib.RespQueryKeys{}, nil
|
||||
return fclient.RespQueryKeys{}, nil
|
||||
}
|
||||
|
||||
func (t *testFedClient) ClaimKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string) (gomatrixserverlib.RespClaimKeys, error) {
|
||||
func (t *testFedClient) ClaimKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string) (fclient.RespClaimKeys, error) {
|
||||
t.claimKeysCalled = true
|
||||
if t.shouldFail {
|
||||
return gomatrixserverlib.RespClaimKeys{}, fmt.Errorf("Failure")
|
||||
return fclient.RespClaimKeys{}, fmt.Errorf("Failure")
|
||||
}
|
||||
return gomatrixserverlib.RespClaimKeys{}, nil
|
||||
return fclient.RespClaimKeys{}, nil
|
||||
}
|
||||
|
||||
func TestFederationClientQueryKeys(t *testing.T) {
|
||||
|
@ -54,7 +55,7 @@ func TestFederationClientQueryKeys(t *testing.T) {
|
|||
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "server",
|
||||
},
|
||||
},
|
||||
|
@ -85,7 +86,7 @@ func TestFederationClientQueryKeysBlacklisted(t *testing.T) {
|
|||
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "server",
|
||||
},
|
||||
},
|
||||
|
@ -115,7 +116,7 @@ func TestFederationClientQueryKeysFailure(t *testing.T) {
|
|||
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "server",
|
||||
},
|
||||
},
|
||||
|
@ -145,7 +146,7 @@ func TestFederationClientClaimKeys(t *testing.T) {
|
|||
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "server",
|
||||
},
|
||||
},
|
||||
|
@ -176,7 +177,7 @@ func TestFederationClientClaimKeysBlacklisted(t *testing.T) {
|
|||
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "server",
|
||||
},
|
||||
},
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/gomatrix"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/matrix-org/util"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
|
@ -255,7 +256,7 @@ func (r *FederationInternalAPI) performJoinUsingServer(
|
|||
// waste the effort.
|
||||
// TODO: Can we expand Check here to return a list of missing auth
|
||||
// events rather than failing one at a time?
|
||||
var respState *gomatrixserverlib.RespState
|
||||
var respState *fclient.RespState
|
||||
respState, err = respSendJoin.Check(
|
||||
context.Background(),
|
||||
respMakeJoin.RoomVersion,
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/setup/process"
|
||||
"github.com/matrix-org/dendrite/test"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -35,8 +36,8 @@ type testFedClient struct {
|
|||
shouldFail bool
|
||||
}
|
||||
|
||||
func (t *testFedClient) LookupRoomAlias(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomAlias string) (res gomatrixserverlib.RespDirectory, err error) {
|
||||
return gomatrixserverlib.RespDirectory{}, nil
|
||||
func (t *testFedClient) LookupRoomAlias(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomAlias string) (res fclient.RespDirectory, err error) {
|
||||
return fclient.RespDirectory{}, nil
|
||||
}
|
||||
|
||||
func TestPerformWakeupServers(t *testing.T) {
|
||||
|
@ -54,7 +55,7 @@ func TestPerformWakeupServers(t *testing.T) {
|
|||
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "relay",
|
||||
},
|
||||
},
|
||||
|
@ -96,7 +97,7 @@ func TestQueryRelayServers(t *testing.T) {
|
|||
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "relay",
|
||||
},
|
||||
},
|
||||
|
@ -133,7 +134,7 @@ func TestRemoveRelayServers(t *testing.T) {
|
|||
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "relay",
|
||||
},
|
||||
},
|
||||
|
@ -169,7 +170,7 @@ func TestPerformDirectoryLookup(t *testing.T) {
|
|||
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "relay",
|
||||
},
|
||||
},
|
||||
|
@ -204,7 +205,7 @@ func TestPerformDirectoryLookupRelaying(t *testing.T) {
|
|||
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: server,
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue