mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 21:12:45 +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
|
@ -18,6 +18,7 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
)
|
||||
|
||||
// RelayInternalAPI is used to query information from the relay server.
|
||||
|
@ -51,7 +52,7 @@ type RelayServerAPI interface {
|
|||
QueryTransactions(
|
||||
ctx context.Context,
|
||||
userID gomatrixserverlib.UserID,
|
||||
previousEntry gomatrixserverlib.RelayEntry,
|
||||
previousEntry fclient.RelayEntry,
|
||||
) (QueryRelayTransactionsResponse, error)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/relayapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -46,7 +47,7 @@ func (r *RelayInternalAPI) PerformRelayServerSync(
|
|||
) error {
|
||||
// Providing a default RelayEntry (EntryID = 0) is done to ask the relay if there are any
|
||||
// transactions available for this node.
|
||||
prevEntry := gomatrixserverlib.RelayEntry{}
|
||||
prevEntry := fclient.RelayEntry{}
|
||||
asyncResponse, err := r.fedClient.P2PGetTransactionFromRelay(ctx, userID, prevEntry, relayServer)
|
||||
if err != nil {
|
||||
logrus.Errorf("P2PGetTransactionFromRelay: %s", err.Error())
|
||||
|
@ -54,12 +55,12 @@ func (r *RelayInternalAPI) PerformRelayServerSync(
|
|||
}
|
||||
r.processTransaction(&asyncResponse.Transaction)
|
||||
|
||||
prevEntry = gomatrixserverlib.RelayEntry{EntryID: asyncResponse.EntryID}
|
||||
prevEntry = fclient.RelayEntry{EntryID: asyncResponse.EntryID}
|
||||
for asyncResponse.EntriesQueued {
|
||||
// There are still more entries available for this node from the relay.
|
||||
logrus.Infof("Retrieving next entry from relay, previous: %v", prevEntry)
|
||||
asyncResponse, err = r.fedClient.P2PGetTransactionFromRelay(ctx, userID, prevEntry, relayServer)
|
||||
prevEntry = gomatrixserverlib.RelayEntry{EntryID: asyncResponse.EntryID}
|
||||
prevEntry = fclient.RelayEntry{EntryID: asyncResponse.EntryID}
|
||||
if err != nil {
|
||||
logrus.Errorf("P2PGetTransactionFromRelay: %s", err.Error())
|
||||
return err
|
||||
|
@ -97,7 +98,7 @@ func (r *RelayInternalAPI) PerformStoreTransaction(
|
|||
func (r *RelayInternalAPI) QueryTransactions(
|
||||
ctx context.Context,
|
||||
userID gomatrixserverlib.UserID,
|
||||
previousEntry gomatrixserverlib.RelayEntry,
|
||||
previousEntry fclient.RelayEntry,
|
||||
) (api.QueryRelayTransactionsResponse, error) {
|
||||
logrus.Infof("QueryTransactions for %s", userID.Raw())
|
||||
if previousEntry.EntryID > 0 {
|
||||
|
|
|
@ -24,6 +24,7 @@ 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"
|
||||
)
|
||||
|
||||
|
@ -37,15 +38,15 @@ type testFedClient struct {
|
|||
func (f *testFedClient) P2PGetTransactionFromRelay(
|
||||
ctx context.Context,
|
||||
u gomatrixserverlib.UserID,
|
||||
prev gomatrixserverlib.RelayEntry,
|
||||
prev fclient.RelayEntry,
|
||||
relayServer gomatrixserverlib.ServerName,
|
||||
) (res gomatrixserverlib.RespGetRelayTransaction, err error) {
|
||||
) (res fclient.RespGetRelayTransaction, err error) {
|
||||
f.queryCount++
|
||||
if f.shouldFail {
|
||||
return res, fmt.Errorf("Error")
|
||||
}
|
||||
|
||||
res = gomatrixserverlib.RespGetRelayTransaction{
|
||||
res = fclient.RespGetRelayTransaction{
|
||||
Transaction: gomatrixserverlib.Transaction{},
|
||||
EntryID: 0,
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
rsAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -53,7 +54,7 @@ func AddPublicRoutes(
|
|||
func NewRelayInternalAPI(
|
||||
dendriteCfg *config.Dendrite,
|
||||
cm sqlutil.Connections,
|
||||
fedClient *gomatrixserverlib.FederationClient,
|
||||
fedClient *fclient.FederationClient,
|
||||
rsAPI rsAPI.RoomserverInternalAPI,
|
||||
keyRing *gomatrixserverlib.KeyRing,
|
||||
producer *producers.SyncAPIProducer,
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/test"
|
||||
"github.com/matrix-org/dendrite/test/testrig"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -79,7 +80,7 @@ func createGetRelayTxnHTTPRequest(serverName gomatrixserverlib.ServerName, userI
|
|||
pk := sk.Public().(ed25519.PublicKey)
|
||||
origin := gomatrixserverlib.ServerName(hex.EncodeToString(pk))
|
||||
req := gomatrixserverlib.NewFederationRequest("GET", origin, serverName, "/_matrix/federation/v1/relay_txn/"+userID)
|
||||
content := gomatrixserverlib.RelayEntry{EntryID: 0}
|
||||
content := fclient.RelayEntry{EntryID: 0}
|
||||
req.SetContent(content)
|
||||
req.Sign(origin, gomatrixserverlib.KeyID(keyID), sk)
|
||||
httpreq, _ := req.HTTPRequest()
|
||||
|
|
|
@ -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