refactor: update GMSL (#3058)

Sister PR to https://github.com/matrix-org/gomatrixserverlib/pull/364

Read this commit by commit to avoid going insane.
This commit is contained in:
kegsay 2023-04-19 15:50:33 +01:00 committed by GitHub
parent 9fa39263c0
commit 72285b2659
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
306 changed files with 2117 additions and 1934 deletions

View file

@ -22,6 +22,7 @@ import (
"github.com/matrix-org/dendrite/relayapi/storage"
rsAPI "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/spec"
)
type RelayInternalAPI struct {
@ -31,7 +32,7 @@ type RelayInternalAPI struct {
keyRing *gomatrixserverlib.KeyRing
producer *producers.SyncAPIProducer
presenceEnabledInbound bool
serverName gomatrixserverlib.ServerName
serverName spec.ServerName
relayingEnabledMutex sync.Mutex
relayingEnabled bool
}
@ -43,7 +44,7 @@ func NewRelayInternalAPI(
keyRing *gomatrixserverlib.KeyRing,
producer *producers.SyncAPIProducer,
presenceEnabledInbound bool,
serverName gomatrixserverlib.ServerName,
serverName spec.ServerName,
relayingEnabled bool,
) *RelayInternalAPI {
return &RelayInternalAPI{

View file

@ -22,6 +22,7 @@ import (
"github.com/matrix-org/dendrite/relayapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/gomatrixserverlib/spec"
"github.com/sirupsen/logrus"
)
@ -42,8 +43,8 @@ func (r *RelayInternalAPI) RelayingEnabled() bool {
// PerformRelayServerSync implements api.RelayInternalAPI
func (r *RelayInternalAPI) PerformRelayServerSync(
ctx context.Context,
userID gomatrixserverlib.UserID,
relayServer gomatrixserverlib.ServerName,
userID spec.UserID,
relayServer spec.ServerName,
) error {
// Providing a default RelayEntry (EntryID = 0) is done to ask the relay if there are any
// transactions available for this node.
@ -75,7 +76,7 @@ func (r *RelayInternalAPI) PerformRelayServerSync(
func (r *RelayInternalAPI) PerformStoreTransaction(
ctx context.Context,
transaction gomatrixserverlib.Transaction,
userID gomatrixserverlib.UserID,
userID spec.UserID,
) error {
logrus.Warnf("Storing transaction for %v", userID)
receipt, err := r.db.StoreTransaction(ctx, transaction)
@ -85,7 +86,7 @@ func (r *RelayInternalAPI) PerformStoreTransaction(
}
err = r.db.AssociateTransactionWithDestinations(
ctx,
map[gomatrixserverlib.UserID]struct{}{
map[spec.UserID]struct{}{
userID: {},
},
transaction.TransactionID,
@ -97,7 +98,7 @@ func (r *RelayInternalAPI) PerformStoreTransaction(
// QueryTransactions implements api.RelayInternalAPI
func (r *RelayInternalAPI) QueryTransactions(
ctx context.Context,
userID gomatrixserverlib.UserID,
userID spec.UserID,
previousEntry fclient.RelayEntry,
) (api.QueryRelayTransactionsResponse, error) {
logrus.Infof("QueryTransactions for %s", userID.Raw())

View file

@ -25,6 +25,7 @@ import (
"github.com/matrix-org/dendrite/test"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/gomatrixserverlib/spec"
"github.com/stretchr/testify/assert"
)
@ -37,9 +38,9 @@ type testFedClient struct {
func (f *testFedClient) P2PGetTransactionFromRelay(
ctx context.Context,
u gomatrixserverlib.UserID,
u spec.UserID,
prev fclient.RelayEntry,
relayServer gomatrixserverlib.ServerName,
relayServer spec.ServerName,
) (res fclient.RespGetRelayTransaction, err error) {
f.queryCount++
if f.shouldFail {
@ -68,7 +69,7 @@ func TestPerformRelayServerSync(t *testing.T) {
RelayQueueJSON: testDB,
}
userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
userID, err := spec.NewUserID("@local:domain", false)
assert.Nil(t, err, "Invalid userID")
fedClient := &testFedClient{}
@ -76,7 +77,7 @@ func TestPerformRelayServerSync(t *testing.T) {
&db, fedClient, nil, nil, nil, false, "", true,
)
err = relayAPI.PerformRelayServerSync(context.Background(), *userID, gomatrixserverlib.ServerName("relay"))
err = relayAPI.PerformRelayServerSync(context.Background(), *userID, spec.ServerName("relay"))
assert.NoError(t, err)
}
@ -88,7 +89,7 @@ func TestPerformRelayServerSyncFedError(t *testing.T) {
RelayQueueJSON: testDB,
}
userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
userID, err := spec.NewUserID("@local:domain", false)
assert.Nil(t, err, "Invalid userID")
fedClient := &testFedClient{shouldFail: true}
@ -96,7 +97,7 @@ func TestPerformRelayServerSyncFedError(t *testing.T) {
&db, fedClient, nil, nil, nil, false, "", true,
)
err = relayAPI.PerformRelayServerSync(context.Background(), *userID, gomatrixserverlib.ServerName("relay"))
err = relayAPI.PerformRelayServerSync(context.Background(), *userID, spec.ServerName("relay"))
assert.Error(t, err)
}
@ -108,7 +109,7 @@ func TestPerformRelayServerSyncRunsUntilQueueEmpty(t *testing.T) {
RelayQueueJSON: testDB,
}
userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
userID, err := spec.NewUserID("@local:domain", false)
assert.Nil(t, err, "Invalid userID")
fedClient := &testFedClient{queueDepth: 2}
@ -116,7 +117,7 @@ func TestPerformRelayServerSyncRunsUntilQueueEmpty(t *testing.T) {
&db, fedClient, nil, nil, nil, false, "", true,
)
err = relayAPI.PerformRelayServerSync(context.Background(), *userID, gomatrixserverlib.ServerName("relay"))
err = relayAPI.PerformRelayServerSync(context.Background(), *userID, spec.ServerName("relay"))
assert.NoError(t, err)
assert.Equal(t, uint(3), fedClient.queryCount)
}