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
|
@ -21,6 +21,7 @@ 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/util"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -35,7 +36,7 @@ func GetTransactionFromRelay(
|
|||
) util.JSONResponse {
|
||||
logrus.Infof("Processing relay_txn for %s", userID.Raw())
|
||||
|
||||
var previousEntry gomatrixserverlib.RelayEntry
|
||||
var previousEntry fclient.RelayEntry
|
||||
if err := json.Unmarshal(fedReq.Content(), &previousEntry); err != nil {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusInternalServerError,
|
||||
|
@ -59,7 +60,7 @@ func GetTransactionFromRelay(
|
|||
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: gomatrixserverlib.RespGetRelayTransaction{
|
||||
JSON: fclient.RespGetRelayTransaction{
|
||||
Transaction: response.Transaction,
|
||||
EntryID: response.EntryID,
|
||||
EntriesQueued: response.EntriesQueued,
|
||||
|
|
|
@ -25,12 +25,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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func createQuery(
|
||||
userID gomatrixserverlib.UserID,
|
||||
prevEntry gomatrixserverlib.RelayEntry,
|
||||
prevEntry fclient.RelayEntry,
|
||||
) gomatrixserverlib.FederationRequest {
|
||||
var federationPathPrefixV1 = "/_matrix/federation/v1"
|
||||
path := federationPathPrefixV1 + "/relay_txn/" + userID.Raw()
|
||||
|
@ -60,11 +61,11 @@ func TestGetEmptyDatabaseReturnsNothing(t *testing.T) {
|
|||
&db, nil, nil, nil, nil, false, "", true,
|
||||
)
|
||||
|
||||
request := createQuery(*userID, gomatrixserverlib.RelayEntry{})
|
||||
request := createQuery(*userID, fclient.RelayEntry{})
|
||||
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||
assert.Equal(t, http.StatusOK, response.Code)
|
||||
|
||||
jsonResponse := response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
||||
jsonResponse := response.JSON.(fclient.RespGetRelayTransaction)
|
||||
assert.Equal(t, false, jsonResponse.EntriesQueued)
|
||||
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
||||
|
||||
|
@ -93,7 +94,7 @@ func TestGetInvalidPrevEntryFails(t *testing.T) {
|
|||
&db, nil, nil, nil, nil, false, "", true,
|
||||
)
|
||||
|
||||
request := createQuery(*userID, gomatrixserverlib.RelayEntry{EntryID: -1})
|
||||
request := createQuery(*userID, fclient.RelayEntry{EntryID: -1})
|
||||
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||
assert.Equal(t, http.StatusInternalServerError, response.Code)
|
||||
}
|
||||
|
@ -126,20 +127,20 @@ func TestGetReturnsSavedTransaction(t *testing.T) {
|
|||
&db, nil, nil, nil, nil, false, "", true,
|
||||
)
|
||||
|
||||
request := createQuery(*userID, gomatrixserverlib.RelayEntry{})
|
||||
request := createQuery(*userID, fclient.RelayEntry{})
|
||||
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||
assert.Equal(t, http.StatusOK, response.Code)
|
||||
|
||||
jsonResponse := response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
||||
jsonResponse := response.JSON.(fclient.RespGetRelayTransaction)
|
||||
assert.True(t, jsonResponse.EntriesQueued)
|
||||
assert.Equal(t, transaction, jsonResponse.Transaction)
|
||||
|
||||
// And once more to clear the queue
|
||||
request = createQuery(*userID, gomatrixserverlib.RelayEntry{EntryID: jsonResponse.EntryID})
|
||||
request = createQuery(*userID, fclient.RelayEntry{EntryID: jsonResponse.EntryID})
|
||||
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||
assert.Equal(t, http.StatusOK, response.Code)
|
||||
|
||||
jsonResponse = response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
||||
jsonResponse = response.JSON.(fclient.RespGetRelayTransaction)
|
||||
assert.False(t, jsonResponse.EntriesQueued)
|
||||
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
||||
|
||||
|
@ -189,28 +190,28 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) {
|
|||
&db, nil, nil, nil, nil, false, "", true,
|
||||
)
|
||||
|
||||
request := createQuery(*userID, gomatrixserverlib.RelayEntry{})
|
||||
request := createQuery(*userID, fclient.RelayEntry{})
|
||||
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||
assert.Equal(t, http.StatusOK, response.Code)
|
||||
|
||||
jsonResponse := response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
||||
jsonResponse := response.JSON.(fclient.RespGetRelayTransaction)
|
||||
assert.True(t, jsonResponse.EntriesQueued)
|
||||
assert.Equal(t, transaction, jsonResponse.Transaction)
|
||||
|
||||
request = createQuery(*userID, gomatrixserverlib.RelayEntry{EntryID: jsonResponse.EntryID})
|
||||
request = createQuery(*userID, fclient.RelayEntry{EntryID: jsonResponse.EntryID})
|
||||
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||
assert.Equal(t, http.StatusOK, response.Code)
|
||||
|
||||
jsonResponse = response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
||||
jsonResponse = response.JSON.(fclient.RespGetRelayTransaction)
|
||||
assert.True(t, jsonResponse.EntriesQueued)
|
||||
assert.Equal(t, transaction2, jsonResponse.Transaction)
|
||||
|
||||
// And once more to clear the queue
|
||||
request = createQuery(*userID, gomatrixserverlib.RelayEntry{EntryID: jsonResponse.EntryID})
|
||||
request = createQuery(*userID, fclient.RelayEntry{EntryID: jsonResponse.EntryID})
|
||||
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||
assert.Equal(t, http.StatusOK, response.Code)
|
||||
|
||||
jsonResponse = response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
||||
jsonResponse = response.JSON.(fclient.RespGetRelayTransaction)
|
||||
assert.False(t, jsonResponse.EntriesQueued)
|
||||
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ 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/util"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -36,7 +37,7 @@ func SendTransactionToRelay(
|
|||
) util.JSONResponse {
|
||||
logrus.Infof("Processing send_relay for %s", userID.Raw())
|
||||
|
||||
var txnEvents gomatrixserverlib.RelayEvents
|
||||
var txnEvents fclient.RelayEvents
|
||||
if err := json.Unmarshal(fedReq.Content(), &txnEvents); err != nil {
|
||||
logrus.Info("The request body could not be decoded into valid JSON." + err.Error())
|
||||
return util.JSONResponse{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue