mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-08 18:16:59 +00:00
Use gmsl relay_txn response type
This commit is contained in:
parent
f98003c030
commit
7b3334778f
@ -52,7 +52,7 @@ func (r *RelayInternalAPI) PerformRelayServerSync(
|
|||||||
logrus.Errorf("P2PGetTransactionFromRelay: %s", err.Error())
|
logrus.Errorf("P2PGetTransactionFromRelay: %s", err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
r.processTransaction(&asyncResponse.Txn)
|
r.processTransaction(&asyncResponse.Transaction)
|
||||||
|
|
||||||
prevEntry = gomatrixserverlib.RelayEntry{EntryID: asyncResponse.EntryID}
|
prevEntry = gomatrixserverlib.RelayEntry{EntryID: asyncResponse.EntryID}
|
||||||
for asyncResponse.EntriesQueued {
|
for asyncResponse.EntriesQueued {
|
||||||
@ -64,7 +64,7 @@ func (r *RelayInternalAPI) PerformRelayServerSync(
|
|||||||
logrus.Errorf("P2PGetTransactionFromRelay: %s", err.Error())
|
logrus.Errorf("P2PGetTransactionFromRelay: %s", err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
r.processTransaction(&asyncResponse.Txn)
|
r.processTransaction(&asyncResponse.Transaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -46,8 +46,8 @@ func (f *testFedClient) P2PGetTransactionFromRelay(
|
|||||||
}
|
}
|
||||||
|
|
||||||
res = gomatrixserverlib.RespGetRelayTransaction{
|
res = gomatrixserverlib.RespGetRelayTransaction{
|
||||||
Txn: gomatrixserverlib.Transaction{},
|
Transaction: gomatrixserverlib.Transaction{},
|
||||||
EntryID: 0,
|
EntryID: 0,
|
||||||
}
|
}
|
||||||
if f.queueDepth > 0 {
|
if f.queueDepth > 0 {
|
||||||
res.EntriesQueued = true
|
res.EntriesQueued = true
|
||||||
|
@ -25,12 +25,6 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RelayTransactionResponse struct {
|
|
||||||
Transaction gomatrixserverlib.Transaction `json:"transaction"`
|
|
||||||
EntryID int64 `json:"entry_id,omitempty"`
|
|
||||||
EntriesQueued bool `json:"entries_queued"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTransactionFromRelay implements GET /_matrix/federation/v1/relay_txn/{userID}
|
// GetTransactionFromRelay implements GET /_matrix/federation/v1/relay_txn/{userID}
|
||||||
// This endpoint can be extracted into a separate relay server service.
|
// This endpoint can be extracted into a separate relay server service.
|
||||||
func GetTransactionFromRelay(
|
func GetTransactionFromRelay(
|
||||||
@ -41,7 +35,7 @@ func GetTransactionFromRelay(
|
|||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
logrus.Infof("Processing relay_txn for %s", userID.Raw())
|
logrus.Infof("Processing relay_txn for %s", userID.Raw())
|
||||||
|
|
||||||
previousEntry := gomatrixserverlib.RelayEntry{}
|
var previousEntry gomatrixserverlib.RelayEntry
|
||||||
if err := json.Unmarshal(fedReq.Content(), &previousEntry); err != nil {
|
if err := json.Unmarshal(fedReq.Content(), &previousEntry); err != nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusInternalServerError,
|
Code: http.StatusInternalServerError,
|
||||||
@ -65,7 +59,7 @@ func GetTransactionFromRelay(
|
|||||||
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: RelayTransactionResponse{
|
JSON: gomatrixserverlib.RespGetRelayTransaction{
|
||||||
Transaction: response.Transaction,
|
Transaction: response.Transaction,
|
||||||
EntryID: response.EntryID,
|
EntryID: response.EntryID,
|
||||||
EntriesQueued: response.EntriesQueued,
|
EntriesQueued: response.EntriesQueued,
|
||||||
|
@ -64,7 +64,7 @@ func TestGetEmptyDatabaseReturnsNothing(t *testing.T) {
|
|||||||
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusOK, response.Code)
|
assert.Equal(t, http.StatusOK, response.Code)
|
||||||
|
|
||||||
jsonResponse := response.JSON.(routing.RelayTransactionResponse)
|
jsonResponse := response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
||||||
assert.Equal(t, false, jsonResponse.EntriesQueued)
|
assert.Equal(t, false, jsonResponse.EntriesQueued)
|
||||||
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ func TestGetReturnsSavedTransaction(t *testing.T) {
|
|||||||
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusOK, response.Code)
|
assert.Equal(t, http.StatusOK, response.Code)
|
||||||
|
|
||||||
jsonResponse := response.JSON.(routing.RelayTransactionResponse)
|
jsonResponse := response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
||||||
assert.True(t, jsonResponse.EntriesQueued)
|
assert.True(t, jsonResponse.EntriesQueued)
|
||||||
assert.Equal(t, transaction, jsonResponse.Transaction)
|
assert.Equal(t, transaction, jsonResponse.Transaction)
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ func TestGetReturnsSavedTransaction(t *testing.T) {
|
|||||||
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusOK, response.Code)
|
assert.Equal(t, http.StatusOK, response.Code)
|
||||||
|
|
||||||
jsonResponse = response.JSON.(routing.RelayTransactionResponse)
|
jsonResponse = response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
||||||
assert.False(t, jsonResponse.EntriesQueued)
|
assert.False(t, jsonResponse.EntriesQueued)
|
||||||
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) {
|
|||||||
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusOK, response.Code)
|
assert.Equal(t, http.StatusOK, response.Code)
|
||||||
|
|
||||||
jsonResponse := response.JSON.(routing.RelayTransactionResponse)
|
jsonResponse := response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
||||||
assert.True(t, jsonResponse.EntriesQueued)
|
assert.True(t, jsonResponse.EntriesQueued)
|
||||||
assert.Equal(t, transaction, jsonResponse.Transaction)
|
assert.Equal(t, transaction, jsonResponse.Transaction)
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) {
|
|||||||
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusOK, response.Code)
|
assert.Equal(t, http.StatusOK, response.Code)
|
||||||
|
|
||||||
jsonResponse = response.JSON.(routing.RelayTransactionResponse)
|
jsonResponse = response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
||||||
assert.True(t, jsonResponse.EntriesQueued)
|
assert.True(t, jsonResponse.EntriesQueued)
|
||||||
assert.Equal(t, transaction2, jsonResponse.Transaction)
|
assert.Equal(t, transaction2, jsonResponse.Transaction)
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) {
|
|||||||
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusOK, response.Code)
|
assert.Equal(t, http.StatusOK, response.Code)
|
||||||
|
|
||||||
jsonResponse = response.JSON.(routing.RelayTransactionResponse)
|
jsonResponse = response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
||||||
assert.False(t, jsonResponse.EntriesQueued)
|
assert.False(t, jsonResponse.EntriesQueued)
|
||||||
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user