aboutsummaryrefslogtreecommitdiff
path: root/relayapi
diff options
context:
space:
mode:
authorkegsay <kegan@matrix.org>2023-04-19 15:50:33 +0100
committerGitHub <noreply@github.com>2023-04-19 15:50:33 +0100
commit72285b2659a31ebd52c91799c17105d81d996f40 (patch)
tree1855395f5efdc3ea6051dd502882bf62aaa57e7c /relayapi
parent9fa39263c0a4a8d349c8715f6ba30cae30b1b73a (diff)
refactor: update GMSL (#3058)
Sister PR to https://github.com/matrix-org/gomatrixserverlib/pull/364 Read this commit by commit to avoid going insane.
Diffstat (limited to 'relayapi')
-rw-r--r--relayapi/api/api.go9
-rw-r--r--relayapi/internal/api.go5
-rw-r--r--relayapi/internal/perform.go11
-rw-r--r--relayapi/internal/perform_test.go17
-rw-r--r--relayapi/relayapi_test.go13
-rw-r--r--relayapi/routing/relaytxn.go6
-rw-r--r--relayapi/routing/relaytxn_test.go21
-rw-r--r--relayapi/routing/routing.go18
-rw-r--r--relayapi/routing/sendrelay.go5
-rw-r--r--relayapi/routing/sendrelay_test.go26
-rw-r--r--relayapi/storage/interface.go9
-rw-r--r--relayapi/storage/postgres/relay_queue_table.go9
-rw-r--r--relayapi/storage/postgres/storage.go4
-rw-r--r--relayapi/storage/shared/storage.go11
-rw-r--r--relayapi/storage/sqlite3/relay_queue_table.go9
-rw-r--r--relayapi/storage/sqlite3/storage.go4
-rw-r--r--relayapi/storage/storage.go4
-rw-r--r--relayapi/storage/storage_wasm.go2
-rw-r--r--relayapi/storage/tables/interface.go9
-rw-r--r--relayapi/storage/tables/relay_queue_json_table_test.go3
-rw-r--r--relayapi/storage/tables/relay_queue_table_test.go15
21 files changed, 114 insertions, 96 deletions
diff --git a/relayapi/api/api.go b/relayapi/api/api.go
index f0ed8326..83ff2890 100644
--- a/relayapi/api/api.go
+++ b/relayapi/api/api.go
@@ -19,6 +19,7 @@ import (
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
// RelayInternalAPI is used to query information from the relay server.
@@ -28,8 +29,8 @@ type RelayInternalAPI interface {
// Retrieve from external relay server all transactions stored for us and process them.
PerformRelayServerSync(
ctx context.Context,
- userID gomatrixserverlib.UserID,
- relayServer gomatrixserverlib.ServerName,
+ userID spec.UserID,
+ relayServer spec.ServerName,
) error
// Tells the relayapi whether or not it should act as a relay server for external servers.
@@ -45,13 +46,13 @@ type RelayServerAPI interface {
PerformStoreTransaction(
ctx context.Context,
transaction gomatrixserverlib.Transaction,
- userID gomatrixserverlib.UserID,
+ userID spec.UserID,
) error
// Obtain the oldest stored transaction for the specified userID.
QueryTransactions(
ctx context.Context,
- userID gomatrixserverlib.UserID,
+ userID spec.UserID,
previousEntry fclient.RelayEntry,
) (QueryRelayTransactionsResponse, error)
}
diff --git a/relayapi/internal/api.go b/relayapi/internal/api.go
index 3a5762fb..55e86aef 100644
--- a/relayapi/internal/api.go
+++ b/relayapi/internal/api.go
@@ -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{
diff --git a/relayapi/internal/perform.go b/relayapi/internal/perform.go
index 66d42119..45765211 100644
--- a/relayapi/internal/perform.go
+++ b/relayapi/internal/perform.go
@@ -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())
diff --git a/relayapi/internal/perform_test.go b/relayapi/internal/perform_test.go
index 2c5e1f1f..111fb46b 100644
--- a/relayapi/internal/perform_test.go
+++ b/relayapi/internal/perform_test.go
@@ -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)
}
diff --git a/relayapi/relayapi_test.go b/relayapi/relayapi_test.go
index 27426221..9d67cdf9 100644
--- a/relayapi/relayapi_test.go
+++ b/relayapi/relayapi_test.go
@@ -33,6 +33,7 @@ import (
"github.com/matrix-org/dendrite/test/testrig"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/stretchr/testify/assert"
)
@@ -74,12 +75,12 @@ func TestCreateInvalidRelayPublicRoutesPanics(t *testing.T) {
})
}
-func createGetRelayTxnHTTPRequest(serverName gomatrixserverlib.ServerName, userID string) *http.Request {
+func createGetRelayTxnHTTPRequest(serverName spec.ServerName, userID string) *http.Request {
_, sk, _ := ed25519.GenerateKey(nil)
keyID := signing.KeyID
pk := sk.Public().(ed25519.PublicKey)
- origin := gomatrixserverlib.ServerName(hex.EncodeToString(pk))
- req := gomatrixserverlib.NewFederationRequest("GET", origin, serverName, "/_matrix/federation/v1/relay_txn/"+userID)
+ origin := spec.ServerName(hex.EncodeToString(pk))
+ req := fclient.NewFederationRequest("GET", origin, serverName, "/_matrix/federation/v1/relay_txn/"+userID)
content := fclient.RelayEntry{EntryID: 0}
req.SetContent(content)
req.Sign(origin, gomatrixserverlib.KeyID(keyID), sk)
@@ -94,12 +95,12 @@ type sendRelayContent struct {
EDUs []gomatrixserverlib.EDU `json:"edus"`
}
-func createSendRelayTxnHTTPRequest(serverName gomatrixserverlib.ServerName, txnID string, userID string) *http.Request {
+func createSendRelayTxnHTTPRequest(serverName spec.ServerName, txnID string, userID string) *http.Request {
_, sk, _ := ed25519.GenerateKey(nil)
keyID := signing.KeyID
pk := sk.Public().(ed25519.PublicKey)
- origin := gomatrixserverlib.ServerName(hex.EncodeToString(pk))
- req := gomatrixserverlib.NewFederationRequest("PUT", origin, serverName, "/_matrix/federation/v1/send_relay/"+txnID+"/"+userID)
+ origin := spec.ServerName(hex.EncodeToString(pk))
+ req := fclient.NewFederationRequest("PUT", origin, serverName, "/_matrix/federation/v1/send_relay/"+txnID+"/"+userID)
content := sendRelayContent{}
req.SetContent(content)
req.Sign(origin, gomatrixserverlib.KeyID(keyID), sk)
diff --git a/relayapi/routing/relaytxn.go b/relayapi/routing/relaytxn.go
index 06a2a07f..2fc61373 100644
--- a/relayapi/routing/relaytxn.go
+++ b/relayapi/routing/relaytxn.go
@@ -20,8 +20,8 @@ import (
"github.com/matrix-org/dendrite/clientapi/jsonerror"
"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/matrix-org/util"
"github.com/sirupsen/logrus"
)
@@ -30,9 +30,9 @@ import (
// This endpoint can be extracted into a separate relay server service.
func GetTransactionFromRelay(
httpReq *http.Request,
- fedReq *gomatrixserverlib.FederationRequest,
+ fedReq *fclient.FederationRequest,
relayAPI api.RelayInternalAPI,
- userID gomatrixserverlib.UserID,
+ userID spec.UserID,
) util.JSONResponse {
logrus.Infof("Processing relay_txn for %s", userID.Raw())
diff --git a/relayapi/routing/relaytxn_test.go b/relayapi/routing/relaytxn_test.go
index bc76ddf2..e6d2d9e5 100644
--- a/relayapi/routing/relaytxn_test.go
+++ b/relayapi/routing/relaytxn_test.go
@@ -26,16 +26,17 @@ 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"
)
func createQuery(
- userID gomatrixserverlib.UserID,
+ userID spec.UserID,
prevEntry fclient.RelayEntry,
-) gomatrixserverlib.FederationRequest {
+) fclient.FederationRequest {
var federationPathPrefixV1 = "/_matrix/federation/v1"
path := federationPathPrefixV1 + "/relay_txn/" + userID.Raw()
- request := gomatrixserverlib.NewFederationRequest("GET", userID.Domain(), "relay", path)
+ request := fclient.NewFederationRequest("GET", userID.Domain(), "relay", path)
request.SetContent(prevEntry)
return request
@@ -49,7 +50,7 @@ func TestGetEmptyDatabaseReturnsNothing(t *testing.T) {
RelayQueueJSON: testDB,
}
httpReq := &http.Request{}
- userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
+ userID, err := spec.NewUserID("@local:domain", false)
assert.NoError(t, err, "Invalid userID")
transaction := createTransaction()
@@ -82,7 +83,7 @@ func TestGetInvalidPrevEntryFails(t *testing.T) {
RelayQueueJSON: testDB,
}
httpReq := &http.Request{}
- userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
+ userID, err := spec.NewUserID("@local:domain", false)
assert.NoError(t, err, "Invalid userID")
transaction := createTransaction()
@@ -107,7 +108,7 @@ func TestGetReturnsSavedTransaction(t *testing.T) {
RelayQueueJSON: testDB,
}
httpReq := &http.Request{}
- userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
+ userID, err := spec.NewUserID("@local:domain", false)
assert.NoError(t, err, "Invalid userID")
transaction := createTransaction()
@@ -116,7 +117,7 @@ func TestGetReturnsSavedTransaction(t *testing.T) {
err = db.AssociateTransactionWithDestinations(
context.Background(),
- map[gomatrixserverlib.UserID]struct{}{
+ map[spec.UserID]struct{}{
*userID: {},
},
transaction.TransactionID,
@@ -157,7 +158,7 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) {
RelayQueueJSON: testDB,
}
httpReq := &http.Request{}
- userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
+ userID, err := spec.NewUserID("@local:domain", false)
assert.NoError(t, err, "Invalid userID")
transaction := createTransaction()
@@ -166,7 +167,7 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) {
err = db.AssociateTransactionWithDestinations(
context.Background(),
- map[gomatrixserverlib.UserID]struct{}{
+ map[spec.UserID]struct{}{
*userID: {},
},
transaction.TransactionID,
@@ -179,7 +180,7 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) {
err = db.AssociateTransactionWithDestinations(
context.Background(),
- map[gomatrixserverlib.UserID]struct{}{
+ map[spec.UserID]struct{}{
*userID: {},
},
transaction2.TransactionID,
diff --git a/relayapi/routing/routing.go b/relayapi/routing/routing.go
index 8ee0743e..6140d032 100644
--- a/relayapi/routing/routing.go
+++ b/relayapi/routing/routing.go
@@ -26,6 +26,8 @@ import (
relayInternal "github.com/matrix-org/dendrite/relayapi/internal"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/fclient"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
)
@@ -44,7 +46,7 @@ func Setup(
v1fedmux.Handle("/send_relay/{txnID}/{userID}", MakeRelayAPI(
"send_relay_transaction", "", cfg.Matrix.IsLocalServerName, keys,
- func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
+ func(httpReq *http.Request, request *fclient.FederationRequest, vars map[string]string) util.JSONResponse {
logrus.Infof("Handling send_relay from: %s", request.Origin())
if !relayAPI.RelayingEnabled() {
logrus.Warnf("Dropping send_relay from: %s", request.Origin())
@@ -53,7 +55,7 @@ func Setup(
}
}
- userID, err := gomatrixserverlib.NewUserID(vars["userID"], false)
+ userID, err := spec.NewUserID(vars["userID"], false)
if err != nil {
return util.JSONResponse{
Code: http.StatusBadRequest,
@@ -69,7 +71,7 @@ func Setup(
v1fedmux.Handle("/relay_txn/{userID}", MakeRelayAPI(
"get_relay_transaction", "", cfg.Matrix.IsLocalServerName, keys,
- func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
+ func(httpReq *http.Request, request *fclient.FederationRequest, vars map[string]string) util.JSONResponse {
logrus.Infof("Handling relay_txn from: %s", request.Origin())
if !relayAPI.RelayingEnabled() {
logrus.Warnf("Dropping relay_txn from: %s", request.Origin())
@@ -78,7 +80,7 @@ func Setup(
}
}
- userID, err := gomatrixserverlib.NewUserID(vars["userID"], false)
+ userID, err := spec.NewUserID(vars["userID"], false)
if err != nil {
return util.JSONResponse{
Code: http.StatusBadRequest,
@@ -92,13 +94,13 @@ func Setup(
// MakeRelayAPI makes an http.Handler that checks matrix relay authentication.
func MakeRelayAPI(
- metricsName string, serverName gomatrixserverlib.ServerName,
- isLocalServerName func(gomatrixserverlib.ServerName) bool,
+ metricsName string, serverName spec.ServerName,
+ isLocalServerName func(spec.ServerName) bool,
keyRing gomatrixserverlib.JSONVerifier,
- f func(*http.Request, *gomatrixserverlib.FederationRequest, map[string]string) util.JSONResponse,
+ f func(*http.Request, *fclient.FederationRequest, map[string]string) util.JSONResponse,
) http.Handler {
h := func(req *http.Request) util.JSONResponse {
- fedReq, errResp := gomatrixserverlib.VerifyHTTPRequest(
+ fedReq, errResp := fclient.VerifyHTTPRequest(
req, time.Now(), serverName, isLocalServerName, keyRing,
)
if fedReq == nil {
diff --git a/relayapi/routing/sendrelay.go b/relayapi/routing/sendrelay.go
index 84c24103..e4794dc4 100644
--- a/relayapi/routing/sendrelay.go
+++ b/relayapi/routing/sendrelay.go
@@ -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/matrix-org/util"
"github.com/sirupsen/logrus"
)
@@ -30,10 +31,10 @@ import (
// This endpoint can be extracted into a separate relay server service.
func SendTransactionToRelay(
httpReq *http.Request,
- fedReq *gomatrixserverlib.FederationRequest,
+ fedReq *fclient.FederationRequest,
relayAPI api.RelayInternalAPI,
txnID gomatrixserverlib.TransactionID,
- userID gomatrixserverlib.UserID,
+ userID spec.UserID,
) util.JSONResponse {
logrus.Infof("Processing send_relay for %s", userID.Raw())
diff --git a/relayapi/routing/sendrelay_test.go b/relayapi/routing/sendrelay_test.go
index 66594c47..05dfbe6d 100644
--- a/relayapi/routing/sendrelay_test.go
+++ b/relayapi/routing/sendrelay_test.go
@@ -26,11 +26,13 @@ import (
"github.com/matrix-org/dendrite/relayapi/storage/shared"
"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"
)
const (
- testOrigin = gomatrixserverlib.ServerName("kaer.morhen")
+ testOrigin = spec.ServerName("kaer.morhen")
)
func createTransaction() gomatrixserverlib.Transaction {
@@ -43,15 +45,15 @@ func createTransaction() gomatrixserverlib.Transaction {
}
func createFederationRequest(
- userID gomatrixserverlib.UserID,
+ userID spec.UserID,
txnID gomatrixserverlib.TransactionID,
- origin gomatrixserverlib.ServerName,
- destination gomatrixserverlib.ServerName,
+ origin spec.ServerName,
+ destination spec.ServerName,
content interface{},
-) gomatrixserverlib.FederationRequest {
+) fclient.FederationRequest {
var federationPathPrefixV1 = "/_matrix/federation/v1"
path := federationPathPrefixV1 + "/send_relay/" + string(txnID) + "/" + userID.Raw()
- request := gomatrixserverlib.NewFederationRequest("PUT", origin, destination, path)
+ request := fclient.NewFederationRequest("PUT", origin, destination, path)
request.SetContent(content)
return request
@@ -65,7 +67,7 @@ func TestForwardEmptyReturnsOk(t *testing.T) {
RelayQueueJSON: testDB,
}
httpReq := &http.Request{}
- userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
+ userID, err := spec.NewUserID("@local:domain", false)
assert.NoError(t, err, "Invalid userID")
txn := createTransaction()
@@ -88,7 +90,7 @@ func TestForwardBadJSONReturnsError(t *testing.T) {
RelayQueueJSON: testDB,
}
httpReq := &http.Request{}
- userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
+ userID, err := spec.NewUserID("@local:domain", false)
assert.NoError(t, err, "Invalid userID")
type BadData struct {
@@ -117,7 +119,7 @@ func TestForwardTooManyPDUsReturnsError(t *testing.T) {
RelayQueueJSON: testDB,
}
httpReq := &http.Request{}
- userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
+ userID, err := spec.NewUserID("@local:domain", false)
assert.NoError(t, err, "Invalid userID")
type BadData struct {
@@ -151,7 +153,7 @@ func TestForwardTooManyEDUsReturnsError(t *testing.T) {
RelayQueueJSON: testDB,
}
httpReq := &http.Request{}
- userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
+ userID, err := spec.NewUserID("@local:domain", false)
assert.NoError(t, err, "Invalid userID")
type BadData struct {
@@ -161,7 +163,7 @@ func TestForwardTooManyEDUsReturnsError(t *testing.T) {
Field: []gomatrixserverlib.EDU{},
}
for i := 0; i < 101; i++ {
- content.Field = append(content.Field, gomatrixserverlib.EDU{Type: gomatrixserverlib.MTyping})
+ content.Field = append(content.Field, gomatrixserverlib.EDU{Type: spec.MTyping})
}
assert.Greater(t, len(content.Field), 100)
@@ -185,7 +187,7 @@ func TestUniqueTransactionStoredInDatabase(t *testing.T) {
RelayQueueJSON: testDB,
}
httpReq := &http.Request{}
- userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
+ userID, err := spec.NewUserID("@local:domain", false)
assert.NoError(t, err, "Invalid userID")
txn := createTransaction()
diff --git a/relayapi/storage/interface.go b/relayapi/storage/interface.go
index f5f9a06e..bc1722cd 100644
--- a/relayapi/storage/interface.go
+++ b/relayapi/storage/interface.go
@@ -19,6 +19,7 @@ import (
"github.com/matrix-org/dendrite/federationapi/storage/shared/receipt"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
type Database interface {
@@ -29,19 +30,19 @@ type Database interface {
// Adds a new transaction_id: server_name mapping with associated json table nid to the queue
// entry table for each provided destination.
- AssociateTransactionWithDestinations(ctx context.Context, destinations map[gomatrixserverlib.UserID]struct{}, transactionID gomatrixserverlib.TransactionID, dbReceipt *receipt.Receipt) error
+ AssociateTransactionWithDestinations(ctx context.Context, destinations map[spec.UserID]struct{}, transactionID gomatrixserverlib.TransactionID, dbReceipt *receipt.Receipt) error
// Removes every server_name: receipt pair provided from the queue entries table.
// Will then remove every entry for each receipt provided from the queue json table.
// If any of the entries don't exist in either table, nothing will happen for that entry and
// an error will not be generated.
- CleanTransactions(ctx context.Context, userID gomatrixserverlib.UserID, receipts []*receipt.Receipt) error
+ CleanTransactions(ctx context.Context, userID spec.UserID, receipts []*receipt.Receipt) error
// Gets the oldest transaction for the provided server_name.
// If no transactions exist, returns nil and no error.
- GetTransaction(ctx context.Context, userID gomatrixserverlib.UserID) (*gomatrixserverlib.Transaction, *receipt.Receipt, error)
+ GetTransaction(ctx context.Context, userID spec.UserID) (*gomatrixserverlib.Transaction, *receipt.Receipt, error)
// Gets the number of transactions being stored for the provided server_name.
// If the server doesn't exist in the database then 0 is returned with no error.
- GetTransactionCount(ctx context.Context, userID gomatrixserverlib.UserID) (int64, error)
+ GetTransactionCount(ctx context.Context, userID spec.UserID) (int64, error)
}
diff --git a/relayapi/storage/postgres/relay_queue_table.go b/relayapi/storage/postgres/relay_queue_table.go
index e97cf8cc..5873af76 100644
--- a/relayapi/storage/postgres/relay_queue_table.go
+++ b/relayapi/storage/postgres/relay_queue_table.go
@@ -22,6 +22,7 @@ import (
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
const relayQueueSchema = `
@@ -90,7 +91,7 @@ func (s *relayQueueStatements) InsertQueueEntry(
ctx context.Context,
txn *sql.Tx,
transactionID gomatrixserverlib.TransactionID,
- serverName gomatrixserverlib.ServerName,
+ serverName spec.ServerName,
nid int64,
) error {
stmt := sqlutil.TxStmt(txn, s.insertQueueEntryStmt)
@@ -106,7 +107,7 @@ func (s *relayQueueStatements) InsertQueueEntry(
func (s *relayQueueStatements) DeleteQueueEntries(
ctx context.Context,
txn *sql.Tx,
- serverName gomatrixserverlib.ServerName,
+ serverName spec.ServerName,
jsonNIDs []int64,
) error {
stmt := sqlutil.TxStmt(txn, s.deleteQueueEntriesStmt)
@@ -117,7 +118,7 @@ func (s *relayQueueStatements) DeleteQueueEntries(
func (s *relayQueueStatements) SelectQueueEntries(
ctx context.Context,
txn *sql.Tx,
- serverName gomatrixserverlib.ServerName,
+ serverName spec.ServerName,
limit int,
) ([]int64, error) {
stmt := sqlutil.TxStmt(txn, s.selectQueueEntriesStmt)
@@ -141,7 +142,7 @@ func (s *relayQueueStatements) SelectQueueEntries(
func (s *relayQueueStatements) SelectQueueEntryCount(
ctx context.Context,
txn *sql.Tx,
- serverName gomatrixserverlib.ServerName,
+ serverName spec.ServerName,
) (int64, error) {
var count int64
stmt := sqlutil.TxStmt(txn, s.selectQueueEntryCountStmt)
diff --git a/relayapi/storage/postgres/storage.go b/relayapi/storage/postgres/storage.go
index 78bbaf1c..35c08c28 100644
--- a/relayapi/storage/postgres/storage.go
+++ b/relayapi/storage/postgres/storage.go
@@ -21,7 +21,7 @@ import (
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/relayapi/storage/shared"
"github.com/matrix-org/dendrite/setup/config"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
// Database stores information needed by the relayapi
@@ -36,7 +36,7 @@ func NewDatabase(
conMan sqlutil.Connections,
dbProperties *config.DatabaseOptions,
cache caching.FederationCache,
- isLocalServerName func(gomatrixserverlib.ServerName) bool,
+ isLocalServerName func(spec.ServerName) bool,
) (*Database, error) {
var d Database
var err error
diff --git a/relayapi/storage/shared/storage.go b/relayapi/storage/shared/storage.go
index 0993707b..fc1f12e7 100644
--- a/relayapi/storage/shared/storage.go
+++ b/relayapi/storage/shared/storage.go
@@ -25,11 +25,12 @@ import (
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/relayapi/storage/tables"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
type Database struct {
DB *sql.DB
- IsLocalServerName func(gomatrixserverlib.ServerName) bool
+ IsLocalServerName func(spec.ServerName) bool
Cache caching.FederationCache
Writer sqlutil.Writer
RelayQueue tables.RelayQueue
@@ -61,7 +62,7 @@ func (d *Database) StoreTransaction(
func (d *Database) AssociateTransactionWithDestinations(
ctx context.Context,
- destinations map[gomatrixserverlib.UserID]struct{},
+ destinations map[spec.UserID]struct{},
transactionID gomatrixserverlib.TransactionID,
dbReceipt *receipt.Receipt,
) error {
@@ -88,7 +89,7 @@ func (d *Database) AssociateTransactionWithDestinations(
func (d *Database) CleanTransactions(
ctx context.Context,
- userID gomatrixserverlib.UserID,
+ userID spec.UserID,
receipts []*receipt.Receipt,
) error {
nids := make([]int64, len(receipts))
@@ -123,7 +124,7 @@ func (d *Database) CleanTransactions(
func (d *Database) GetTransaction(
ctx context.Context,
- userID gomatrixserverlib.UserID,
+ userID spec.UserID,
) (*gomatrixserverlib.Transaction, *receipt.Receipt, error) {
entriesRequested := 1
nids, err := d.RelayQueue.SelectQueueEntries(ctx, nil, userID.Domain(), entriesRequested)
@@ -160,7 +161,7 @@ func (d *Database) GetTransaction(
func (d *Database) GetTransactionCount(
ctx context.Context,
- userID gomatrixserverlib.UserID,
+ userID spec.UserID,
) (int64, error) {
count, err := d.RelayQueue.SelectQueueEntryCount(ctx, nil, userID.Domain())
if err != nil {
diff --git a/relayapi/storage/sqlite3/relay_queue_table.go b/relayapi/storage/sqlite3/relay_queue_table.go
index 49c6b4de..30482ae9 100644
--- a/relayapi/storage/sqlite3/relay_queue_table.go
+++ b/relayapi/storage/sqlite3/relay_queue_table.go
@@ -23,6 +23,7 @@ import (
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
const relayQueueSchema = `
@@ -90,7 +91,7 @@ func (s *relayQueueStatements) InsertQueueEntry(
ctx context.Context,
txn *sql.Tx,
transactionID gomatrixserverlib.TransactionID,
- serverName gomatrixserverlib.ServerName,
+ serverName spec.ServerName,
nid int64,
) error {
stmt := sqlutil.TxStmt(txn, s.insertQueueEntryStmt)
@@ -106,7 +107,7 @@ func (s *relayQueueStatements) InsertQueueEntry(
func (s *relayQueueStatements) DeleteQueueEntries(
ctx context.Context,
txn *sql.Tx,
- serverName gomatrixserverlib.ServerName,
+ serverName spec.ServerName,
jsonNIDs []int64,
) error {
deleteSQL := strings.Replace(deleteQueueEntriesSQL, "($2)", sqlutil.QueryVariadicOffset(len(jsonNIDs), 1), 1)
@@ -129,7 +130,7 @@ func (s *relayQueueStatements) DeleteQueueEntries(
func (s *relayQueueStatements) SelectQueueEntries(
ctx context.Context,
txn *sql.Tx,
- serverName gomatrixserverlib.ServerName,
+ serverName spec.ServerName,
limit int,
) ([]int64, error) {
stmt := sqlutil.TxStmt(txn, s.selectQueueEntriesStmt)
@@ -153,7 +154,7 @@ func (s *relayQueueStatements) SelectQueueEntries(
func (s *relayQueueStatements) SelectQueueEntryCount(
ctx context.Context,
txn *sql.Tx,
- serverName gomatrixserverlib.ServerName,
+ serverName spec.ServerName,
) (int64, error) {
var count int64
stmt := sqlutil.TxStmt(txn, s.selectQueueEntryCountStmt)
diff --git a/relayapi/storage/sqlite3/storage.go b/relayapi/storage/sqlite3/storage.go
index da2cf9f7..7b46396f 100644
--- a/relayapi/storage/sqlite3/storage.go
+++ b/relayapi/storage/sqlite3/storage.go
@@ -21,7 +21,7 @@ import (
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/relayapi/storage/shared"
"github.com/matrix-org/dendrite/setup/config"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
// Database stores information needed by the federation sender
@@ -36,7 +36,7 @@ func NewDatabase(
conMan sqlutil.Connections,
dbProperties *config.DatabaseOptions,
cache caching.FederationCache,
- isLocalServerName func(gomatrixserverlib.ServerName) bool,
+ isLocalServerName func(spec.ServerName) bool,
) (*Database, error) {
var d Database
var err error
diff --git a/relayapi/storage/storage.go b/relayapi/storage/storage.go
index 17d9e6c7..6fce1efe 100644
--- a/relayapi/storage/storage.go
+++ b/relayapi/storage/storage.go
@@ -25,7 +25,7 @@ import (
"github.com/matrix-org/dendrite/relayapi/storage/postgres"
"github.com/matrix-org/dendrite/relayapi/storage/sqlite3"
"github.com/matrix-org/dendrite/setup/config"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
// NewDatabase opens a new database
@@ -33,7 +33,7 @@ func NewDatabase(
conMan sqlutil.Connections,
dbProperties *config.DatabaseOptions,
cache caching.FederationCache,
- isLocalServerName func(gomatrixserverlib.ServerName) bool,
+ isLocalServerName func(spec.ServerName) bool,
) (Database, error) {
switch {
case dbProperties.ConnectionString.IsSQLite():
diff --git a/relayapi/storage/storage_wasm.go b/relayapi/storage/storage_wasm.go
index 92847e1b..7e732334 100644
--- a/relayapi/storage/storage_wasm.go
+++ b/relayapi/storage/storage_wasm.go
@@ -29,7 +29,7 @@ func NewDatabase(
conMan sqlutil.Connections,
dbProperties *config.DatabaseOptions,
cache caching.FederationCache,
- isLocalServerName func(gomatrixserverlib.ServerName) bool,
+ isLocalServerName func(spec.ServerName) bool,
) (Database, error) {
switch {
case dbProperties.ConnectionString.IsSQLite():
diff --git a/relayapi/storage/tables/interface.go b/relayapi/storage/tables/interface.go
index 9056a567..27f43a8d 100644
--- a/relayapi/storage/tables/interface.go
+++ b/relayapi/storage/tables/interface.go
@@ -19,6 +19,7 @@ import (
"database/sql"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
// RelayQueue table contains a mapping of server name to transaction id and the corresponding nid.
@@ -28,21 +29,21 @@ type RelayQueue interface {
// Adds a new transaction_id: server_name mapping with associated json table nid to the table.
// Will ensure only one transaction id is present for each server_name: nid mapping.
// Adding duplicates will silently do nothing.
- InsertQueueEntry(ctx context.Context, txn *sql.Tx, transactionID gomatrixserverlib.TransactionID, serverName gomatrixserverlib.ServerName, nid int64) error
+ InsertQueueEntry(ctx context.Context, txn *sql.Tx, transactionID gomatrixserverlib.TransactionID, serverName spec.ServerName, nid int64) error
// Removes multiple entries from the table corresponding the the list of nids provided.
// If any of the provided nids don't match a row in the table, that deletion is considered
// successful.
- DeleteQueueEntries(ctx context.Context, txn *sql.Tx, serverName gomatrixserverlib.ServerName, jsonNIDs []int64) error
+ DeleteQueueEntries(ctx context.Context, txn *sql.Tx, serverName spec.ServerName, jsonNIDs []int64) error
// Get a list of nids associated with the provided server name.
// Returns up to `limit` nids. The entries are returned oldest first.
// Will return an empty list if no matches were found.
- SelectQueueEntries(ctx context.Context, txn *sql.Tx, serverName gomatrixserverlib.ServerName, limit int) ([]int64, error)
+ SelectQueueEntries(ctx context.Context, txn *sql.Tx, serverName spec.ServerName, limit int) ([]int64, error)
// Get the number of entries in the table associated with the provided server name.
// If there are no matching rows, a count of 0 is returned with err set to nil.
- SelectQueueEntryCount(ctx context.Context, txn *sql.Tx, serverName gomatrixserverlib.ServerName) (int64, error)
+ SelectQueueEntryCount(ctx context.Context, txn *sql.Tx, serverName spec.ServerName) (int64, error)
}
// RelayQueueJSON table contains a map of nid to the raw transaction json.
diff --git a/relayapi/storage/tables/relay_queue_json_table_test.go b/relayapi/storage/tables/relay_queue_json_table_test.go
index efa3363e..97af7eae 100644
--- a/relayapi/storage/tables/relay_queue_json_table_test.go
+++ b/relayapi/storage/tables/relay_queue_json_table_test.go
@@ -27,11 +27,12 @@ import (
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/test"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/stretchr/testify/assert"
)
const (
- testOrigin = gomatrixserverlib.ServerName("kaer.morhen")
+ testOrigin = spec.ServerName("kaer.morhen")
)
func mustCreateTransaction() gomatrixserverlib.Transaction {
diff --git a/relayapi/storage/tables/relay_queue_table_test.go b/relayapi/storage/tables/relay_queue_table_test.go
index 99f9922c..d196eaf5 100644
--- a/relayapi/storage/tables/relay_queue_table_test.go
+++ b/relayapi/storage/tables/relay_queue_table_test.go
@@ -28,6 +28,7 @@ import (
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/test"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/stretchr/testify/assert"
)
@@ -73,7 +74,7 @@ func TestShoudInsertQueueTransaction(t *testing.T) {
defer close()
transactionID := gomatrixserverlib.TransactionID(fmt.Sprintf("%d", time.Now().UnixNano()))
- serverName := gomatrixserverlib.ServerName("domain")
+ serverName := spec.ServerName("domain")
nid := int64(1)
err := db.Table.InsertQueueEntry(ctx, nil, transactionID, serverName, nid)
if err != nil {
@@ -89,7 +90,7 @@ func TestShouldRetrieveInsertedQueueTransaction(t *testing.T) {
defer close()
transactionID := gomatrixserverlib.TransactionID(fmt.Sprintf("%d", time.Now().UnixNano()))
- serverName := gomatrixserverlib.ServerName("domain")
+ serverName := spec.ServerName("domain")
nid := int64(1)
err := db.Table.InsertQueueEntry(ctx, nil, transactionID, serverName, nid)
@@ -114,7 +115,7 @@ func TestShouldRetrieveOldestInsertedQueueTransaction(t *testing.T) {
defer close()
transactionID := gomatrixserverlib.TransactionID(fmt.Sprintf("%d", time.Now().UnixNano()))
- serverName := gomatrixserverlib.ServerName("domain")
+ serverName := spec.ServerName("domain")
nid := int64(2)
err := db.Table.InsertQueueEntry(ctx, nil, transactionID, serverName, nid)
if err != nil {
@@ -122,7 +123,7 @@ func TestShouldRetrieveOldestInsertedQueueTransaction(t *testing.T) {
}
transactionID = gomatrixserverlib.TransactionID(fmt.Sprintf("%d", time.Now().UnixNano()))
- serverName = gomatrixserverlib.ServerName("domain")
+ serverName = spec.ServerName("domain")
oldestNID := int64(1)
err = db.Table.InsertQueueEntry(ctx, nil, transactionID, serverName, oldestNID)
if err != nil {
@@ -155,7 +156,7 @@ func TestShouldDeleteQueueTransaction(t *testing.T) {
defer close()
transactionID := gomatrixserverlib.TransactionID(fmt.Sprintf("%d", time.Now().UnixNano()))
- serverName := gomatrixserverlib.ServerName("domain")
+ serverName := spec.ServerName("domain")
nid := int64(1)
err := db.Table.InsertQueueEntry(ctx, nil, transactionID, serverName, nid)
@@ -186,10 +187,10 @@ func TestShouldDeleteOnlySpecifiedQueueTransaction(t *testing.T) {
defer close()
transactionID := gomatrixserverlib.TransactionID(fmt.Sprintf("%d", time.Now().UnixNano()))
- serverName := gomatrixserverlib.ServerName("domain")
+ serverName := spec.ServerName("domain")
nid := int64(1)
transactionID2 := gomatrixserverlib.TransactionID(fmt.Sprintf("%d2", time.Now().UnixNano()))
- serverName2 := gomatrixserverlib.ServerName("domain2")
+ serverName2 := spec.ServerName("domain2")
nid2 := int64(2)
transactionID3 := gomatrixserverlib.TransactionID(fmt.Sprintf("%d3", time.Now().UnixNano()))