aboutsummaryrefslogtreecommitdiff
path: root/federationapi/routing
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-08-11 15:29:33 +0100
committerGitHub <noreply@github.com>2022-08-11 15:29:33 +0100
commitc45d0936b59b0eb65f12fe22a3da3690ae0b5494 (patch)
treefffe20dcf4c1d4efd8e6d8b6af1d21ef25a9539c /federationapi/routing
parent240ae257deb74b7be8a17500b77d5e1bca56e8f5 (diff)
Generic-based internal HTTP API (#2626)
* Generic-based internal HTTP API (tested out on a few endpoints in the federation API) * Add `PerformInvite` * More tweaks * Fix metric name * Fix LookupStateIDs * Lots of changes to clients * Some serverside stuff * Some error handling * Use paths as metric names * Revert "Use paths as metric names" This reverts commit a9323a6a343f5ce6461a2e5bd570fe06465f1b15. * Namespace metric names * Remove duplicate entry * Remove another duplicate entry * Tweak error handling * Some more tweaks * Update error behaviour * Some more error tweaking * Fix API path for `PerformDeleteKeys` * Fix another path * Tweak federation client proxying * Fix another path * Don't return typed nils * Some more tweaks, not that it makes any difference * Tweak federation client proxying * Maybe fix the key backup test
Diffstat (limited to 'federationapi/routing')
-rw-r--r--federationapi/routing/devices.go10
-rw-r--r--federationapi/routing/join.go6
-rw-r--r--federationapi/routing/keys.go16
-rw-r--r--federationapi/routing/leave.go6
-rw-r--r--federationapi/routing/send.go4
-rw-r--r--federationapi/routing/send_test.go3
6 files changed, 30 insertions, 15 deletions
diff --git a/federationapi/routing/devices.go b/federationapi/routing/devices.go
index 2f9da1f2..ce8b06b7 100644
--- a/federationapi/routing/devices.go
+++ b/federationapi/routing/devices.go
@@ -30,9 +30,11 @@ func GetUserDevices(
userID string,
) util.JSONResponse {
var res keyapi.QueryDeviceMessagesResponse
- keyAPI.QueryDeviceMessages(req.Context(), &keyapi.QueryDeviceMessagesRequest{
+ if err := keyAPI.QueryDeviceMessages(req.Context(), &keyapi.QueryDeviceMessagesRequest{
UserID: userID,
- }, &res)
+ }, &res); err != nil {
+ return util.ErrorResponse(err)
+ }
if res.Error != nil {
util.GetLogger(req.Context()).WithError(res.Error).Error("keyAPI.QueryDeviceMessages failed")
return jsonerror.InternalServerError()
@@ -47,7 +49,9 @@ func GetUserDevices(
for _, dev := range res.Devices {
sigReq.TargetIDs[userID] = append(sigReq.TargetIDs[userID], gomatrixserverlib.KeyID(dev.DeviceID))
}
- keyAPI.QuerySignatures(req.Context(), sigReq, sigRes)
+ if err := keyAPI.QuerySignatures(req.Context(), sigReq, sigRes); err != nil {
+ return jsonerror.InternalAPIError(req.Context(), err)
+ }
response := gomatrixserverlib.RespUserDevices{
UserID: userID,
diff --git a/federationapi/routing/join.go b/federationapi/routing/join.go
index 9ad3bd8e..b48eaf78 100644
--- a/federationapi/routing/join.go
+++ b/federationapi/routing/join.go
@@ -392,7 +392,7 @@ func SendJoin(
// the room, so set SendAsServer to cfg.Matrix.ServerName
if !alreadyJoined {
var response api.InputRoomEventsResponse
- rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
+ if err := rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
InputRoomEvents: []api.InputRoomEvent{
{
Kind: api.KindNew,
@@ -401,7 +401,9 @@ func SendJoin(
TransactionID: nil,
},
},
- }, &response)
+ }, &response); err != nil {
+ return jsonerror.InternalAPIError(httpReq.Context(), err)
+ }
if response.ErrMsg != "" {
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, response.ErrMsg).Error("SendEvents failed")
if response.NotAllowed {
diff --git a/federationapi/routing/keys.go b/federationapi/routing/keys.go
index b1a9b671..b03d4c1d 100644
--- a/federationapi/routing/keys.go
+++ b/federationapi/routing/keys.go
@@ -19,7 +19,7 @@ import (
"net/http"
"time"
- "github.com/matrix-org/dendrite/clientapi/httputil"
+ clienthttputil "github.com/matrix-org/dendrite/clientapi/httputil"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
"github.com/matrix-org/dendrite/keyserver/api"
@@ -61,9 +61,11 @@ func QueryDeviceKeys(
}
var queryRes api.QueryKeysResponse
- keyAPI.QueryKeys(httpReq.Context(), &api.QueryKeysRequest{
+ if err := keyAPI.QueryKeys(httpReq.Context(), &api.QueryKeysRequest{
UserToDevices: qkr.DeviceKeys,
- }, &queryRes)
+ }, &queryRes); err != nil {
+ return jsonerror.InternalAPIError(httpReq.Context(), err)
+ }
if queryRes.Error != nil {
util.GetLogger(httpReq.Context()).WithError(queryRes.Error).Error("Failed to QueryKeys")
return jsonerror.InternalServerError()
@@ -113,9 +115,11 @@ func ClaimOneTimeKeys(
}
var claimRes api.PerformClaimKeysResponse
- keyAPI.PerformClaimKeys(httpReq.Context(), &api.PerformClaimKeysRequest{
+ if err := keyAPI.PerformClaimKeys(httpReq.Context(), &api.PerformClaimKeysRequest{
OneTimeKeys: cor.OneTimeKeys,
- }, &claimRes)
+ }, &claimRes); err != nil {
+ return jsonerror.InternalAPIError(httpReq.Context(), err)
+ }
if claimRes.Error != nil {
util.GetLogger(httpReq.Context()).WithError(claimRes.Error).Error("Failed to PerformClaimKeys")
return jsonerror.InternalServerError()
@@ -184,7 +188,7 @@ func NotaryKeys(
) util.JSONResponse {
if req == nil {
req = &gomatrixserverlib.PublicKeyNotaryLookupRequest{}
- if reqErr := httputil.UnmarshalJSONRequest(httpReq, &req); reqErr != nil {
+ if reqErr := clienthttputil.UnmarshalJSONRequest(httpReq, &req); reqErr != nil {
return *reqErr
}
}
diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go
index dbaf68e5..8e43ce95 100644
--- a/federationapi/routing/leave.go
+++ b/federationapi/routing/leave.go
@@ -277,7 +277,7 @@ func SendLeave(
// We are responsible for notifying other servers that the user has left
// the room, so set SendAsServer to cfg.Matrix.ServerName
var response api.InputRoomEventsResponse
- rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
+ if err := rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
InputRoomEvents: []api.InputRoomEvent{
{
Kind: api.KindNew,
@@ -286,7 +286,9 @@ func SendLeave(
TransactionID: nil,
},
},
- }, &response)
+ }, &response); err != nil {
+ return jsonerror.InternalAPIError(httpReq.Context(), err)
+ }
if response.ErrMsg != "" {
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, response.ErrMsg).WithField("not_allowed", response.NotAllowed).Error("producer.SendEvents failed")
diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go
index 43003be3..87b6fa33 100644
--- a/federationapi/routing/send.go
+++ b/federationapi/routing/send.go
@@ -458,7 +458,9 @@ func (t *txnReq) processSigningKeyUpdate(ctx context.Context, e gomatrixserverli
UserID: updatePayload.UserID,
}
uploadRes := &keyapi.PerformUploadDeviceKeysResponse{}
- t.keyAPI.PerformUploadDeviceKeys(ctx, uploadReq, uploadRes)
+ if err := t.keyAPI.PerformUploadDeviceKeys(ctx, uploadReq, uploadRes); err != nil {
+ return err
+ }
if uploadRes.Error != nil {
return uploadRes.Error
}
diff --git a/federationapi/routing/send_test.go b/federationapi/routing/send_test.go
index a111580c..1c796f54 100644
--- a/federationapi/routing/send_test.go
+++ b/federationapi/routing/send_test.go
@@ -64,11 +64,12 @@ func (t *testRoomserverAPI) InputRoomEvents(
ctx context.Context,
request *api.InputRoomEventsRequest,
response *api.InputRoomEventsResponse,
-) {
+) error {
t.inputRoomEvents = append(t.inputRoomEvents, request.InputRoomEvents...)
for _, ire := range request.InputRoomEvents {
fmt.Println("InputRoomEvents: ", ire.Event.EventID())
}
+ return nil
}
// Query the latest events and state for a room from the room server.