mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-25 21:21:35 +00:00
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
This commit is contained in:
parent
240ae257de
commit
c45d0936b5
@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/appservice/api"
|
"github.com/matrix-org/dendrite/appservice/api"
|
||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/opentracing/opentracing-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTP paths for the internal HTTP APIs
|
// HTTP paths for the internal HTTP APIs
|
||||||
@ -42,11 +41,10 @@ func (h *httpAppServiceQueryAPI) RoomAliasExists(
|
|||||||
request *api.RoomAliasExistsRequest,
|
request *api.RoomAliasExistsRequest,
|
||||||
response *api.RoomAliasExistsResponse,
|
response *api.RoomAliasExistsResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "appserviceRoomAliasExists")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"RoomAliasExists", h.appserviceURL+AppServiceRoomAliasExistsPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.appserviceURL + AppServiceRoomAliasExistsPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserIDExists implements AppServiceQueryAPI
|
// UserIDExists implements AppServiceQueryAPI
|
||||||
@ -55,9 +53,8 @@ func (h *httpAppServiceQueryAPI) UserIDExists(
|
|||||||
request *api.UserIDExistsRequest,
|
request *api.UserIDExistsRequest,
|
||||||
response *api.UserIDExistsResponse,
|
response *api.UserIDExistsResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "appserviceUserIDExists")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"UserIDExists", h.appserviceURL+AppServiceUserIDExistsPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.appserviceURL + AppServiceUserIDExistsPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
@ -1,43 +1,20 @@
|
|||||||
package inthttp
|
package inthttp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/appservice/api"
|
"github.com/matrix-org/dendrite/appservice/api"
|
||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddRoutes adds the AppServiceQueryAPI handlers to the http.ServeMux.
|
// AddRoutes adds the AppServiceQueryAPI handlers to the http.ServeMux.
|
||||||
func AddRoutes(a api.AppServiceInternalAPI, internalAPIMux *mux.Router) {
|
func AddRoutes(a api.AppServiceInternalAPI, internalAPIMux *mux.Router) {
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
AppServiceRoomAliasExistsPath,
|
AppServiceRoomAliasExistsPath,
|
||||||
httputil.MakeInternalAPI("appserviceRoomAliasExists", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("AppserviceRoomAliasExists", a.RoomAliasExists),
|
||||||
var request api.RoomAliasExistsRequest
|
|
||||||
var response api.RoomAliasExistsResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := a.RoomAliasExists(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
AppServiceUserIDExistsPath,
|
AppServiceUserIDExistsPath,
|
||||||
httputil.MakeInternalAPI("appserviceUserIDExists", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("AppserviceUserIDExists", a.UserIDExists),
|
||||||
var request api.UserIDExistsRequest
|
|
||||||
var response api.UserIDExistsResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := a.UserIDExists(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,13 @@
|
|||||||
package jsonerror
|
package jsonerror
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MatrixError represents the "standard error response" in Matrix.
|
// MatrixError represents the "standard error response" in Matrix.
|
||||||
@ -213,3 +215,15 @@ func NotTrusted(serverName string) *MatrixError {
|
|||||||
Err: fmt.Sprintf("Untrusted server '%s'", serverName),
|
Err: fmt.Sprintf("Untrusted server '%s'", serverName),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InternalAPIError is returned when Dendrite failed to reach an internal API.
|
||||||
|
func InternalAPIError(ctx context.Context, err error) util.JSONResponse {
|
||||||
|
logrus.WithContext(ctx).WithError(err).Error("Error reaching an internal API")
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusInternalServerError,
|
||||||
|
JSON: &MatrixError{
|
||||||
|
ErrCode: "M_INTERNAL_SERVER_ERROR",
|
||||||
|
Err: "Dendrite encountered an error reaching an internal API.",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -30,13 +30,15 @@ func AdminEvacuateRoom(req *http.Request, device *userapi.Device, rsAPI roomserv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
res := &roomserverAPI.PerformAdminEvacuateRoomResponse{}
|
res := &roomserverAPI.PerformAdminEvacuateRoomResponse{}
|
||||||
rsAPI.PerformAdminEvacuateRoom(
|
if err := rsAPI.PerformAdminEvacuateRoom(
|
||||||
req.Context(),
|
req.Context(),
|
||||||
&roomserverAPI.PerformAdminEvacuateRoomRequest{
|
&roomserverAPI.PerformAdminEvacuateRoomRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
},
|
},
|
||||||
res,
|
res,
|
||||||
)
|
); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
if err := res.Error; err != nil {
|
if err := res.Error; err != nil {
|
||||||
return err.JSONResponse()
|
return err.JSONResponse()
|
||||||
}
|
}
|
||||||
@ -67,13 +69,15 @@ func AdminEvacuateUser(req *http.Request, device *userapi.Device, rsAPI roomserv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
res := &roomserverAPI.PerformAdminEvacuateUserResponse{}
|
res := &roomserverAPI.PerformAdminEvacuateUserResponse{}
|
||||||
rsAPI.PerformAdminEvacuateUser(
|
if err := rsAPI.PerformAdminEvacuateUser(
|
||||||
req.Context(),
|
req.Context(),
|
||||||
&roomserverAPI.PerformAdminEvacuateUserRequest{
|
&roomserverAPI.PerformAdminEvacuateUserRequest{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
},
|
},
|
||||||
res,
|
res,
|
||||||
)
|
); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
if err := res.Error; err != nil {
|
if err := res.Error; err != nil {
|
||||||
return err.JSONResponse()
|
return err.JSONResponse()
|
||||||
}
|
}
|
||||||
|
@ -556,10 +556,12 @@ func createRoom(
|
|||||||
if r.Visibility == "public" {
|
if r.Visibility == "public" {
|
||||||
// expose this room in the published room list
|
// expose this room in the published room list
|
||||||
var pubRes roomserverAPI.PerformPublishResponse
|
var pubRes roomserverAPI.PerformPublishResponse
|
||||||
rsAPI.PerformPublish(ctx, &roomserverAPI.PerformPublishRequest{
|
if err := rsAPI.PerformPublish(ctx, &roomserverAPI.PerformPublishRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
Visibility: "public",
|
Visibility: "public",
|
||||||
}, &pubRes)
|
}, &pubRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(ctx, err)
|
||||||
|
}
|
||||||
if pubRes.Error != nil {
|
if pubRes.Error != nil {
|
||||||
// treat as non-fatal since the room is already made by this point
|
// treat as non-fatal since the room is already made by this point
|
||||||
util.GetLogger(ctx).WithError(pubRes.Error).Error("failed to visibility:public")
|
util.GetLogger(ctx).WithError(pubRes.Error).Error("failed to visibility:public")
|
||||||
|
@ -302,10 +302,12 @@ func SetVisibility(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var publishRes roomserverAPI.PerformPublishResponse
|
var publishRes roomserverAPI.PerformPublishResponse
|
||||||
rsAPI.PerformPublish(req.Context(), &roomserverAPI.PerformPublishRequest{
|
if err := rsAPI.PerformPublish(req.Context(), &roomserverAPI.PerformPublishRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
Visibility: v.Visibility,
|
Visibility: v.Visibility,
|
||||||
}, &publishRes)
|
}, &publishRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
if publishRes.Error != nil {
|
if publishRes.Error != nil {
|
||||||
util.GetLogger(req.Context()).WithError(publishRes.Error).Error("PerformPublish failed")
|
util.GetLogger(req.Context()).WithError(publishRes.Error).Error("PerformPublish failed")
|
||||||
return publishRes.Error.JSONResponse()
|
return publishRes.Error.JSONResponse()
|
||||||
|
@ -81,8 +81,9 @@ func JoinRoomByIDOrAlias(
|
|||||||
done := make(chan util.JSONResponse, 1)
|
done := make(chan util.JSONResponse, 1)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(done)
|
defer close(done)
|
||||||
rsAPI.PerformJoin(req.Context(), &joinReq, &joinRes)
|
if err := rsAPI.PerformJoin(req.Context(), &joinReq, &joinRes); err != nil {
|
||||||
if joinRes.Error != nil {
|
done <- jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
} else if joinRes.Error != nil {
|
||||||
done <- joinRes.Error.JSONResponse()
|
done <- joinRes.Error.JSONResponse()
|
||||||
} else {
|
} else {
|
||||||
done <- util.JSONResponse{
|
done <- util.JSONResponse{
|
||||||
|
@ -91,10 +91,12 @@ func CreateKeyBackupVersion(req *http.Request, userAPI userapi.ClientUserAPI, de
|
|||||||
// Implements GET /_matrix/client/r0/room_keys/version and GET /_matrix/client/r0/room_keys/version/{version}
|
// Implements GET /_matrix/client/r0/room_keys/version and GET /_matrix/client/r0/room_keys/version/{version}
|
||||||
func KeyBackupVersion(req *http.Request, userAPI userapi.ClientUserAPI, device *userapi.Device, version string) util.JSONResponse {
|
func KeyBackupVersion(req *http.Request, userAPI userapi.ClientUserAPI, device *userapi.Device, version string) util.JSONResponse {
|
||||||
var queryResp userapi.QueryKeyBackupResponse
|
var queryResp userapi.QueryKeyBackupResponse
|
||||||
userAPI.QueryKeyBackup(req.Context(), &userapi.QueryKeyBackupRequest{
|
if err := userAPI.QueryKeyBackup(req.Context(), &userapi.QueryKeyBackupRequest{
|
||||||
UserID: device.UserID,
|
UserID: device.UserID,
|
||||||
Version: version,
|
Version: version,
|
||||||
}, &queryResp)
|
}, &queryResp); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
if queryResp.Error != "" {
|
if queryResp.Error != "" {
|
||||||
return util.ErrorResponse(fmt.Errorf("QueryKeyBackup: %s", queryResp.Error))
|
return util.ErrorResponse(fmt.Errorf("QueryKeyBackup: %s", queryResp.Error))
|
||||||
}
|
}
|
||||||
@ -233,13 +235,15 @@ func GetBackupKeys(
|
|||||||
req *http.Request, userAPI userapi.ClientUserAPI, device *userapi.Device, version, roomID, sessionID string,
|
req *http.Request, userAPI userapi.ClientUserAPI, device *userapi.Device, version, roomID, sessionID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var queryResp userapi.QueryKeyBackupResponse
|
var queryResp userapi.QueryKeyBackupResponse
|
||||||
userAPI.QueryKeyBackup(req.Context(), &userapi.QueryKeyBackupRequest{
|
if err := userAPI.QueryKeyBackup(req.Context(), &userapi.QueryKeyBackupRequest{
|
||||||
UserID: device.UserID,
|
UserID: device.UserID,
|
||||||
Version: version,
|
Version: version,
|
||||||
ReturnKeys: true,
|
ReturnKeys: true,
|
||||||
KeysForRoomID: roomID,
|
KeysForRoomID: roomID,
|
||||||
KeysForSessionID: sessionID,
|
KeysForSessionID: sessionID,
|
||||||
}, &queryResp)
|
}, &queryResp); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
if queryResp.Error != "" {
|
if queryResp.Error != "" {
|
||||||
return util.ErrorResponse(fmt.Errorf("QueryKeyBackup: %s", queryResp.Error))
|
return util.ErrorResponse(fmt.Errorf("QueryKeyBackup: %s", queryResp.Error))
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,9 @@ func UploadCrossSigningDeviceKeys(
|
|||||||
sessions.addCompletedSessionStage(sessionID, authtypes.LoginTypePassword)
|
sessions.addCompletedSessionStage(sessionID, authtypes.LoginTypePassword)
|
||||||
|
|
||||||
uploadReq.UserID = device.UserID
|
uploadReq.UserID = device.UserID
|
||||||
keyserverAPI.PerformUploadDeviceKeys(req.Context(), &uploadReq.PerformUploadDeviceKeysRequest, uploadRes)
|
if err := keyserverAPI.PerformUploadDeviceKeys(req.Context(), &uploadReq.PerformUploadDeviceKeysRequest, uploadRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := uploadRes.Error; err != nil {
|
if err := uploadRes.Error; err != nil {
|
||||||
switch {
|
switch {
|
||||||
@ -114,7 +116,9 @@ func UploadCrossSigningDeviceSignatures(req *http.Request, keyserverAPI api.Clie
|
|||||||
}
|
}
|
||||||
|
|
||||||
uploadReq.UserID = device.UserID
|
uploadReq.UserID = device.UserID
|
||||||
keyserverAPI.PerformUploadDeviceSignatures(req.Context(), uploadReq, uploadRes)
|
if err := keyserverAPI.PerformUploadDeviceSignatures(req.Context(), uploadReq, uploadRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := uploadRes.Error; err != nil {
|
if err := uploadRes.Error; err != nil {
|
||||||
switch {
|
switch {
|
||||||
|
@ -62,7 +62,9 @@ func UploadKeys(req *http.Request, keyAPI api.ClientKeyAPI, device *userapi.Devi
|
|||||||
}
|
}
|
||||||
|
|
||||||
var uploadRes api.PerformUploadKeysResponse
|
var uploadRes api.PerformUploadKeysResponse
|
||||||
keyAPI.PerformUploadKeys(req.Context(), uploadReq, &uploadRes)
|
if err := keyAPI.PerformUploadKeys(req.Context(), uploadReq, &uploadRes); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
if uploadRes.Error != nil {
|
if uploadRes.Error != nil {
|
||||||
util.GetLogger(req.Context()).WithError(uploadRes.Error).Error("Failed to PerformUploadKeys")
|
util.GetLogger(req.Context()).WithError(uploadRes.Error).Error("Failed to PerformUploadKeys")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
@ -107,12 +109,14 @@ func QueryKeys(req *http.Request, keyAPI api.ClientKeyAPI, device *userapi.Devic
|
|||||||
return *resErr
|
return *resErr
|
||||||
}
|
}
|
||||||
queryRes := api.QueryKeysResponse{}
|
queryRes := api.QueryKeysResponse{}
|
||||||
keyAPI.QueryKeys(req.Context(), &api.QueryKeysRequest{
|
if err := keyAPI.QueryKeys(req.Context(), &api.QueryKeysRequest{
|
||||||
UserID: device.UserID,
|
UserID: device.UserID,
|
||||||
UserToDevices: r.DeviceKeys,
|
UserToDevices: r.DeviceKeys,
|
||||||
Timeout: r.GetTimeout(),
|
Timeout: r.GetTimeout(),
|
||||||
// TODO: Token?
|
// TODO: Token?
|
||||||
}, &queryRes)
|
}, &queryRes); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: 200,
|
Code: 200,
|
||||||
JSON: map[string]interface{}{
|
JSON: map[string]interface{}{
|
||||||
@ -145,10 +149,12 @@ func ClaimKeys(req *http.Request, keyAPI api.ClientKeyAPI) util.JSONResponse {
|
|||||||
return *resErr
|
return *resErr
|
||||||
}
|
}
|
||||||
claimRes := api.PerformClaimKeysResponse{}
|
claimRes := api.PerformClaimKeysResponse{}
|
||||||
keyAPI.PerformClaimKeys(req.Context(), &api.PerformClaimKeysRequest{
|
if err := keyAPI.PerformClaimKeys(req.Context(), &api.PerformClaimKeysRequest{
|
||||||
OneTimeKeys: r.OneTimeKeys,
|
OneTimeKeys: r.OneTimeKeys,
|
||||||
Timeout: r.GetTimeout(),
|
Timeout: r.GetTimeout(),
|
||||||
}, &claimRes)
|
}, &claimRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
if claimRes.Error != nil {
|
if claimRes.Error != nil {
|
||||||
util.GetLogger(req.Context()).WithError(claimRes.Error).Error("failed to PerformClaimKeys")
|
util.GetLogger(req.Context()).WithError(claimRes.Error).Error("failed to PerformClaimKeys")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
|
@ -17,6 +17,7 @@ package routing
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
@ -54,7 +55,9 @@ func PeekRoomByIDOrAlias(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ask the roomserver to perform the peek.
|
// Ask the roomserver to perform the peek.
|
||||||
rsAPI.PerformPeek(req.Context(), &peekReq, &peekRes)
|
if err := rsAPI.PerformPeek(req.Context(), &peekReq, &peekRes); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
if peekRes.Error != nil {
|
if peekRes.Error != nil {
|
||||||
return peekRes.Error.JSONResponse()
|
return peekRes.Error.JSONResponse()
|
||||||
}
|
}
|
||||||
@ -89,7 +92,9 @@ func UnpeekRoomByID(
|
|||||||
}
|
}
|
||||||
unpeekRes := roomserverAPI.PerformUnpeekResponse{}
|
unpeekRes := roomserverAPI.PerformUnpeekResponse{}
|
||||||
|
|
||||||
rsAPI.PerformUnpeek(req.Context(), &unpeekReq, &unpeekRes)
|
if err := rsAPI.PerformUnpeek(req.Context(), &unpeekReq, &unpeekRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
if unpeekRes.Error != nil {
|
if unpeekRes.Error != nil {
|
||||||
return unpeekRes.Error.JSONResponse()
|
return unpeekRes.Error.JSONResponse()
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,9 @@ func UpgradeRoom(
|
|||||||
}
|
}
|
||||||
upgradeResp := roomserverAPI.PerformRoomUpgradeResponse{}
|
upgradeResp := roomserverAPI.PerformRoomUpgradeResponse{}
|
||||||
|
|
||||||
rsAPI.PerformRoomUpgrade(req.Context(), &upgradeReq, &upgradeResp)
|
if err := rsAPI.PerformRoomUpgrade(req.Context(), &upgradeReq, &upgradeResp); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
|
|
||||||
if upgradeResp.Error != nil {
|
if upgradeResp.Error != nil {
|
||||||
if upgradeResp.Error.Code == roomserverAPI.PerformErrorNoRoom {
|
if upgradeResp.Error.Code == roomserverAPI.PerformErrorNoRoom {
|
||||||
|
@ -110,7 +110,7 @@ type FederationClientError struct {
|
|||||||
Blacklisted bool
|
Blacklisted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *FederationClientError) Error() string {
|
func (e FederationClientError) Error() string {
|
||||||
return fmt.Sprintf("%s - (retry_after=%s, blacklisted=%v)", e.Err, e.RetryAfter.String(), e.Blacklisted)
|
return fmt.Sprintf("%s - (retry_after=%s, blacklisted=%v)", e.Err, e.RetryAfter.String(), e.Blacklisted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,11 +32,12 @@ type fedRoomserverAPI struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PerformJoin will call this function
|
// PerformJoin will call this function
|
||||||
func (f *fedRoomserverAPI) InputRoomEvents(ctx context.Context, req *rsapi.InputRoomEventsRequest, res *rsapi.InputRoomEventsResponse) {
|
func (f *fedRoomserverAPI) InputRoomEvents(ctx context.Context, req *rsapi.InputRoomEventsRequest, res *rsapi.InputRoomEventsResponse) error {
|
||||||
if f.inputRoomEvents == nil {
|
if f.inputRoomEvents == nil {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
f.inputRoomEvents(ctx, req, res)
|
f.inputRoomEvents(ctx, req, res)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// keychange consumer calls this
|
// keychange consumer calls this
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/opentracing/opentracing-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTP paths for the internal HTTP API
|
// HTTP paths for the internal HTTP API
|
||||||
@ -48,7 +47,11 @@ func NewFederationAPIClient(federationSenderURL string, httpClient *http.Client,
|
|||||||
if httpClient == nil {
|
if httpClient == nil {
|
||||||
return nil, errors.New("NewFederationInternalAPIHTTP: httpClient is <nil>")
|
return nil, errors.New("NewFederationInternalAPIHTTP: httpClient is <nil>")
|
||||||
}
|
}
|
||||||
return &httpFederationInternalAPI{federationSenderURL, httpClient, cache}, nil
|
return &httpFederationInternalAPI{
|
||||||
|
federationAPIURL: federationSenderURL,
|
||||||
|
httpClient: httpClient,
|
||||||
|
cache: cache,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpFederationInternalAPI struct {
|
type httpFederationInternalAPI struct {
|
||||||
@ -63,11 +66,10 @@ func (h *httpFederationInternalAPI) PerformLeave(
|
|||||||
request *api.PerformLeaveRequest,
|
request *api.PerformLeaveRequest,
|
||||||
response *api.PerformLeaveResponse,
|
response *api.PerformLeaveResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformLeaveRequest")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformLeave", h.federationAPIURL+FederationAPIPerformLeaveRequestPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.federationAPIURL + FederationAPIPerformLeaveRequestPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle sending an invite to a remote server.
|
// Handle sending an invite to a remote server.
|
||||||
@ -76,11 +78,10 @@ func (h *httpFederationInternalAPI) PerformInvite(
|
|||||||
request *api.PerformInviteRequest,
|
request *api.PerformInviteRequest,
|
||||||
response *api.PerformInviteResponse,
|
response *api.PerformInviteResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformInviteRequest")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformInvite", h.federationAPIURL+FederationAPIPerformInviteRequestPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.federationAPIURL + FederationAPIPerformInviteRequestPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle starting a peek on a remote server.
|
// Handle starting a peek on a remote server.
|
||||||
@ -89,11 +90,10 @@ func (h *httpFederationInternalAPI) PerformOutboundPeek(
|
|||||||
request *api.PerformOutboundPeekRequest,
|
request *api.PerformOutboundPeekRequest,
|
||||||
response *api.PerformOutboundPeekResponse,
|
response *api.PerformOutboundPeekResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformOutboundPeekRequest")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformOutboundPeek", h.federationAPIURL+FederationAPIPerformOutboundPeekRequestPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.federationAPIURL + FederationAPIPerformOutboundPeekRequestPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryJoinedHostServerNamesInRoom implements FederationInternalAPI
|
// QueryJoinedHostServerNamesInRoom implements FederationInternalAPI
|
||||||
@ -102,11 +102,10 @@ func (h *httpFederationInternalAPI) QueryJoinedHostServerNamesInRoom(
|
|||||||
request *api.QueryJoinedHostServerNamesInRoomRequest,
|
request *api.QueryJoinedHostServerNamesInRoomRequest,
|
||||||
response *api.QueryJoinedHostServerNamesInRoomResponse,
|
response *api.QueryJoinedHostServerNamesInRoomResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryJoinedHostServerNamesInRoom")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryJoinedHostServerNamesInRoom", h.federationAPIURL+FederationAPIQueryJoinedHostServerNamesInRoomPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.federationAPIURL + FederationAPIQueryJoinedHostServerNamesInRoomPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle an instruction to make_join & send_join with a remote server.
|
// Handle an instruction to make_join & send_join with a remote server.
|
||||||
@ -115,12 +114,10 @@ func (h *httpFederationInternalAPI) PerformJoin(
|
|||||||
request *api.PerformJoinRequest,
|
request *api.PerformJoinRequest,
|
||||||
response *api.PerformJoinResponse,
|
response *api.PerformJoinResponse,
|
||||||
) {
|
) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformJoinRequest")
|
if err := httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformJoinRequest", h.federationAPIURL+FederationAPIPerformJoinRequestPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.federationAPIURL + FederationAPIPerformJoinRequestPath
|
); err != nil {
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.LastError = &gomatrix.HTTPError{
|
response.LastError = &gomatrix.HTTPError{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
Code: 0,
|
Code: 0,
|
||||||
@ -135,11 +132,10 @@ func (h *httpFederationInternalAPI) PerformDirectoryLookup(
|
|||||||
request *api.PerformDirectoryLookupRequest,
|
request *api.PerformDirectoryLookupRequest,
|
||||||
response *api.PerformDirectoryLookupResponse,
|
response *api.PerformDirectoryLookupResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformDirectoryLookup")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformDirectoryLookup", h.federationAPIURL+FederationAPIPerformDirectoryLookupRequestPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.federationAPIURL + FederationAPIPerformDirectoryLookupRequestPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle an instruction to broadcast an EDU to all servers in rooms we are joined to.
|
// Handle an instruction to broadcast an EDU to all servers in rooms we are joined to.
|
||||||
@ -148,101 +144,61 @@ func (h *httpFederationInternalAPI) PerformBroadcastEDU(
|
|||||||
request *api.PerformBroadcastEDURequest,
|
request *api.PerformBroadcastEDURequest,
|
||||||
response *api.PerformBroadcastEDUResponse,
|
response *api.PerformBroadcastEDUResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformBroadcastEDU")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformBroadcastEDU", h.federationAPIURL+FederationAPIPerformBroadcastEDUPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.federationAPIURL + FederationAPIPerformBroadcastEDUPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type getUserDevices struct {
|
type getUserDevices struct {
|
||||||
S gomatrixserverlib.ServerName
|
S gomatrixserverlib.ServerName
|
||||||
UserID string
|
UserID string
|
||||||
Res *gomatrixserverlib.RespUserDevices
|
|
||||||
Err *api.FederationClientError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) GetUserDevices(
|
func (h *httpFederationInternalAPI) GetUserDevices(
|
||||||
ctx context.Context, s gomatrixserverlib.ServerName, userID string,
|
ctx context.Context, s gomatrixserverlib.ServerName, userID string,
|
||||||
) (gomatrixserverlib.RespUserDevices, error) {
|
) (gomatrixserverlib.RespUserDevices, error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "GetUserDevices")
|
return httputil.CallInternalProxyAPI[getUserDevices, gomatrixserverlib.RespUserDevices, *api.FederationClientError](
|
||||||
defer span.Finish()
|
"GetUserDevices", h.federationAPIURL+FederationAPIGetUserDevicesPath, h.httpClient,
|
||||||
|
ctx, &getUserDevices{
|
||||||
var result gomatrixserverlib.RespUserDevices
|
|
||||||
request := getUserDevices{
|
|
||||||
S: s,
|
S: s,
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
}
|
},
|
||||||
var response getUserDevices
|
)
|
||||||
apiURL := h.federationAPIURL + FederationAPIGetUserDevicesPath
|
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
if response.Err != nil {
|
|
||||||
return result, response.Err
|
|
||||||
}
|
|
||||||
return *response.Res, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type claimKeys struct {
|
type claimKeys struct {
|
||||||
S gomatrixserverlib.ServerName
|
S gomatrixserverlib.ServerName
|
||||||
OneTimeKeys map[string]map[string]string
|
OneTimeKeys map[string]map[string]string
|
||||||
Res *gomatrixserverlib.RespClaimKeys
|
|
||||||
Err *api.FederationClientError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) ClaimKeys(
|
func (h *httpFederationInternalAPI) ClaimKeys(
|
||||||
ctx context.Context, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string,
|
ctx context.Context, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string,
|
||||||
) (gomatrixserverlib.RespClaimKeys, error) {
|
) (gomatrixserverlib.RespClaimKeys, error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "ClaimKeys")
|
return httputil.CallInternalProxyAPI[claimKeys, gomatrixserverlib.RespClaimKeys, *api.FederationClientError](
|
||||||
defer span.Finish()
|
"ClaimKeys", h.federationAPIURL+FederationAPIClaimKeysPath, h.httpClient,
|
||||||
|
ctx, &claimKeys{
|
||||||
var result gomatrixserverlib.RespClaimKeys
|
|
||||||
request := claimKeys{
|
|
||||||
S: s,
|
S: s,
|
||||||
OneTimeKeys: oneTimeKeys,
|
OneTimeKeys: oneTimeKeys,
|
||||||
}
|
},
|
||||||
var response claimKeys
|
)
|
||||||
apiURL := h.federationAPIURL + FederationAPIClaimKeysPath
|
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
if response.Err != nil {
|
|
||||||
return result, response.Err
|
|
||||||
}
|
|
||||||
return *response.Res, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type queryKeys struct {
|
type queryKeys struct {
|
||||||
S gomatrixserverlib.ServerName
|
S gomatrixserverlib.ServerName
|
||||||
Keys map[string][]string
|
Keys map[string][]string
|
||||||
Res *gomatrixserverlib.RespQueryKeys
|
|
||||||
Err *api.FederationClientError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) QueryKeys(
|
func (h *httpFederationInternalAPI) QueryKeys(
|
||||||
ctx context.Context, s gomatrixserverlib.ServerName, keys map[string][]string,
|
ctx context.Context, s gomatrixserverlib.ServerName, keys map[string][]string,
|
||||||
) (gomatrixserverlib.RespQueryKeys, error) {
|
) (gomatrixserverlib.RespQueryKeys, error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryKeys")
|
return httputil.CallInternalProxyAPI[queryKeys, gomatrixserverlib.RespQueryKeys, *api.FederationClientError](
|
||||||
defer span.Finish()
|
"QueryKeys", h.federationAPIURL+FederationAPIQueryKeysPath, h.httpClient,
|
||||||
|
ctx, &queryKeys{
|
||||||
var result gomatrixserverlib.RespQueryKeys
|
|
||||||
request := queryKeys{
|
|
||||||
S: s,
|
S: s,
|
||||||
Keys: keys,
|
Keys: keys,
|
||||||
}
|
},
|
||||||
var response queryKeys
|
)
|
||||||
apiURL := h.federationAPIURL + FederationAPIQueryKeysPath
|
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
if response.Err != nil {
|
|
||||||
return result, response.Err
|
|
||||||
}
|
|
||||||
return *response.Res, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type backfill struct {
|
type backfill struct {
|
||||||
@ -250,32 +206,20 @@ type backfill struct {
|
|||||||
RoomID string
|
RoomID string
|
||||||
Limit int
|
Limit int
|
||||||
EventIDs []string
|
EventIDs []string
|
||||||
Res *gomatrixserverlib.Transaction
|
|
||||||
Err *api.FederationClientError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) Backfill(
|
func (h *httpFederationInternalAPI) Backfill(
|
||||||
ctx context.Context, s gomatrixserverlib.ServerName, roomID string, limit int, eventIDs []string,
|
ctx context.Context, s gomatrixserverlib.ServerName, roomID string, limit int, eventIDs []string,
|
||||||
) (gomatrixserverlib.Transaction, error) {
|
) (gomatrixserverlib.Transaction, error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "Backfill")
|
return httputil.CallInternalProxyAPI[backfill, gomatrixserverlib.Transaction, *api.FederationClientError](
|
||||||
defer span.Finish()
|
"Backfill", h.federationAPIURL+FederationAPIBackfillPath, h.httpClient,
|
||||||
|
ctx, &backfill{
|
||||||
request := backfill{
|
|
||||||
S: s,
|
S: s,
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
EventIDs: eventIDs,
|
EventIDs: eventIDs,
|
||||||
}
|
},
|
||||||
var response backfill
|
)
|
||||||
apiURL := h.federationAPIURL + FederationAPIBackfillPath
|
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return gomatrixserverlib.Transaction{}, err
|
|
||||||
}
|
|
||||||
if response.Err != nil {
|
|
||||||
return gomatrixserverlib.Transaction{}, response.Err
|
|
||||||
}
|
|
||||||
return *response.Res, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type lookupState struct {
|
type lookupState struct {
|
||||||
@ -283,63 +227,39 @@ type lookupState struct {
|
|||||||
RoomID string
|
RoomID string
|
||||||
EventID string
|
EventID string
|
||||||
RoomVersion gomatrixserverlib.RoomVersion
|
RoomVersion gomatrixserverlib.RoomVersion
|
||||||
Res *gomatrixserverlib.RespState
|
|
||||||
Err *api.FederationClientError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) LookupState(
|
func (h *httpFederationInternalAPI) LookupState(
|
||||||
ctx context.Context, s gomatrixserverlib.ServerName, roomID, eventID string, roomVersion gomatrixserverlib.RoomVersion,
|
ctx context.Context, s gomatrixserverlib.ServerName, roomID, eventID string, roomVersion gomatrixserverlib.RoomVersion,
|
||||||
) (gomatrixserverlib.RespState, error) {
|
) (gomatrixserverlib.RespState, error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "LookupState")
|
return httputil.CallInternalProxyAPI[lookupState, gomatrixserverlib.RespState, *api.FederationClientError](
|
||||||
defer span.Finish()
|
"LookupState", h.federationAPIURL+FederationAPILookupStatePath, h.httpClient,
|
||||||
|
ctx, &lookupState{
|
||||||
request := lookupState{
|
|
||||||
S: s,
|
S: s,
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
EventID: eventID,
|
EventID: eventID,
|
||||||
RoomVersion: roomVersion,
|
RoomVersion: roomVersion,
|
||||||
}
|
},
|
||||||
var response lookupState
|
)
|
||||||
apiURL := h.federationAPIURL + FederationAPILookupStatePath
|
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return gomatrixserverlib.RespState{}, err
|
|
||||||
}
|
|
||||||
if response.Err != nil {
|
|
||||||
return gomatrixserverlib.RespState{}, response.Err
|
|
||||||
}
|
|
||||||
return *response.Res, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type lookupStateIDs struct {
|
type lookupStateIDs struct {
|
||||||
S gomatrixserverlib.ServerName
|
S gomatrixserverlib.ServerName
|
||||||
RoomID string
|
RoomID string
|
||||||
EventID string
|
EventID string
|
||||||
Res *gomatrixserverlib.RespStateIDs
|
|
||||||
Err *api.FederationClientError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) LookupStateIDs(
|
func (h *httpFederationInternalAPI) LookupStateIDs(
|
||||||
ctx context.Context, s gomatrixserverlib.ServerName, roomID, eventID string,
|
ctx context.Context, s gomatrixserverlib.ServerName, roomID, eventID string,
|
||||||
) (gomatrixserverlib.RespStateIDs, error) {
|
) (gomatrixserverlib.RespStateIDs, error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "LookupStateIDs")
|
return httputil.CallInternalProxyAPI[lookupStateIDs, gomatrixserverlib.RespStateIDs, *api.FederationClientError](
|
||||||
defer span.Finish()
|
"LookupStateIDs", h.federationAPIURL+FederationAPILookupStateIDsPath, h.httpClient,
|
||||||
|
ctx, &lookupStateIDs{
|
||||||
request := lookupStateIDs{
|
|
||||||
S: s,
|
S: s,
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
EventID: eventID,
|
EventID: eventID,
|
||||||
}
|
},
|
||||||
var response lookupStateIDs
|
)
|
||||||
apiURL := h.federationAPIURL + FederationAPILookupStateIDsPath
|
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return gomatrixserverlib.RespStateIDs{}, err
|
|
||||||
}
|
|
||||||
if response.Err != nil {
|
|
||||||
return gomatrixserverlib.RespStateIDs{}, response.Err
|
|
||||||
}
|
|
||||||
return *response.Res, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type lookupMissingEvents struct {
|
type lookupMissingEvents struct {
|
||||||
@ -347,64 +267,38 @@ type lookupMissingEvents struct {
|
|||||||
RoomID string
|
RoomID string
|
||||||
Missing gomatrixserverlib.MissingEvents
|
Missing gomatrixserverlib.MissingEvents
|
||||||
RoomVersion gomatrixserverlib.RoomVersion
|
RoomVersion gomatrixserverlib.RoomVersion
|
||||||
Res struct {
|
|
||||||
Events []gomatrixserverlib.RawJSON `json:"events"`
|
|
||||||
}
|
|
||||||
Err *api.FederationClientError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) LookupMissingEvents(
|
func (h *httpFederationInternalAPI) LookupMissingEvents(
|
||||||
ctx context.Context, s gomatrixserverlib.ServerName, roomID string,
|
ctx context.Context, s gomatrixserverlib.ServerName, roomID string,
|
||||||
missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion,
|
missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion,
|
||||||
) (res gomatrixserverlib.RespMissingEvents, err error) {
|
) (res gomatrixserverlib.RespMissingEvents, err error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "LookupMissingEvents")
|
return httputil.CallInternalProxyAPI[lookupMissingEvents, gomatrixserverlib.RespMissingEvents, *api.FederationClientError](
|
||||||
defer span.Finish()
|
"LookupMissingEvents", h.federationAPIURL+FederationAPILookupMissingEventsPath, h.httpClient,
|
||||||
|
ctx, &lookupMissingEvents{
|
||||||
request := lookupMissingEvents{
|
|
||||||
S: s,
|
S: s,
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
Missing: missing,
|
Missing: missing,
|
||||||
RoomVersion: roomVersion,
|
RoomVersion: roomVersion,
|
||||||
}
|
},
|
||||||
apiURL := h.federationAPIURL + FederationAPILookupMissingEventsPath
|
)
|
||||||
err = httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &request)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
if request.Err != nil {
|
|
||||||
return res, request.Err
|
|
||||||
}
|
|
||||||
res.Events = request.Res.Events
|
|
||||||
return res, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type getEvent struct {
|
type getEvent struct {
|
||||||
S gomatrixserverlib.ServerName
|
S gomatrixserverlib.ServerName
|
||||||
EventID string
|
EventID string
|
||||||
Res *gomatrixserverlib.Transaction
|
|
||||||
Err *api.FederationClientError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) GetEvent(
|
func (h *httpFederationInternalAPI) GetEvent(
|
||||||
ctx context.Context, s gomatrixserverlib.ServerName, eventID string,
|
ctx context.Context, s gomatrixserverlib.ServerName, eventID string,
|
||||||
) (gomatrixserverlib.Transaction, error) {
|
) (gomatrixserverlib.Transaction, error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "GetEvent")
|
return httputil.CallInternalProxyAPI[getEvent, gomatrixserverlib.Transaction, *api.FederationClientError](
|
||||||
defer span.Finish()
|
"GetEvent", h.federationAPIURL+FederationAPIGetEventPath, h.httpClient,
|
||||||
|
ctx, &getEvent{
|
||||||
request := getEvent{
|
|
||||||
S: s,
|
S: s,
|
||||||
EventID: eventID,
|
EventID: eventID,
|
||||||
}
|
},
|
||||||
var response getEvent
|
)
|
||||||
apiURL := h.federationAPIURL + FederationAPIGetEventPath
|
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return gomatrixserverlib.Transaction{}, err
|
|
||||||
}
|
|
||||||
if response.Err != nil {
|
|
||||||
return gomatrixserverlib.Transaction{}, response.Err
|
|
||||||
}
|
|
||||||
return *response.Res, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type getEventAuth struct {
|
type getEventAuth struct {
|
||||||
@ -412,135 +306,86 @@ type getEventAuth struct {
|
|||||||
RoomVersion gomatrixserverlib.RoomVersion
|
RoomVersion gomatrixserverlib.RoomVersion
|
||||||
RoomID string
|
RoomID string
|
||||||
EventID string
|
EventID string
|
||||||
Res *gomatrixserverlib.RespEventAuth
|
|
||||||
Err *api.FederationClientError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) GetEventAuth(
|
func (h *httpFederationInternalAPI) GetEventAuth(
|
||||||
ctx context.Context, s gomatrixserverlib.ServerName,
|
ctx context.Context, s gomatrixserverlib.ServerName,
|
||||||
roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string,
|
roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string,
|
||||||
) (gomatrixserverlib.RespEventAuth, error) {
|
) (gomatrixserverlib.RespEventAuth, error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "GetEventAuth")
|
return httputil.CallInternalProxyAPI[getEventAuth, gomatrixserverlib.RespEventAuth, *api.FederationClientError](
|
||||||
defer span.Finish()
|
"GetEventAuth", h.federationAPIURL+FederationAPIGetEventAuthPath, h.httpClient,
|
||||||
|
ctx, &getEventAuth{
|
||||||
request := getEventAuth{
|
|
||||||
S: s,
|
S: s,
|
||||||
RoomVersion: roomVersion,
|
RoomVersion: roomVersion,
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
EventID: eventID,
|
EventID: eventID,
|
||||||
}
|
},
|
||||||
var response getEventAuth
|
)
|
||||||
apiURL := h.federationAPIURL + FederationAPIGetEventAuthPath
|
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return gomatrixserverlib.RespEventAuth{}, err
|
|
||||||
}
|
|
||||||
if response.Err != nil {
|
|
||||||
return gomatrixserverlib.RespEventAuth{}, response.Err
|
|
||||||
}
|
|
||||||
return *response.Res, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) QueryServerKeys(
|
func (h *httpFederationInternalAPI) QueryServerKeys(
|
||||||
ctx context.Context, req *api.QueryServerKeysRequest, res *api.QueryServerKeysResponse,
|
ctx context.Context, req *api.QueryServerKeysRequest, res *api.QueryServerKeysResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryServerKeys")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryServerKeys", h.federationAPIURL+FederationAPIQueryServerKeysPath,
|
||||||
|
h.httpClient, ctx, req, res,
|
||||||
apiURL := h.federationAPIURL + FederationAPIQueryServerKeysPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type lookupServerKeys struct {
|
type lookupServerKeys struct {
|
||||||
S gomatrixserverlib.ServerName
|
S gomatrixserverlib.ServerName
|
||||||
KeyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp
|
KeyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp
|
||||||
ServerKeys []gomatrixserverlib.ServerKeys
|
|
||||||
Err *api.FederationClientError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) LookupServerKeys(
|
func (h *httpFederationInternalAPI) LookupServerKeys(
|
||||||
ctx context.Context, s gomatrixserverlib.ServerName, keyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp,
|
ctx context.Context, s gomatrixserverlib.ServerName, keyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp,
|
||||||
) ([]gomatrixserverlib.ServerKeys, error) {
|
) ([]gomatrixserverlib.ServerKeys, error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "LookupServerKeys")
|
return httputil.CallInternalProxyAPI[lookupServerKeys, []gomatrixserverlib.ServerKeys, *api.FederationClientError](
|
||||||
defer span.Finish()
|
"LookupServerKeys", h.federationAPIURL+FederationAPILookupServerKeysPath, h.httpClient,
|
||||||
|
ctx, &lookupServerKeys{
|
||||||
request := lookupServerKeys{
|
|
||||||
S: s,
|
S: s,
|
||||||
KeyRequests: keyRequests,
|
KeyRequests: keyRequests,
|
||||||
}
|
},
|
||||||
var response lookupServerKeys
|
)
|
||||||
apiURL := h.federationAPIURL + FederationAPILookupServerKeysPath
|
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return []gomatrixserverlib.ServerKeys{}, err
|
|
||||||
}
|
|
||||||
if response.Err != nil {
|
|
||||||
return []gomatrixserverlib.ServerKeys{}, response.Err
|
|
||||||
}
|
|
||||||
return response.ServerKeys, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type eventRelationships struct {
|
type eventRelationships struct {
|
||||||
S gomatrixserverlib.ServerName
|
S gomatrixserverlib.ServerName
|
||||||
Req gomatrixserverlib.MSC2836EventRelationshipsRequest
|
Req gomatrixserverlib.MSC2836EventRelationshipsRequest
|
||||||
RoomVer gomatrixserverlib.RoomVersion
|
RoomVer gomatrixserverlib.RoomVersion
|
||||||
Res gomatrixserverlib.MSC2836EventRelationshipsResponse
|
|
||||||
Err *api.FederationClientError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) MSC2836EventRelationships(
|
func (h *httpFederationInternalAPI) MSC2836EventRelationships(
|
||||||
ctx context.Context, s gomatrixserverlib.ServerName, r gomatrixserverlib.MSC2836EventRelationshipsRequest,
|
ctx context.Context, s gomatrixserverlib.ServerName, r gomatrixserverlib.MSC2836EventRelationshipsRequest,
|
||||||
roomVersion gomatrixserverlib.RoomVersion,
|
roomVersion gomatrixserverlib.RoomVersion,
|
||||||
) (res gomatrixserverlib.MSC2836EventRelationshipsResponse, err error) {
|
) (res gomatrixserverlib.MSC2836EventRelationshipsResponse, err error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "MSC2836EventRelationships")
|
return httputil.CallInternalProxyAPI[eventRelationships, gomatrixserverlib.MSC2836EventRelationshipsResponse, *api.FederationClientError](
|
||||||
defer span.Finish()
|
"MSC2836EventRelationships", h.federationAPIURL+FederationAPIEventRelationshipsPath, h.httpClient,
|
||||||
|
ctx, &eventRelationships{
|
||||||
request := eventRelationships{
|
|
||||||
S: s,
|
S: s,
|
||||||
Req: r,
|
Req: r,
|
||||||
RoomVer: roomVersion,
|
RoomVer: roomVersion,
|
||||||
}
|
},
|
||||||
var response eventRelationships
|
)
|
||||||
apiURL := h.federationAPIURL + FederationAPIEventRelationshipsPath
|
|
||||||
err = httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
if response.Err != nil {
|
|
||||||
return res, response.Err
|
|
||||||
}
|
|
||||||
return response.Res, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type spacesReq struct {
|
type spacesReq struct {
|
||||||
S gomatrixserverlib.ServerName
|
S gomatrixserverlib.ServerName
|
||||||
SuggestedOnly bool
|
SuggestedOnly bool
|
||||||
RoomID string
|
RoomID string
|
||||||
Res gomatrixserverlib.MSC2946SpacesResponse
|
|
||||||
Err *api.FederationClientError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) MSC2946Spaces(
|
func (h *httpFederationInternalAPI) MSC2946Spaces(
|
||||||
ctx context.Context, dst gomatrixserverlib.ServerName, roomID string, suggestedOnly bool,
|
ctx context.Context, dst gomatrixserverlib.ServerName, roomID string, suggestedOnly bool,
|
||||||
) (res gomatrixserverlib.MSC2946SpacesResponse, err error) {
|
) (res gomatrixserverlib.MSC2946SpacesResponse, err error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "MSC2946Spaces")
|
return httputil.CallInternalProxyAPI[spacesReq, gomatrixserverlib.MSC2946SpacesResponse, *api.FederationClientError](
|
||||||
defer span.Finish()
|
"MSC2836EventRelationships", h.federationAPIURL+FederationAPISpacesSummaryPath, h.httpClient,
|
||||||
|
ctx, &spacesReq{
|
||||||
request := spacesReq{
|
|
||||||
S: dst,
|
S: dst,
|
||||||
SuggestedOnly: suggestedOnly,
|
SuggestedOnly: suggestedOnly,
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
}
|
},
|
||||||
var response spacesReq
|
)
|
||||||
apiURL := h.federationAPIURL + FederationAPISpacesSummaryPath
|
|
||||||
err = httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
if response.Err != nil {
|
|
||||||
return res, response.Err
|
|
||||||
}
|
|
||||||
return response.Res, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpFederationInternalAPI) KeyRing() *gomatrixserverlib.KeyRing {
|
func (s *httpFederationInternalAPI) KeyRing() *gomatrixserverlib.KeyRing {
|
||||||
@ -614,11 +459,10 @@ func (h *httpFederationInternalAPI) InputPublicKeys(
|
|||||||
request *api.InputPublicKeysRequest,
|
request *api.InputPublicKeysRequest,
|
||||||
response *api.InputPublicKeysResponse,
|
response *api.InputPublicKeysResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "InputPublicKey")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"InputPublicKey", h.federationAPIURL+FederationAPIInputPublicKeyPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.federationAPIURL + FederationAPIInputPublicKeyPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpFederationInternalAPI) QueryPublicKeys(
|
func (h *httpFederationInternalAPI) QueryPublicKeys(
|
||||||
@ -626,9 +470,8 @@ func (h *httpFederationInternalAPI) QueryPublicKeys(
|
|||||||
request *api.QueryPublicKeysRequest,
|
request *api.QueryPublicKeysRequest,
|
||||||
response *api.QueryPublicKeysResponse,
|
response *api.QueryPublicKeysResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryPublicKey")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryPublicKeys", h.federationAPIURL+FederationAPIQueryPublicKeyPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.federationAPIURL + FederationAPIQueryPublicKeyPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package inthttp
|
package inthttp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/federationapi/api"
|
"github.com/matrix-org/dendrite/federationapi/api"
|
||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,372 +17,180 @@ import (
|
|||||||
func AddRoutes(intAPI api.FederationInternalAPI, internalAPIMux *mux.Router) {
|
func AddRoutes(intAPI api.FederationInternalAPI, internalAPIMux *mux.Router) {
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPIQueryJoinedHostServerNamesInRoomPath,
|
FederationAPIQueryJoinedHostServerNamesInRoomPath,
|
||||||
httputil.MakeInternalAPI("QueryJoinedHostServerNamesInRoom", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("FederationAPIQueryJoinedHostServerNamesInRoom", intAPI.QueryJoinedHostServerNamesInRoom),
|
||||||
var request api.QueryJoinedHostServerNamesInRoomRequest
|
|
||||||
var response api.QueryJoinedHostServerNamesInRoomResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := intAPI.QueryJoinedHostServerNamesInRoom(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(
|
|
||||||
FederationAPIPerformJoinRequestPath,
|
|
||||||
httputil.MakeInternalAPI("PerformJoinRequest", func(req *http.Request) util.JSONResponse {
|
|
||||||
var request api.PerformJoinRequest
|
|
||||||
var response api.PerformJoinResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
intAPI.PerformJoin(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(
|
|
||||||
FederationAPIPerformLeaveRequestPath,
|
|
||||||
httputil.MakeInternalAPI("PerformLeaveRequest", func(req *http.Request) util.JSONResponse {
|
|
||||||
var request api.PerformLeaveRequest
|
|
||||||
var response api.PerformLeaveResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := intAPI.PerformLeave(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPIPerformInviteRequestPath,
|
FederationAPIPerformInviteRequestPath,
|
||||||
httputil.MakeInternalAPI("PerformInviteRequest", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("FederationAPIPerformInvite", intAPI.PerformInvite),
|
||||||
var request api.PerformInviteRequest
|
|
||||||
var response api.PerformInviteResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := intAPI.PerformInvite(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
FederationAPIPerformLeaveRequestPath,
|
||||||
|
httputil.MakeInternalRPCAPI("FederationAPIPerformLeave", intAPI.PerformLeave),
|
||||||
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPIPerformDirectoryLookupRequestPath,
|
FederationAPIPerformDirectoryLookupRequestPath,
|
||||||
httputil.MakeInternalAPI("PerformDirectoryLookupRequest", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("FederationAPIPerformDirectoryLookupRequest", intAPI.PerformDirectoryLookup),
|
||||||
var request api.PerformDirectoryLookupRequest
|
|
||||||
var response api.PerformDirectoryLookupResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := intAPI.PerformDirectoryLookup(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPIPerformBroadcastEDUPath,
|
FederationAPIPerformBroadcastEDUPath,
|
||||||
httputil.MakeInternalAPI("PerformBroadcastEDU", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("FederationAPIPerformBroadcastEDU", intAPI.PerformBroadcastEDU),
|
||||||
var request api.PerformBroadcastEDURequest
|
|
||||||
var response api.PerformBroadcastEDUResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := intAPI.PerformBroadcastEDU(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
FederationAPIPerformJoinRequestPath,
|
||||||
|
httputil.MakeInternalRPCAPI(
|
||||||
|
"FederationAPIPerformJoinRequest",
|
||||||
|
func(ctx context.Context, req *api.PerformJoinRequest, res *api.PerformJoinResponse) error {
|
||||||
|
intAPI.PerformJoin(ctx, req, res)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPIGetUserDevicesPath,
|
FederationAPIGetUserDevicesPath,
|
||||||
httputil.MakeInternalAPI("GetUserDevices", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalProxyAPI(
|
||||||
var request getUserDevices
|
"FederationAPIGetUserDevices",
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
func(ctx context.Context, req *getUserDevices) (*gomatrixserverlib.RespUserDevices, error) {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
res, err := intAPI.GetUserDevices(ctx, req.S, req.UserID)
|
||||||
}
|
return &res, federationClientError(err)
|
||||||
res, err := intAPI.GetUserDevices(req.Context(), request.S, request.UserID)
|
},
|
||||||
if err != nil {
|
),
|
||||||
ferr, ok := err.(*api.FederationClientError)
|
|
||||||
if ok {
|
|
||||||
request.Err = ferr
|
|
||||||
} else {
|
|
||||||
request.Err = &api.FederationClientError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.Res = &res
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: request}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPIClaimKeysPath,
|
FederationAPIClaimKeysPath,
|
||||||
httputil.MakeInternalAPI("ClaimKeys", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalProxyAPI(
|
||||||
var request claimKeys
|
"FederationAPIClaimKeys",
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
func(ctx context.Context, req *claimKeys) (*gomatrixserverlib.RespClaimKeys, error) {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
res, err := intAPI.ClaimKeys(ctx, req.S, req.OneTimeKeys)
|
||||||
}
|
return &res, federationClientError(err)
|
||||||
res, err := intAPI.ClaimKeys(req.Context(), request.S, request.OneTimeKeys)
|
},
|
||||||
if err != nil {
|
),
|
||||||
ferr, ok := err.(*api.FederationClientError)
|
|
||||||
if ok {
|
|
||||||
request.Err = ferr
|
|
||||||
} else {
|
|
||||||
request.Err = &api.FederationClientError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.Res = &res
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: request}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPIQueryKeysPath,
|
FederationAPIQueryKeysPath,
|
||||||
httputil.MakeInternalAPI("QueryKeys", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalProxyAPI(
|
||||||
var request queryKeys
|
"FederationAPIQueryKeys",
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
func(ctx context.Context, req *queryKeys) (*gomatrixserverlib.RespQueryKeys, error) {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
res, err := intAPI.QueryKeys(ctx, req.S, req.Keys)
|
||||||
}
|
return &res, federationClientError(err)
|
||||||
res, err := intAPI.QueryKeys(req.Context(), request.S, request.Keys)
|
},
|
||||||
if err != nil {
|
),
|
||||||
ferr, ok := err.(*api.FederationClientError)
|
|
||||||
if ok {
|
|
||||||
request.Err = ferr
|
|
||||||
} else {
|
|
||||||
request.Err = &api.FederationClientError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.Res = &res
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: request}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPIBackfillPath,
|
FederationAPIBackfillPath,
|
||||||
httputil.MakeInternalAPI("Backfill", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalProxyAPI(
|
||||||
var request backfill
|
"FederationAPIBackfill",
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
func(ctx context.Context, req *backfill) (*gomatrixserverlib.Transaction, error) {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
res, err := intAPI.Backfill(ctx, req.S, req.RoomID, req.Limit, req.EventIDs)
|
||||||
}
|
return &res, federationClientError(err)
|
||||||
res, err := intAPI.Backfill(req.Context(), request.S, request.RoomID, request.Limit, request.EventIDs)
|
},
|
||||||
if err != nil {
|
),
|
||||||
ferr, ok := err.(*api.FederationClientError)
|
|
||||||
if ok {
|
|
||||||
request.Err = ferr
|
|
||||||
} else {
|
|
||||||
request.Err = &api.FederationClientError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.Res = &res
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: request}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPILookupStatePath,
|
FederationAPILookupStatePath,
|
||||||
httputil.MakeInternalAPI("LookupState", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalProxyAPI(
|
||||||
var request lookupState
|
"FederationAPILookupState",
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
func(ctx context.Context, req *lookupState) (*gomatrixserverlib.RespState, error) {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
res, err := intAPI.LookupState(ctx, req.S, req.RoomID, req.EventID, req.RoomVersion)
|
||||||
}
|
return &res, federationClientError(err)
|
||||||
res, err := intAPI.LookupState(req.Context(), request.S, request.RoomID, request.EventID, request.RoomVersion)
|
},
|
||||||
if err != nil {
|
),
|
||||||
ferr, ok := err.(*api.FederationClientError)
|
|
||||||
if ok {
|
|
||||||
request.Err = ferr
|
|
||||||
} else {
|
|
||||||
request.Err = &api.FederationClientError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.Res = &res
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: request}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPILookupStateIDsPath,
|
FederationAPILookupStateIDsPath,
|
||||||
httputil.MakeInternalAPI("LookupStateIDs", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalProxyAPI(
|
||||||
var request lookupStateIDs
|
"FederationAPILookupStateIDs",
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
func(ctx context.Context, req *lookupStateIDs) (*gomatrixserverlib.RespStateIDs, error) {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
res, err := intAPI.LookupStateIDs(ctx, req.S, req.RoomID, req.EventID)
|
||||||
}
|
return &res, federationClientError(err)
|
||||||
res, err := intAPI.LookupStateIDs(req.Context(), request.S, request.RoomID, request.EventID)
|
},
|
||||||
if err != nil {
|
),
|
||||||
ferr, ok := err.(*api.FederationClientError)
|
|
||||||
if ok {
|
|
||||||
request.Err = ferr
|
|
||||||
} else {
|
|
||||||
request.Err = &api.FederationClientError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.Res = &res
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: request}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPILookupMissingEventsPath,
|
FederationAPILookupMissingEventsPath,
|
||||||
httputil.MakeInternalAPI("LookupMissingEvents", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalProxyAPI(
|
||||||
var request lookupMissingEvents
|
"FederationAPILookupMissingEvents",
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
func(ctx context.Context, req *lookupMissingEvents) (*gomatrixserverlib.RespMissingEvents, error) {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
res, err := intAPI.LookupMissingEvents(ctx, req.S, req.RoomID, req.Missing, req.RoomVersion)
|
||||||
}
|
return &res, federationClientError(err)
|
||||||
res, err := intAPI.LookupMissingEvents(req.Context(), request.S, request.RoomID, request.Missing, request.RoomVersion)
|
},
|
||||||
if err != nil {
|
),
|
||||||
ferr, ok := err.(*api.FederationClientError)
|
|
||||||
if ok {
|
|
||||||
request.Err = ferr
|
|
||||||
} else {
|
|
||||||
request.Err = &api.FederationClientError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, event := range res.Events {
|
|
||||||
js, err := json.Marshal(event)
|
|
||||||
if err != nil {
|
|
||||||
return util.MessageResponse(http.StatusInternalServerError, err.Error())
|
|
||||||
}
|
|
||||||
request.Res.Events = append(request.Res.Events, js)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: request}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPIGetEventPath,
|
FederationAPIGetEventPath,
|
||||||
httputil.MakeInternalAPI("GetEvent", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalProxyAPI(
|
||||||
var request getEvent
|
"FederationAPIGetEvent",
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
func(ctx context.Context, req *getEvent) (*gomatrixserverlib.Transaction, error) {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
res, err := intAPI.GetEvent(ctx, req.S, req.EventID)
|
||||||
}
|
return &res, federationClientError(err)
|
||||||
res, err := intAPI.GetEvent(req.Context(), request.S, request.EventID)
|
},
|
||||||
if err != nil {
|
),
|
||||||
ferr, ok := err.(*api.FederationClientError)
|
|
||||||
if ok {
|
|
||||||
request.Err = ferr
|
|
||||||
} else {
|
|
||||||
request.Err = &api.FederationClientError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.Res = &res
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: request}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPIGetEventAuthPath,
|
FederationAPIGetEventAuthPath,
|
||||||
httputil.MakeInternalAPI("GetEventAuth", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalProxyAPI(
|
||||||
var request getEventAuth
|
"FederationAPIGetEventAuth",
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
func(ctx context.Context, req *getEventAuth) (*gomatrixserverlib.RespEventAuth, error) {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
res, err := intAPI.GetEventAuth(ctx, req.S, req.RoomVersion, req.RoomID, req.EventID)
|
||||||
}
|
return &res, federationClientError(err)
|
||||||
res, err := intAPI.GetEventAuth(req.Context(), request.S, request.RoomVersion, request.RoomID, request.EventID)
|
},
|
||||||
if err != nil {
|
),
|
||||||
ferr, ok := err.(*api.FederationClientError)
|
|
||||||
if ok {
|
|
||||||
request.Err = ferr
|
|
||||||
} else {
|
|
||||||
request.Err = &api.FederationClientError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.Res = &res
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: request}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPIQueryServerKeysPath,
|
FederationAPIQueryServerKeysPath,
|
||||||
httputil.MakeInternalAPI("QueryServerKeys", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("FederationAPIQueryServerKeys", intAPI.QueryServerKeys),
|
||||||
var request api.QueryServerKeysRequest
|
|
||||||
var response api.QueryServerKeysResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := intAPI.QueryServerKeys(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPILookupServerKeysPath,
|
FederationAPILookupServerKeysPath,
|
||||||
httputil.MakeInternalAPI("LookupServerKeys", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalProxyAPI(
|
||||||
var request lookupServerKeys
|
"FederationAPILookupServerKeys",
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
func(ctx context.Context, req *lookupServerKeys) (*[]gomatrixserverlib.ServerKeys, error) {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
res, err := intAPI.LookupServerKeys(ctx, req.S, req.KeyRequests)
|
||||||
}
|
return &res, federationClientError(err)
|
||||||
res, err := intAPI.LookupServerKeys(req.Context(), request.S, request.KeyRequests)
|
},
|
||||||
if err != nil {
|
),
|
||||||
ferr, ok := err.(*api.FederationClientError)
|
|
||||||
if ok {
|
|
||||||
request.Err = ferr
|
|
||||||
} else {
|
|
||||||
request.Err = &api.FederationClientError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.ServerKeys = res
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: request}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPIEventRelationshipsPath,
|
FederationAPIEventRelationshipsPath,
|
||||||
httputil.MakeInternalAPI("MSC2836EventRelationships", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalProxyAPI(
|
||||||
var request eventRelationships
|
"FederationAPIMSC2836EventRelationships",
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
func(ctx context.Context, req *eventRelationships) (*gomatrixserverlib.MSC2836EventRelationshipsResponse, error) {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
res, err := intAPI.MSC2836EventRelationships(ctx, req.S, req.Req, req.RoomVer)
|
||||||
}
|
return &res, federationClientError(err)
|
||||||
res, err := intAPI.MSC2836EventRelationships(req.Context(), request.S, request.Req, request.RoomVer)
|
},
|
||||||
if err != nil {
|
),
|
||||||
ferr, ok := err.(*api.FederationClientError)
|
|
||||||
if ok {
|
|
||||||
request.Err = ferr
|
|
||||||
} else {
|
|
||||||
request.Err = &api.FederationClientError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.Res = res
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: request}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
FederationAPISpacesSummaryPath,
|
FederationAPISpacesSummaryPath,
|
||||||
httputil.MakeInternalAPI("MSC2946SpacesSummary", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalProxyAPI(
|
||||||
var request spacesReq
|
"FederationAPIMSC2946SpacesSummary",
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
func(ctx context.Context, req *spacesReq) (*gomatrixserverlib.MSC2946SpacesResponse, error) {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
res, err := intAPI.MSC2946Spaces(ctx, req.S, req.RoomID, req.SuggestedOnly)
|
||||||
}
|
return &res, federationClientError(err)
|
||||||
res, err := intAPI.MSC2946Spaces(req.Context(), request.S, request.RoomID, request.SuggestedOnly)
|
},
|
||||||
if err != nil {
|
),
|
||||||
ferr, ok := err.(*api.FederationClientError)
|
|
||||||
if ok {
|
|
||||||
request.Err = ferr
|
|
||||||
} else {
|
|
||||||
request.Err = &api.FederationClientError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.Res = res
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: request}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: Look at this shape
|
||||||
internalAPIMux.Handle(FederationAPIQueryPublicKeyPath,
|
internalAPIMux.Handle(FederationAPIQueryPublicKeyPath,
|
||||||
httputil.MakeInternalAPI("queryPublicKeys", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalAPI("FederationAPIQueryPublicKeys", func(req *http.Request) util.JSONResponse {
|
||||||
request := api.QueryPublicKeysRequest{}
|
request := api.QueryPublicKeysRequest{}
|
||||||
response := api.QueryPublicKeysResponse{}
|
response := api.QueryPublicKeysResponse{}
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
@ -394,8 +204,10 @@ func AddRoutes(intAPI api.FederationInternalAPI, internalAPIMux *mux.Router) {
|
|||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: Look at this shape
|
||||||
internalAPIMux.Handle(FederationAPIInputPublicKeyPath,
|
internalAPIMux.Handle(FederationAPIInputPublicKeyPath,
|
||||||
httputil.MakeInternalAPI("inputPublicKeys", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalAPI("FederationAPIInputPublicKeys", func(req *http.Request) util.JSONResponse {
|
||||||
request := api.InputPublicKeysRequest{}
|
request := api.InputPublicKeysRequest{}
|
||||||
response := api.InputPublicKeysResponse{}
|
response := api.InputPublicKeysResponse{}
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
@ -408,3 +220,18 @@ func AddRoutes(intAPI api.FederationInternalAPI, internalAPIMux *mux.Router) {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func federationClientError(err error) error {
|
||||||
|
switch ferr := err.(type) {
|
||||||
|
case nil:
|
||||||
|
return nil
|
||||||
|
case api.FederationClientError:
|
||||||
|
return &ferr
|
||||||
|
case *api.FederationClientError:
|
||||||
|
return ferr
|
||||||
|
default:
|
||||||
|
return &api.FederationClientError{
|
||||||
|
Err: err.Error(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -30,9 +30,11 @@ func GetUserDevices(
|
|||||||
userID string,
|
userID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var res keyapi.QueryDeviceMessagesResponse
|
var res keyapi.QueryDeviceMessagesResponse
|
||||||
keyAPI.QueryDeviceMessages(req.Context(), &keyapi.QueryDeviceMessagesRequest{
|
if err := keyAPI.QueryDeviceMessages(req.Context(), &keyapi.QueryDeviceMessagesRequest{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
}, &res)
|
}, &res); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
util.GetLogger(req.Context()).WithError(res.Error).Error("keyAPI.QueryDeviceMessages failed")
|
util.GetLogger(req.Context()).WithError(res.Error).Error("keyAPI.QueryDeviceMessages failed")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
@ -47,7 +49,9 @@ func GetUserDevices(
|
|||||||
for _, dev := range res.Devices {
|
for _, dev := range res.Devices {
|
||||||
sigReq.TargetIDs[userID] = append(sigReq.TargetIDs[userID], gomatrixserverlib.KeyID(dev.DeviceID))
|
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{
|
response := gomatrixserverlib.RespUserDevices{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
|
@ -392,7 +392,7 @@ func SendJoin(
|
|||||||
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
||||||
if !alreadyJoined {
|
if !alreadyJoined {
|
||||||
var response api.InputRoomEventsResponse
|
var response api.InputRoomEventsResponse
|
||||||
rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
|
if err := rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
|
||||||
InputRoomEvents: []api.InputRoomEvent{
|
InputRoomEvents: []api.InputRoomEvent{
|
||||||
{
|
{
|
||||||
Kind: api.KindNew,
|
Kind: api.KindNew,
|
||||||
@ -401,7 +401,9 @@ func SendJoin(
|
|||||||
TransactionID: nil,
|
TransactionID: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, &response)
|
}, &response); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(httpReq.Context(), err)
|
||||||
|
}
|
||||||
if response.ErrMsg != "" {
|
if response.ErrMsg != "" {
|
||||||
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, response.ErrMsg).Error("SendEvents failed")
|
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, response.ErrMsg).Error("SendEvents failed")
|
||||||
if response.NotAllowed {
|
if response.NotAllowed {
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
clienthttputil "github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
|
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
|
||||||
"github.com/matrix-org/dendrite/keyserver/api"
|
"github.com/matrix-org/dendrite/keyserver/api"
|
||||||
@ -61,9 +61,11 @@ func QueryDeviceKeys(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var queryRes api.QueryKeysResponse
|
var queryRes api.QueryKeysResponse
|
||||||
keyAPI.QueryKeys(httpReq.Context(), &api.QueryKeysRequest{
|
if err := keyAPI.QueryKeys(httpReq.Context(), &api.QueryKeysRequest{
|
||||||
UserToDevices: qkr.DeviceKeys,
|
UserToDevices: qkr.DeviceKeys,
|
||||||
}, &queryRes)
|
}, &queryRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(httpReq.Context(), err)
|
||||||
|
}
|
||||||
if queryRes.Error != nil {
|
if queryRes.Error != nil {
|
||||||
util.GetLogger(httpReq.Context()).WithError(queryRes.Error).Error("Failed to QueryKeys")
|
util.GetLogger(httpReq.Context()).WithError(queryRes.Error).Error("Failed to QueryKeys")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
@ -113,9 +115,11 @@ func ClaimOneTimeKeys(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var claimRes api.PerformClaimKeysResponse
|
var claimRes api.PerformClaimKeysResponse
|
||||||
keyAPI.PerformClaimKeys(httpReq.Context(), &api.PerformClaimKeysRequest{
|
if err := keyAPI.PerformClaimKeys(httpReq.Context(), &api.PerformClaimKeysRequest{
|
||||||
OneTimeKeys: cor.OneTimeKeys,
|
OneTimeKeys: cor.OneTimeKeys,
|
||||||
}, &claimRes)
|
}, &claimRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(httpReq.Context(), err)
|
||||||
|
}
|
||||||
if claimRes.Error != nil {
|
if claimRes.Error != nil {
|
||||||
util.GetLogger(httpReq.Context()).WithError(claimRes.Error).Error("Failed to PerformClaimKeys")
|
util.GetLogger(httpReq.Context()).WithError(claimRes.Error).Error("Failed to PerformClaimKeys")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
@ -184,7 +188,7 @@ func NotaryKeys(
|
|||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
if req == nil {
|
if req == nil {
|
||||||
req = &gomatrixserverlib.PublicKeyNotaryLookupRequest{}
|
req = &gomatrixserverlib.PublicKeyNotaryLookupRequest{}
|
||||||
if reqErr := httputil.UnmarshalJSONRequest(httpReq, &req); reqErr != nil {
|
if reqErr := clienthttputil.UnmarshalJSONRequest(httpReq, &req); reqErr != nil {
|
||||||
return *reqErr
|
return *reqErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,7 +277,7 @@ func SendLeave(
|
|||||||
// We are responsible for notifying other servers that the user has left
|
// We are responsible for notifying other servers that the user has left
|
||||||
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
||||||
var response api.InputRoomEventsResponse
|
var response api.InputRoomEventsResponse
|
||||||
rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
|
if err := rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
|
||||||
InputRoomEvents: []api.InputRoomEvent{
|
InputRoomEvents: []api.InputRoomEvent{
|
||||||
{
|
{
|
||||||
Kind: api.KindNew,
|
Kind: api.KindNew,
|
||||||
@ -286,7 +286,9 @@ func SendLeave(
|
|||||||
TransactionID: nil,
|
TransactionID: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, &response)
|
}, &response); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(httpReq.Context(), err)
|
||||||
|
}
|
||||||
|
|
||||||
if response.ErrMsg != "" {
|
if response.ErrMsg != "" {
|
||||||
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, response.ErrMsg).WithField("not_allowed", response.NotAllowed).Error("producer.SendEvents failed")
|
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, response.ErrMsg).WithField("not_allowed", response.NotAllowed).Error("producer.SendEvents failed")
|
||||||
|
@ -458,7 +458,9 @@ func (t *txnReq) processSigningKeyUpdate(ctx context.Context, e gomatrixserverli
|
|||||||
UserID: updatePayload.UserID,
|
UserID: updatePayload.UserID,
|
||||||
}
|
}
|
||||||
uploadRes := &keyapi.PerformUploadDeviceKeysResponse{}
|
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 {
|
if uploadRes.Error != nil {
|
||||||
return uploadRes.Error
|
return uploadRes.Error
|
||||||
}
|
}
|
||||||
|
@ -64,11 +64,12 @@ func (t *testRoomserverAPI) InputRoomEvents(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.InputRoomEventsRequest,
|
request *api.InputRoomEventsRequest,
|
||||||
response *api.InputRoomEventsResponse,
|
response *api.InputRoomEventsResponse,
|
||||||
) {
|
) error {
|
||||||
t.inputRoomEvents = append(t.inputRoomEvents, request.InputRoomEvents...)
|
t.inputRoomEvents = append(t.inputRoomEvents, request.InputRoomEvents...)
|
||||||
for _, ire := range request.InputRoomEvents {
|
for _, ire := range request.InputRoomEvents {
|
||||||
fmt.Println("InputRoomEvents: ", ire.Event.EventID())
|
fmt.Println("InputRoomEvents: ", ire.Event.EventID())
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the latest events and state for a room from the room server.
|
// Query the latest events and state for a room from the room server.
|
||||||
|
@ -19,19 +19,21 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
|
||||||
opentracing "github.com/opentracing/opentracing-go"
|
opentracing "github.com/opentracing/opentracing-go"
|
||||||
"github.com/opentracing/opentracing-go/ext"
|
"github.com/opentracing/opentracing-go/ext"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PostJSON performs a POST request with JSON on an internal HTTP API
|
// PostJSON performs a POST request with JSON on an internal HTTP API.
|
||||||
func PostJSON(
|
// The error will match the errtype if returned from the remote API, or
|
||||||
|
// will be a different type if there was a problem reaching the API.
|
||||||
|
func PostJSON[reqtype, restype any, errtype error](
|
||||||
ctx context.Context, span opentracing.Span, httpClient *http.Client,
|
ctx context.Context, span opentracing.Span, httpClient *http.Client,
|
||||||
apiURL string, request, response interface{},
|
apiURL string, request *reqtype, response *restype,
|
||||||
) error {
|
) error {
|
||||||
jsonBytes, err := json.Marshal(request)
|
jsonBytes, err := json.Marshal(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -69,17 +71,23 @@ func PostJSON(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if res.StatusCode != http.StatusOK {
|
var body []byte
|
||||||
var errorBody struct {
|
body, err = io.ReadAll(res.Body)
|
||||||
Message string `json:"message"`
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if res.StatusCode != http.StatusOK {
|
||||||
|
if len(body) == 0 {
|
||||||
|
return fmt.Errorf("HTTP %d from %s (no response body)", res.StatusCode, apiURL)
|
||||||
|
}
|
||||||
|
var reserr errtype
|
||||||
|
if err = json.Unmarshal(body, reserr); err != nil {
|
||||||
|
return fmt.Errorf("HTTP %d from %s", res.StatusCode, apiURL)
|
||||||
|
}
|
||||||
|
return reserr
|
||||||
|
}
|
||||||
|
if err = json.Unmarshal(body, response); err != nil {
|
||||||
|
return fmt.Errorf("json.Unmarshal: %w", err)
|
||||||
}
|
}
|
||||||
if _, ok := response.(*api.PerformKeyBackupResponse); ok { // TODO: remove this, once cross-boundary errors are a thing
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if msgerr := json.NewDecoder(res.Body).Decode(&errorBody); msgerr == nil {
|
|
||||||
return fmt.Errorf("internal API: %d from %s: %s", res.StatusCode, apiURL, errorBody.Message)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("internal API: %d from %s", res.StatusCode, apiURL)
|
|
||||||
}
|
|
||||||
return json.NewDecoder(res.Body).Decode(response)
|
|
||||||
}
|
|
||||||
|
93
internal/httputil/internalapi.go
Normal file
93
internal/httputil/internalapi.go
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
// Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package httputil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/matrix-org/util"
|
||||||
|
opentracing "github.com/opentracing/opentracing-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
type InternalAPIError struct {
|
||||||
|
Type string
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e InternalAPIError) Error() string {
|
||||||
|
return fmt.Sprintf("internal API returned %q error: %s", e.Type, e.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeInternalRPCAPI[reqtype, restype any](metricsName string, f func(context.Context, *reqtype, *restype) error) http.Handler {
|
||||||
|
return MakeInternalAPI(metricsName, func(req *http.Request) util.JSONResponse {
|
||||||
|
var request reqtype
|
||||||
|
var response restype
|
||||||
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||||
|
}
|
||||||
|
if err := f(req.Context(), &request, &response); err != nil {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusInternalServerError,
|
||||||
|
JSON: &InternalAPIError{
|
||||||
|
Type: reflect.TypeOf(err).String(),
|
||||||
|
Message: fmt.Sprintf("%s", err),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
JSON: &response,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeInternalProxyAPI[reqtype, restype any](metricsName string, f func(context.Context, *reqtype) (*restype, error)) http.Handler {
|
||||||
|
return MakeInternalAPI(metricsName, func(req *http.Request) util.JSONResponse {
|
||||||
|
var request reqtype
|
||||||
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||||
|
}
|
||||||
|
response, err := f(req.Context(), &request)
|
||||||
|
if err != nil {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusInternalServerError,
|
||||||
|
JSON: err,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
JSON: response,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func CallInternalRPCAPI[reqtype, restype any](name, url string, client *http.Client, ctx context.Context, request *reqtype, response *restype) error {
|
||||||
|
span, ctx := opentracing.StartSpanFromContext(ctx, name)
|
||||||
|
defer span.Finish()
|
||||||
|
|
||||||
|
return PostJSON[reqtype, restype, InternalAPIError](ctx, span, client, url, request, response)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CallInternalProxyAPI[reqtype, restype any, errtype error](name, url string, client *http.Client, ctx context.Context, request *reqtype) (restype, error) {
|
||||||
|
span, ctx := opentracing.StartSpanFromContext(ctx, name)
|
||||||
|
defer span.Finish()
|
||||||
|
|
||||||
|
var response restype
|
||||||
|
return response, PostJSON[reqtype, restype, errtype](ctx, span, client, url, request, &response)
|
||||||
|
}
|
@ -38,32 +38,32 @@ type KeyInternalAPI interface {
|
|||||||
|
|
||||||
// API functions required by the clientapi
|
// API functions required by the clientapi
|
||||||
type ClientKeyAPI interface {
|
type ClientKeyAPI interface {
|
||||||
QueryKeys(ctx context.Context, req *QueryKeysRequest, res *QueryKeysResponse)
|
QueryKeys(ctx context.Context, req *QueryKeysRequest, res *QueryKeysResponse) error
|
||||||
PerformUploadKeys(ctx context.Context, req *PerformUploadKeysRequest, res *PerformUploadKeysResponse)
|
PerformUploadKeys(ctx context.Context, req *PerformUploadKeysRequest, res *PerformUploadKeysResponse) error
|
||||||
PerformUploadDeviceKeys(ctx context.Context, req *PerformUploadDeviceKeysRequest, res *PerformUploadDeviceKeysResponse)
|
PerformUploadDeviceKeys(ctx context.Context, req *PerformUploadDeviceKeysRequest, res *PerformUploadDeviceKeysResponse) error
|
||||||
PerformUploadDeviceSignatures(ctx context.Context, req *PerformUploadDeviceSignaturesRequest, res *PerformUploadDeviceSignaturesResponse)
|
PerformUploadDeviceSignatures(ctx context.Context, req *PerformUploadDeviceSignaturesRequest, res *PerformUploadDeviceSignaturesResponse) error
|
||||||
// PerformClaimKeys claims one-time keys for use in pre-key messages
|
// PerformClaimKeys claims one-time keys for use in pre-key messages
|
||||||
PerformClaimKeys(ctx context.Context, req *PerformClaimKeysRequest, res *PerformClaimKeysResponse)
|
PerformClaimKeys(ctx context.Context, req *PerformClaimKeysRequest, res *PerformClaimKeysResponse) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// API functions required by the userapi
|
// API functions required by the userapi
|
||||||
type UserKeyAPI interface {
|
type UserKeyAPI interface {
|
||||||
PerformUploadKeys(ctx context.Context, req *PerformUploadKeysRequest, res *PerformUploadKeysResponse)
|
PerformUploadKeys(ctx context.Context, req *PerformUploadKeysRequest, res *PerformUploadKeysResponse) error
|
||||||
PerformDeleteKeys(ctx context.Context, req *PerformDeleteKeysRequest, res *PerformDeleteKeysResponse)
|
PerformDeleteKeys(ctx context.Context, req *PerformDeleteKeysRequest, res *PerformDeleteKeysResponse) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// API functions required by the syncapi
|
// API functions required by the syncapi
|
||||||
type SyncKeyAPI interface {
|
type SyncKeyAPI interface {
|
||||||
QueryKeyChanges(ctx context.Context, req *QueryKeyChangesRequest, res *QueryKeyChangesResponse)
|
QueryKeyChanges(ctx context.Context, req *QueryKeyChangesRequest, res *QueryKeyChangesResponse) error
|
||||||
QueryOneTimeKeys(ctx context.Context, req *QueryOneTimeKeysRequest, res *QueryOneTimeKeysResponse)
|
QueryOneTimeKeys(ctx context.Context, req *QueryOneTimeKeysRequest, res *QueryOneTimeKeysResponse) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type FederationKeyAPI interface {
|
type FederationKeyAPI interface {
|
||||||
QueryKeys(ctx context.Context, req *QueryKeysRequest, res *QueryKeysResponse)
|
QueryKeys(ctx context.Context, req *QueryKeysRequest, res *QueryKeysResponse) error
|
||||||
QuerySignatures(ctx context.Context, req *QuerySignaturesRequest, res *QuerySignaturesResponse)
|
QuerySignatures(ctx context.Context, req *QuerySignaturesRequest, res *QuerySignaturesResponse) error
|
||||||
QueryDeviceMessages(ctx context.Context, req *QueryDeviceMessagesRequest, res *QueryDeviceMessagesResponse)
|
QueryDeviceMessages(ctx context.Context, req *QueryDeviceMessagesRequest, res *QueryDeviceMessagesResponse) error
|
||||||
PerformUploadDeviceKeys(ctx context.Context, req *PerformUploadDeviceKeysRequest, res *PerformUploadDeviceKeysResponse)
|
PerformUploadDeviceKeys(ctx context.Context, req *PerformUploadDeviceKeysRequest, res *PerformUploadDeviceKeysResponse) error
|
||||||
PerformClaimKeys(ctx context.Context, req *PerformClaimKeysRequest, res *PerformClaimKeysResponse)
|
PerformClaimKeys(ctx context.Context, req *PerformClaimKeysRequest, res *PerformClaimKeysResponse) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyError is returned if there was a problem performing/querying the server
|
// KeyError is returned if there was a problem performing/querying the server
|
||||||
|
@ -103,7 +103,7 @@ func sanityCheckKey(key gomatrixserverlib.CrossSigningKey, userID string, purpos
|
|||||||
}
|
}
|
||||||
|
|
||||||
// nolint:gocyclo
|
// nolint:gocyclo
|
||||||
func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.PerformUploadDeviceKeysRequest, res *api.PerformUploadDeviceKeysResponse) {
|
func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.PerformUploadDeviceKeysRequest, res *api.PerformUploadDeviceKeysResponse) error {
|
||||||
// Find the keys to store.
|
// Find the keys to store.
|
||||||
byPurpose := map[gomatrixserverlib.CrossSigningKeyPurpose]gomatrixserverlib.CrossSigningKey{}
|
byPurpose := map[gomatrixserverlib.CrossSigningKeyPurpose]gomatrixserverlib.CrossSigningKey{}
|
||||||
toStore := types.CrossSigningKeyMap{}
|
toStore := types.CrossSigningKeyMap{}
|
||||||
@ -115,7 +115,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
|||||||
Err: "Master key sanity check failed: " + err.Error(),
|
Err: "Master key sanity check failed: " + err.Error(),
|
||||||
IsInvalidParam: true,
|
IsInvalidParam: true,
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
byPurpose[gomatrixserverlib.CrossSigningKeyPurposeMaster] = req.MasterKey
|
byPurpose[gomatrixserverlib.CrossSigningKeyPurposeMaster] = req.MasterKey
|
||||||
@ -131,7 +131,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
|||||||
Err: "Self-signing key sanity check failed: " + err.Error(),
|
Err: "Self-signing key sanity check failed: " + err.Error(),
|
||||||
IsInvalidParam: true,
|
IsInvalidParam: true,
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
byPurpose[gomatrixserverlib.CrossSigningKeyPurposeSelfSigning] = req.SelfSigningKey
|
byPurpose[gomatrixserverlib.CrossSigningKeyPurposeSelfSigning] = req.SelfSigningKey
|
||||||
@ -146,7 +146,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
|||||||
Err: "User-signing key sanity check failed: " + err.Error(),
|
Err: "User-signing key sanity check failed: " + err.Error(),
|
||||||
IsInvalidParam: true,
|
IsInvalidParam: true,
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
byPurpose[gomatrixserverlib.CrossSigningKeyPurposeUserSigning] = req.UserSigningKey
|
byPurpose[gomatrixserverlib.CrossSigningKeyPurposeUserSigning] = req.UserSigningKey
|
||||||
@ -161,7 +161,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
|||||||
Err: "No keys were supplied in the request",
|
Err: "No keys were supplied in the request",
|
||||||
IsMissingParam: true,
|
IsMissingParam: true,
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can't have a self-signing or user-signing key without a master
|
// We can't have a self-signing or user-signing key without a master
|
||||||
@ -174,7 +174,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
|||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: "Retrieving cross-signing keys from database failed: " + err.Error(),
|
Err: "Retrieving cross-signing keys from database failed: " + err.Error(),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we still can't find a master key for the user then stop the upload.
|
// If we still can't find a master key for the user then stop the upload.
|
||||||
@ -185,7 +185,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
|||||||
Err: "No master key was found",
|
Err: "No master key was found",
|
||||||
IsMissingParam: true,
|
IsMissingParam: true,
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !changed {
|
if !changed {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the keys.
|
// Store the keys.
|
||||||
@ -220,7 +220,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
|||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: fmt.Sprintf("a.DB.StoreCrossSigningKeysForUser: %s", err),
|
Err: fmt.Sprintf("a.DB.StoreCrossSigningKeysForUser: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now upload any signatures that were included with the keys.
|
// Now upload any signatures that were included with the keys.
|
||||||
@ -238,7 +238,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
|||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: fmt.Sprintf("a.DB.StoreCrossSigningSigsForTarget: %s", err),
|
Err: fmt.Sprintf("a.DB.StoreCrossSigningSigsForTarget: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,17 +255,18 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
|||||||
update.SelfSigningKey = &ssk
|
update.SelfSigningKey = &ssk
|
||||||
}
|
}
|
||||||
if update.MasterKey == nil && update.SelfSigningKey == nil {
|
if update.MasterKey == nil && update.SelfSigningKey == nil {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if err := a.Producer.ProduceSigningKeyUpdate(update); err != nil {
|
if err := a.Producer.ProduceSigningKeyUpdate(update); err != nil {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: fmt.Sprintf("a.Producer.ProduceSigningKeyUpdate: %s", err),
|
Err: fmt.Sprintf("a.Producer.ProduceSigningKeyUpdate: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req *api.PerformUploadDeviceSignaturesRequest, res *api.PerformUploadDeviceSignaturesResponse) {
|
func (a *KeyInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req *api.PerformUploadDeviceSignaturesRequest, res *api.PerformUploadDeviceSignaturesResponse) error {
|
||||||
// Before we do anything, we need the master and self-signing keys for this user.
|
// Before we do anything, we need the master and self-signing keys for this user.
|
||||||
// Then we can verify the signatures make sense.
|
// Then we can verify the signatures make sense.
|
||||||
queryReq := &api.QueryKeysRequest{
|
queryReq := &api.QueryKeysRequest{
|
||||||
@ -276,7 +277,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req
|
|||||||
for userID := range req.Signatures {
|
for userID := range req.Signatures {
|
||||||
queryReq.UserToDevices[userID] = []string{}
|
queryReq.UserToDevices[userID] = []string{}
|
||||||
}
|
}
|
||||||
a.QueryKeys(ctx, queryReq, queryRes)
|
_ = a.QueryKeys(ctx, queryReq, queryRes)
|
||||||
|
|
||||||
selfSignatures := map[string]map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice{}
|
selfSignatures := map[string]map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice{}
|
||||||
otherSignatures := map[string]map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice{}
|
otherSignatures := map[string]map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice{}
|
||||||
@ -322,14 +323,14 @@ func (a *KeyInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req
|
|||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: fmt.Sprintf("a.processSelfSignatures: %s", err),
|
Err: fmt.Sprintf("a.processSelfSignatures: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := a.processOtherSignatures(ctx, req.UserID, queryRes, otherSignatures); err != nil {
|
if err := a.processOtherSignatures(ctx, req.UserID, queryRes, otherSignatures); err != nil {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: fmt.Sprintf("a.processOtherSignatures: %s", err),
|
Err: fmt.Sprintf("a.processOtherSignatures: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, generate a notification that we updated the signatures.
|
// Finally, generate a notification that we updated the signatures.
|
||||||
@ -345,9 +346,10 @@ func (a *KeyInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req
|
|||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: fmt.Sprintf("a.Producer.ProduceSigningKeyUpdate: %s", err),
|
Err: fmt.Sprintf("a.Producer.ProduceSigningKeyUpdate: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) processSelfSignatures(
|
func (a *KeyInternalAPI) processSelfSignatures(
|
||||||
@ -520,7 +522,7 @@ func (a *KeyInternalAPI) crossSigningKeysFromDatabase(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) QuerySignatures(ctx context.Context, req *api.QuerySignaturesRequest, res *api.QuerySignaturesResponse) {
|
func (a *KeyInternalAPI) QuerySignatures(ctx context.Context, req *api.QuerySignaturesRequest, res *api.QuerySignaturesResponse) error {
|
||||||
for targetUserID, forTargetUser := range req.TargetIDs {
|
for targetUserID, forTargetUser := range req.TargetIDs {
|
||||||
keyMap, err := a.DB.CrossSigningKeysForUser(ctx, targetUserID)
|
keyMap, err := a.DB.CrossSigningKeysForUser(ctx, targetUserID)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
@ -559,7 +561,7 @@ func (a *KeyInternalAPI) QuerySignatures(ctx context.Context, req *api.QuerySign
|
|||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: fmt.Sprintf("a.DB.CrossSigningSigsForTarget: %s", err),
|
Err: fmt.Sprintf("a.DB.CrossSigningSigsForTarget: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for sourceUserID, forSourceUser := range sigMap {
|
for sourceUserID, forSourceUser := range sigMap {
|
||||||
@ -581,4 +583,5 @@ func (a *KeyInternalAPI) QuerySignatures(ctx context.Context, req *api.QuerySign
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ type DeviceListUpdaterDatabase interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DeviceListUpdaterAPI interface {
|
type DeviceListUpdaterAPI interface {
|
||||||
PerformUploadDeviceKeys(ctx context.Context, req *api.PerformUploadDeviceKeysRequest, res *api.PerformUploadDeviceKeysResponse)
|
PerformUploadDeviceKeys(ctx context.Context, req *api.PerformUploadDeviceKeysRequest, res *api.PerformUploadDeviceKeysResponse) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyChangeProducer is the interface for producers.KeyChange useful for testing.
|
// KeyChangeProducer is the interface for producers.KeyChange useful for testing.
|
||||||
@ -421,7 +421,7 @@ func (u *DeviceListUpdater) processServer(serverName gomatrixserverlib.ServerNam
|
|||||||
uploadReq.SelfSigningKey = *res.SelfSigningKey
|
uploadReq.SelfSigningKey = *res.SelfSigningKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
u.api.PerformUploadDeviceKeys(ctx, uploadReq, uploadRes)
|
_ = u.api.PerformUploadDeviceKeys(ctx, uploadReq, uploadRes)
|
||||||
}
|
}
|
||||||
err = u.updateDeviceList(&res)
|
err = u.updateDeviceList(&res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -113,8 +113,8 @@ func (d *mockDeviceListUpdaterDatabase) DeviceKeysJSON(ctx context.Context, keys
|
|||||||
type mockDeviceListUpdaterAPI struct {
|
type mockDeviceListUpdaterAPI struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *mockDeviceListUpdaterAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.PerformUploadDeviceKeysRequest, res *api.PerformUploadDeviceKeysResponse) {
|
func (d *mockDeviceListUpdaterAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.PerformUploadDeviceKeysRequest, res *api.PerformUploadDeviceKeysResponse) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type roundTripper struct {
|
type roundTripper struct {
|
||||||
|
@ -48,18 +48,20 @@ func (a *KeyInternalAPI) SetUserAPI(i userapi.KeyserverUserAPI) {
|
|||||||
a.UserAPI = i
|
a.UserAPI = i
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) QueryKeyChanges(ctx context.Context, req *api.QueryKeyChangesRequest, res *api.QueryKeyChangesResponse) {
|
func (a *KeyInternalAPI) QueryKeyChanges(ctx context.Context, req *api.QueryKeyChangesRequest, res *api.QueryKeyChangesResponse) error {
|
||||||
userIDs, latest, err := a.DB.KeyChanges(ctx, req.Offset, req.ToOffset)
|
userIDs, latest, err := a.DB.KeyChanges(ctx, req.Offset, req.ToOffset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: err.Error(),
|
Err: err.Error(),
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
res.Offset = latest
|
res.Offset = latest
|
||||||
res.UserIDs = userIDs
|
res.UserIDs = userIDs
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) PerformUploadKeys(ctx context.Context, req *api.PerformUploadKeysRequest, res *api.PerformUploadKeysResponse) {
|
func (a *KeyInternalAPI) PerformUploadKeys(ctx context.Context, req *api.PerformUploadKeysRequest, res *api.PerformUploadKeysResponse) error {
|
||||||
res.KeyErrors = make(map[string]map[string]*api.KeyError)
|
res.KeyErrors = make(map[string]map[string]*api.KeyError)
|
||||||
if len(req.DeviceKeys) > 0 {
|
if len(req.DeviceKeys) > 0 {
|
||||||
a.uploadLocalDeviceKeys(ctx, req, res)
|
a.uploadLocalDeviceKeys(ctx, req, res)
|
||||||
@ -67,9 +69,10 @@ func (a *KeyInternalAPI) PerformUploadKeys(ctx context.Context, req *api.Perform
|
|||||||
if len(req.OneTimeKeys) > 0 {
|
if len(req.OneTimeKeys) > 0 {
|
||||||
a.uploadOneTimeKeys(ctx, req, res)
|
a.uploadOneTimeKeys(ctx, req, res)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) PerformClaimKeys(ctx context.Context, req *api.PerformClaimKeysRequest, res *api.PerformClaimKeysResponse) {
|
func (a *KeyInternalAPI) PerformClaimKeys(ctx context.Context, req *api.PerformClaimKeysRequest, res *api.PerformClaimKeysResponse) error {
|
||||||
res.OneTimeKeys = make(map[string]map[string]map[string]json.RawMessage)
|
res.OneTimeKeys = make(map[string]map[string]map[string]json.RawMessage)
|
||||||
res.Failures = make(map[string]interface{})
|
res.Failures = make(map[string]interface{})
|
||||||
// wrap request map in a top-level by-domain map
|
// wrap request map in a top-level by-domain map
|
||||||
@ -113,6 +116,7 @@ func (a *KeyInternalAPI) PerformClaimKeys(ctx context.Context, req *api.PerformC
|
|||||||
if len(domainToDeviceKeys) > 0 {
|
if len(domainToDeviceKeys) > 0 {
|
||||||
a.claimRemoteKeys(ctx, req.Timeout, res, domainToDeviceKeys)
|
a.claimRemoteKeys(ctx, req.Timeout, res, domainToDeviceKeys)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) claimRemoteKeys(
|
func (a *KeyInternalAPI) claimRemoteKeys(
|
||||||
@ -172,32 +176,34 @@ func (a *KeyInternalAPI) claimRemoteKeys(
|
|||||||
util.GetLogger(ctx).WithField("num_keys", keysClaimed).Info("Claimed remote keys")
|
util.GetLogger(ctx).WithField("num_keys", keysClaimed).Info("Claimed remote keys")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) PerformDeleteKeys(ctx context.Context, req *api.PerformDeleteKeysRequest, res *api.PerformDeleteKeysResponse) {
|
func (a *KeyInternalAPI) PerformDeleteKeys(ctx context.Context, req *api.PerformDeleteKeysRequest, res *api.PerformDeleteKeysResponse) error {
|
||||||
if err := a.DB.DeleteDeviceKeys(ctx, req.UserID, req.KeyIDs); err != nil {
|
if err := a.DB.DeleteDeviceKeys(ctx, req.UserID, req.KeyIDs); err != nil {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: fmt.Sprintf("Failed to delete device keys: %s", err),
|
Err: fmt.Sprintf("Failed to delete device keys: %s", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) QueryOneTimeKeys(ctx context.Context, req *api.QueryOneTimeKeysRequest, res *api.QueryOneTimeKeysResponse) {
|
func (a *KeyInternalAPI) QueryOneTimeKeys(ctx context.Context, req *api.QueryOneTimeKeysRequest, res *api.QueryOneTimeKeysResponse) error {
|
||||||
count, err := a.DB.OneTimeKeysCount(ctx, req.UserID, req.DeviceID)
|
count, err := a.DB.OneTimeKeysCount(ctx, req.UserID, req.DeviceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: fmt.Sprintf("Failed to query OTK counts: %s", err),
|
Err: fmt.Sprintf("Failed to query OTK counts: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
res.Count = *count
|
res.Count = *count
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) QueryDeviceMessages(ctx context.Context, req *api.QueryDeviceMessagesRequest, res *api.QueryDeviceMessagesResponse) {
|
func (a *KeyInternalAPI) QueryDeviceMessages(ctx context.Context, req *api.QueryDeviceMessagesRequest, res *api.QueryDeviceMessagesResponse) error {
|
||||||
msgs, err := a.DB.DeviceKeysForUser(ctx, req.UserID, nil, false)
|
msgs, err := a.DB.DeviceKeysForUser(ctx, req.UserID, nil, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: fmt.Sprintf("failed to query DB for device keys: %s", err),
|
Err: fmt.Sprintf("failed to query DB for device keys: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
maxStreamID := int64(0)
|
maxStreamID := int64(0)
|
||||||
for _, m := range msgs {
|
for _, m := range msgs {
|
||||||
@ -215,10 +221,11 @@ func (a *KeyInternalAPI) QueryDeviceMessages(ctx context.Context, req *api.Query
|
|||||||
}
|
}
|
||||||
res.Devices = result
|
res.Devices = result
|
||||||
res.StreamID = maxStreamID
|
res.StreamID = maxStreamID
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint:gocyclo
|
// nolint:gocyclo
|
||||||
func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysRequest, res *api.QueryKeysResponse) {
|
func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysRequest, res *api.QueryKeysResponse) error {
|
||||||
res.DeviceKeys = make(map[string]map[string]json.RawMessage)
|
res.DeviceKeys = make(map[string]map[string]json.RawMessage)
|
||||||
res.MasterKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
res.MasterKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
||||||
res.SelfSigningKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
res.SelfSigningKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
||||||
@ -244,7 +251,7 @@ func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysReques
|
|||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: fmt.Sprintf("failed to query local device keys: %s", err),
|
Err: fmt.Sprintf("failed to query local device keys: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// pull out display names after we have the keys so we handle wildcards correctly
|
// pull out display names after we have the keys so we handle wildcards correctly
|
||||||
@ -318,7 +325,7 @@ func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysReques
|
|||||||
// Stop executing the function if the context was canceled/the deadline was exceeded,
|
// Stop executing the function if the context was canceled/the deadline was exceeded,
|
||||||
// as we can't continue without a valid context.
|
// as we can't continue without a valid context.
|
||||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
logrus.WithError(err).Errorf("a.DB.CrossSigningSigsForTarget failed")
|
logrus.WithError(err).Errorf("a.DB.CrossSigningSigsForTarget failed")
|
||||||
continue
|
continue
|
||||||
@ -344,7 +351,7 @@ func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysReques
|
|||||||
// Stop executing the function if the context was canceled/the deadline was exceeded,
|
// Stop executing the function if the context was canceled/the deadline was exceeded,
|
||||||
// as we can't continue without a valid context.
|
// as we can't continue without a valid context.
|
||||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
logrus.WithError(err).Errorf("a.DB.CrossSigningSigsForTarget failed")
|
logrus.WithError(err).Errorf("a.DB.CrossSigningSigsForTarget failed")
|
||||||
continue
|
continue
|
||||||
@ -372,6 +379,7 @@ func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysReques
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) remoteKeysFromDatabase(
|
func (a *KeyInternalAPI) remoteKeysFromDatabase(
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/keyserver/api"
|
"github.com/matrix-org/dendrite/keyserver/api"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/opentracing/opentracing-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTP paths for the internal HTTP APIs
|
// HTTP paths for the internal HTTP APIs
|
||||||
@ -68,168 +67,108 @@ func (h *httpKeyInternalAPI) PerformClaimKeys(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformClaimKeysRequest,
|
request *api.PerformClaimKeysRequest,
|
||||||
response *api.PerformClaimKeysResponse,
|
response *api.PerformClaimKeysResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformClaimKeys")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformClaimKeys", h.apiURL+PerformClaimKeysPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformClaimKeysPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.KeyError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpKeyInternalAPI) PerformDeleteKeys(
|
func (h *httpKeyInternalAPI) PerformDeleteKeys(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformDeleteKeysRequest,
|
request *api.PerformDeleteKeysRequest,
|
||||||
response *api.PerformDeleteKeysResponse,
|
response *api.PerformDeleteKeysResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformClaimKeys")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformDeleteKeys", h.apiURL+PerformDeleteKeysPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformClaimKeysPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.KeyError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpKeyInternalAPI) PerformUploadKeys(
|
func (h *httpKeyInternalAPI) PerformUploadKeys(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformUploadKeysRequest,
|
request *api.PerformUploadKeysRequest,
|
||||||
response *api.PerformUploadKeysResponse,
|
response *api.PerformUploadKeysResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformUploadKeys")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformUploadKeys", h.apiURL+PerformUploadKeysPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformUploadKeysPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.KeyError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpKeyInternalAPI) QueryKeys(
|
func (h *httpKeyInternalAPI) QueryKeys(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.QueryKeysRequest,
|
request *api.QueryKeysRequest,
|
||||||
response *api.QueryKeysResponse,
|
response *api.QueryKeysResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryKeys")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryKeys", h.apiURL+QueryKeysPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + QueryKeysPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.KeyError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpKeyInternalAPI) QueryOneTimeKeys(
|
func (h *httpKeyInternalAPI) QueryOneTimeKeys(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.QueryOneTimeKeysRequest,
|
request *api.QueryOneTimeKeysRequest,
|
||||||
response *api.QueryOneTimeKeysResponse,
|
response *api.QueryOneTimeKeysResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryOneTimeKeys")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryOneTimeKeys", h.apiURL+QueryOneTimeKeysPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + QueryOneTimeKeysPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.KeyError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpKeyInternalAPI) QueryDeviceMessages(
|
func (h *httpKeyInternalAPI) QueryDeviceMessages(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.QueryDeviceMessagesRequest,
|
request *api.QueryDeviceMessagesRequest,
|
||||||
response *api.QueryDeviceMessagesResponse,
|
response *api.QueryDeviceMessagesResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryDeviceMessages")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryDeviceMessages", h.apiURL+QueryDeviceMessagesPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + QueryDeviceMessagesPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.KeyError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpKeyInternalAPI) QueryKeyChanges(
|
func (h *httpKeyInternalAPI) QueryKeyChanges(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.QueryKeyChangesRequest,
|
request *api.QueryKeyChangesRequest,
|
||||||
response *api.QueryKeyChangesResponse,
|
response *api.QueryKeyChangesResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryKeyChanges")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryKeyChanges", h.apiURL+QueryKeyChangesPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + QueryKeyChangesPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.KeyError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpKeyInternalAPI) PerformUploadDeviceKeys(
|
func (h *httpKeyInternalAPI) PerformUploadDeviceKeys(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformUploadDeviceKeysRequest,
|
request *api.PerformUploadDeviceKeysRequest,
|
||||||
response *api.PerformUploadDeviceKeysResponse,
|
response *api.PerformUploadDeviceKeysResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformUploadDeviceKeys")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformUploadDeviceKeys", h.apiURL+PerformUploadDeviceKeysPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformUploadDeviceKeysPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.KeyError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpKeyInternalAPI) PerformUploadDeviceSignatures(
|
func (h *httpKeyInternalAPI) PerformUploadDeviceSignatures(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformUploadDeviceSignaturesRequest,
|
request *api.PerformUploadDeviceSignaturesRequest,
|
||||||
response *api.PerformUploadDeviceSignaturesResponse,
|
response *api.PerformUploadDeviceSignaturesResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformUploadDeviceSignatures")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformUploadDeviceSignatures", h.apiURL+PerformUploadDeviceSignaturesPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformUploadDeviceSignaturesPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.KeyError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpKeyInternalAPI) QuerySignatures(
|
func (h *httpKeyInternalAPI) QuerySignatures(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.QuerySignaturesRequest,
|
request *api.QuerySignaturesRequest,
|
||||||
response *api.QuerySignaturesResponse,
|
response *api.QuerySignaturesResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QuerySignatures")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QuerySignatures", h.apiURL+QuerySignaturesPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + QuerySignaturesPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.KeyError{
|
|
||||||
Err: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,124 +15,59 @@
|
|||||||
package inthttp
|
package inthttp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/keyserver/api"
|
"github.com/matrix-org/dendrite/keyserver/api"
|
||||||
"github.com/matrix-org/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddRoutes(internalAPIMux *mux.Router, s api.KeyInternalAPI) {
|
func AddRoutes(internalAPIMux *mux.Router, s api.KeyInternalAPI) {
|
||||||
internalAPIMux.Handle(PerformClaimKeysPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("performClaimKeys", func(req *http.Request) util.JSONResponse {
|
PerformClaimKeysPath,
|
||||||
request := api.PerformClaimKeysRequest{}
|
httputil.MakeInternalRPCAPI("KeyserverPerformClaimKeys", s.PerformClaimKeys),
|
||||||
response := api.PerformClaimKeysResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
s.PerformClaimKeys(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformDeleteKeysPath,
|
|
||||||
httputil.MakeInternalAPI("performDeleteKeys", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformDeleteKeysRequest{}
|
PerformDeleteKeysPath,
|
||||||
response := api.PerformDeleteKeysResponse{}
|
httputil.MakeInternalRPCAPI("KeyserverPerformDeleteKeys", s.PerformDeleteKeys),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
s.PerformDeleteKeys(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformUploadKeysPath,
|
|
||||||
httputil.MakeInternalAPI("performUploadKeys", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformUploadKeysRequest{}
|
PerformUploadKeysPath,
|
||||||
response := api.PerformUploadKeysResponse{}
|
httputil.MakeInternalRPCAPI("KeyserverPerformUploadKeys", s.PerformUploadKeys),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
s.PerformUploadKeys(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformUploadDeviceKeysPath,
|
|
||||||
httputil.MakeInternalAPI("performUploadDeviceKeys", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformUploadDeviceKeysRequest{}
|
PerformUploadDeviceKeysPath,
|
||||||
response := api.PerformUploadDeviceKeysResponse{}
|
httputil.MakeInternalRPCAPI("KeyserverPerformUploadDeviceKeys", s.PerformUploadDeviceKeys),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
s.PerformUploadDeviceKeys(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformUploadDeviceSignaturesPath,
|
|
||||||
httputil.MakeInternalAPI("performUploadDeviceSignatures", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformUploadDeviceSignaturesRequest{}
|
PerformUploadDeviceSignaturesPath,
|
||||||
response := api.PerformUploadDeviceSignaturesResponse{}
|
httputil.MakeInternalRPCAPI("KeyserverPerformUploadDeviceSignatures", s.PerformUploadDeviceSignatures),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
s.PerformUploadDeviceSignatures(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryKeysPath,
|
|
||||||
httputil.MakeInternalAPI("queryKeys", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryKeysRequest{}
|
QueryKeysPath,
|
||||||
response := api.QueryKeysResponse{}
|
httputil.MakeInternalRPCAPI("KeyserverQueryKeys", s.QueryKeys),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
s.QueryKeys(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryOneTimeKeysPath,
|
|
||||||
httputil.MakeInternalAPI("queryOneTimeKeys", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryOneTimeKeysRequest{}
|
QueryOneTimeKeysPath,
|
||||||
response := api.QueryOneTimeKeysResponse{}
|
httputil.MakeInternalRPCAPI("KeyserverQueryOneTimeKeys", s.QueryOneTimeKeys),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
s.QueryOneTimeKeys(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryDeviceMessagesPath,
|
|
||||||
httputil.MakeInternalAPI("queryDeviceMessages", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryDeviceMessagesRequest{}
|
QueryDeviceMessagesPath,
|
||||||
response := api.QueryDeviceMessagesResponse{}
|
httputil.MakeInternalRPCAPI("KeyserverQueryDeviceMessages", s.QueryDeviceMessages),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
s.QueryDeviceMessages(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryKeyChangesPath,
|
|
||||||
httputil.MakeInternalAPI("queryKeyChanges", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryKeyChangesRequest{}
|
QueryKeyChangesPath,
|
||||||
response := api.QueryKeyChangesResponse{}
|
httputil.MakeInternalRPCAPI("KeyserverQueryKeyChanges", s.QueryKeyChanges),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
s.QueryKeyChanges(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QuerySignaturesPath,
|
|
||||||
httputil.MakeInternalAPI("querySignatures", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QuerySignaturesRequest{}
|
QuerySignaturesPath,
|
||||||
response := api.QuerySignaturesResponse{}
|
httputil.MakeInternalRPCAPI("KeyserverQuerySignatures", s.QuerySignatures),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
s.QuerySignatures(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ type InputRoomEventsAPI interface {
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *InputRoomEventsRequest,
|
req *InputRoomEventsRequest,
|
||||||
res *InputRoomEventsResponse,
|
res *InputRoomEventsResponse,
|
||||||
)
|
) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the latest events and state for a room from the room server.
|
// Query the latest events and state for a room from the room server.
|
||||||
@ -139,15 +139,15 @@ type ClientRoomserverAPI interface {
|
|||||||
GetAliasesForRoomID(ctx context.Context, req *GetAliasesForRoomIDRequest, res *GetAliasesForRoomIDResponse) error
|
GetAliasesForRoomID(ctx context.Context, req *GetAliasesForRoomIDRequest, res *GetAliasesForRoomIDResponse) error
|
||||||
|
|
||||||
// PerformRoomUpgrade upgrades a room to a newer version
|
// PerformRoomUpgrade upgrades a room to a newer version
|
||||||
PerformRoomUpgrade(ctx context.Context, req *PerformRoomUpgradeRequest, resp *PerformRoomUpgradeResponse)
|
PerformRoomUpgrade(ctx context.Context, req *PerformRoomUpgradeRequest, resp *PerformRoomUpgradeResponse) error
|
||||||
PerformAdminEvacuateRoom(ctx context.Context, req *PerformAdminEvacuateRoomRequest, res *PerformAdminEvacuateRoomResponse)
|
PerformAdminEvacuateRoom(ctx context.Context, req *PerformAdminEvacuateRoomRequest, res *PerformAdminEvacuateRoomResponse) error
|
||||||
PerformAdminEvacuateUser(ctx context.Context, req *PerformAdminEvacuateUserRequest, res *PerformAdminEvacuateUserResponse)
|
PerformAdminEvacuateUser(ctx context.Context, req *PerformAdminEvacuateUserRequest, res *PerformAdminEvacuateUserResponse) error
|
||||||
PerformPeek(ctx context.Context, req *PerformPeekRequest, res *PerformPeekResponse)
|
PerformPeek(ctx context.Context, req *PerformPeekRequest, res *PerformPeekResponse) error
|
||||||
PerformUnpeek(ctx context.Context, req *PerformUnpeekRequest, res *PerformUnpeekResponse)
|
PerformUnpeek(ctx context.Context, req *PerformUnpeekRequest, res *PerformUnpeekResponse) error
|
||||||
PerformInvite(ctx context.Context, req *PerformInviteRequest, res *PerformInviteResponse) error
|
PerformInvite(ctx context.Context, req *PerformInviteRequest, res *PerformInviteResponse) error
|
||||||
PerformJoin(ctx context.Context, req *PerformJoinRequest, res *PerformJoinResponse)
|
PerformJoin(ctx context.Context, req *PerformJoinRequest, res *PerformJoinResponse) error
|
||||||
PerformLeave(ctx context.Context, req *PerformLeaveRequest, res *PerformLeaveResponse) error
|
PerformLeave(ctx context.Context, req *PerformLeaveRequest, res *PerformLeaveResponse) error
|
||||||
PerformPublish(ctx context.Context, req *PerformPublishRequest, res *PerformPublishResponse)
|
PerformPublish(ctx context.Context, req *PerformPublishRequest, res *PerformPublishResponse) error
|
||||||
// PerformForget forgets a rooms history for a specific user
|
// PerformForget forgets a rooms history for a specific user
|
||||||
PerformForget(ctx context.Context, req *PerformForgetRequest, resp *PerformForgetResponse) error
|
PerformForget(ctx context.Context, req *PerformForgetRequest, resp *PerformForgetResponse) error
|
||||||
SetRoomAlias(ctx context.Context, req *SetRoomAliasRequest, res *SetRoomAliasResponse) error
|
SetRoomAlias(ctx context.Context, req *SetRoomAliasRequest, res *SetRoomAliasResponse) error
|
||||||
@ -158,7 +158,7 @@ type UserRoomserverAPI interface {
|
|||||||
QueryLatestEventsAndStateAPI
|
QueryLatestEventsAndStateAPI
|
||||||
QueryCurrentState(ctx context.Context, req *QueryCurrentStateRequest, res *QueryCurrentStateResponse) error
|
QueryCurrentState(ctx context.Context, req *QueryCurrentStateRequest, res *QueryCurrentStateResponse) error
|
||||||
QueryMembershipsForRoom(ctx context.Context, req *QueryMembershipsForRoomRequest, res *QueryMembershipsForRoomResponse) error
|
QueryMembershipsForRoom(ctx context.Context, req *QueryMembershipsForRoomRequest, res *QueryMembershipsForRoomResponse) error
|
||||||
PerformAdminEvacuateUser(ctx context.Context, req *PerformAdminEvacuateUserRequest, res *PerformAdminEvacuateUserResponse)
|
PerformAdminEvacuateUser(ctx context.Context, req *PerformAdminEvacuateUserRequest, res *PerformAdminEvacuateUserResponse) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type FederationRoomserverAPI interface {
|
type FederationRoomserverAPI interface {
|
||||||
|
@ -35,9 +35,10 @@ func (t *RoomserverInternalAPITrace) InputRoomEvents(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *InputRoomEventsRequest,
|
req *InputRoomEventsRequest,
|
||||||
res *InputRoomEventsResponse,
|
res *InputRoomEventsResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.InputRoomEvents(ctx, req, res)
|
err := t.Impl.InputRoomEvents(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("InputRoomEvents req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("InputRoomEvents req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformInvite(
|
func (t *RoomserverInternalAPITrace) PerformInvite(
|
||||||
@ -45,44 +46,49 @@ func (t *RoomserverInternalAPITrace) PerformInvite(
|
|||||||
req *PerformInviteRequest,
|
req *PerformInviteRequest,
|
||||||
res *PerformInviteResponse,
|
res *PerformInviteResponse,
|
||||||
) error {
|
) error {
|
||||||
util.GetLogger(ctx).Infof("PerformInvite req=%+v res=%+v", js(req), js(res))
|
err := t.Impl.PerformInvite(ctx, req, res)
|
||||||
return t.Impl.PerformInvite(ctx, req, res)
|
util.GetLogger(ctx).WithError(err).Infof("PerformInvite req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformPeek(
|
func (t *RoomserverInternalAPITrace) PerformPeek(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformPeekRequest,
|
req *PerformPeekRequest,
|
||||||
res *PerformPeekResponse,
|
res *PerformPeekResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformPeek(ctx, req, res)
|
err := t.Impl.PerformPeek(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformPeek req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformPeek req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformUnpeek(
|
func (t *RoomserverInternalAPITrace) PerformUnpeek(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformUnpeekRequest,
|
req *PerformUnpeekRequest,
|
||||||
res *PerformUnpeekResponse,
|
res *PerformUnpeekResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformUnpeek(ctx, req, res)
|
err := t.Impl.PerformUnpeek(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformUnpeek req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformUnpeek req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformRoomUpgrade(
|
func (t *RoomserverInternalAPITrace) PerformRoomUpgrade(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformRoomUpgradeRequest,
|
req *PerformRoomUpgradeRequest,
|
||||||
res *PerformRoomUpgradeResponse,
|
res *PerformRoomUpgradeResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformRoomUpgrade(ctx, req, res)
|
err := t.Impl.PerformRoomUpgrade(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformRoomUpgrade req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformRoomUpgrade req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformJoin(
|
func (t *RoomserverInternalAPITrace) PerformJoin(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformJoinRequest,
|
req *PerformJoinRequest,
|
||||||
res *PerformJoinResponse,
|
res *PerformJoinResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformJoin(ctx, req, res)
|
err := t.Impl.PerformJoin(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformJoin req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformJoin req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformLeave(
|
func (t *RoomserverInternalAPITrace) PerformLeave(
|
||||||
@ -99,27 +105,30 @@ func (t *RoomserverInternalAPITrace) PerformPublish(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformPublishRequest,
|
req *PerformPublishRequest,
|
||||||
res *PerformPublishResponse,
|
res *PerformPublishResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformPublish(ctx, req, res)
|
err := t.Impl.PerformPublish(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformPublish req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformPublish req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformAdminEvacuateRoom(
|
func (t *RoomserverInternalAPITrace) PerformAdminEvacuateRoom(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformAdminEvacuateRoomRequest,
|
req *PerformAdminEvacuateRoomRequest,
|
||||||
res *PerformAdminEvacuateRoomResponse,
|
res *PerformAdminEvacuateRoomResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformAdminEvacuateRoom(ctx, req, res)
|
err := t.Impl.PerformAdminEvacuateRoom(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformAdminEvacuateRoom req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformAdminEvacuateRoom req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformAdminEvacuateUser(
|
func (t *RoomserverInternalAPITrace) PerformAdminEvacuateUser(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformAdminEvacuateUserRequest,
|
req *PerformAdminEvacuateUserRequest,
|
||||||
res *PerformAdminEvacuateUserResponse,
|
res *PerformAdminEvacuateUserResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformAdminEvacuateUser(ctx, req, res)
|
err := t.Impl.PerformAdminEvacuateUser(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformAdminEvacuateUser req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformAdminEvacuateUser req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformInboundPeek(
|
func (t *RoomserverInternalAPITrace) PerformInboundPeek(
|
||||||
@ -128,7 +137,7 @@ func (t *RoomserverInternalAPITrace) PerformInboundPeek(
|
|||||||
res *PerformInboundPeekResponse,
|
res *PerformInboundPeekResponse,
|
||||||
) error {
|
) error {
|
||||||
err := t.Impl.PerformInboundPeek(ctx, req, res)
|
err := t.Impl.PerformInboundPeek(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformInboundPeek req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformInboundPeek req=%+v res=%+v", js(req), js(res))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,9 @@ func SendInputRoomEvents(
|
|||||||
Asynchronous: async,
|
Asynchronous: async,
|
||||||
}
|
}
|
||||||
var response InputRoomEventsResponse
|
var response InputRoomEventsResponse
|
||||||
rsAPI.InputRoomEvents(ctx, &request, &response)
|
if err := rsAPI.InputRoomEvents(ctx, &request, &response); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return response.Err()
|
return response.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,18 +337,18 @@ func (r *Inputer) InputRoomEvents(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.InputRoomEventsRequest,
|
request *api.InputRoomEventsRequest,
|
||||||
response *api.InputRoomEventsResponse,
|
response *api.InputRoomEventsResponse,
|
||||||
) {
|
) error {
|
||||||
// Queue up the event into the roomserver.
|
// Queue up the event into the roomserver.
|
||||||
replySub, err := r.queueInputRoomEvents(ctx, request)
|
replySub, err := r.queueInputRoomEvents(ctx, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrMsg = err.Error()
|
response.ErrMsg = err.Error()
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we aren't waiting for synchronous responses then we can
|
// If we aren't waiting for synchronous responses then we can
|
||||||
// give up here, there is nothing further to do.
|
// give up here, there is nothing further to do.
|
||||||
if replySub == nil {
|
if replySub == nil {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we'll want to sit and wait for the responses
|
// Otherwise, we'll want to sit and wait for the responses
|
||||||
@ -360,12 +360,14 @@ func (r *Inputer) InputRoomEvents(
|
|||||||
msg, err := replySub.NextMsgWithContext(ctx)
|
msg, err := replySub.NextMsgWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrMsg = err.Error()
|
response.ErrMsg = err.Error()
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if len(msg.Data) > 0 {
|
if len(msg.Data) > 0 {
|
||||||
response.ErrMsg = string(msg.Data)
|
response.ErrMsg = string(msg.Data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var roomserverInputBackpressure = prometheus.NewGaugeVec(
|
var roomserverInputBackpressure = prometheus.NewGaugeVec(
|
||||||
|
@ -43,21 +43,21 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformAdminEvacuateRoomRequest,
|
req *api.PerformAdminEvacuateRoomRequest,
|
||||||
res *api.PerformAdminEvacuateRoomResponse,
|
res *api.PerformAdminEvacuateRoomResponse,
|
||||||
) {
|
) error {
|
||||||
roomInfo, err := r.DB.RoomInfo(ctx, req.RoomID)
|
roomInfo, err := r.DB.RoomInfo(ctx, req.RoomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.DB.RoomInfo: %s", err),
|
Msg: fmt.Sprintf("r.DB.RoomInfo: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if roomInfo == nil || roomInfo.IsStub() {
|
if roomInfo == nil || roomInfo.IsStub() {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Code: api.PerformErrorNoRoom,
|
Code: api.PerformErrorNoRoom,
|
||||||
Msg: fmt.Sprintf("Room %s not found", req.RoomID),
|
Msg: fmt.Sprintf("Room %s not found", req.RoomID),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
memberNIDs, err := r.DB.GetMembershipEventNIDsForRoom(ctx, roomInfo.RoomNID, true, true)
|
memberNIDs, err := r.DB.GetMembershipEventNIDsForRoom(ctx, roomInfo.RoomNID, true, true)
|
||||||
@ -66,7 +66,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
|||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.DB.GetMembershipEventNIDsForRoom: %s", err),
|
Msg: fmt.Sprintf("r.DB.GetMembershipEventNIDsForRoom: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
memberEvents, err := r.DB.Events(ctx, memberNIDs)
|
memberEvents, err := r.DB.Events(ctx, memberNIDs)
|
||||||
@ -75,7 +75,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
|||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.DB.Events: %s", err),
|
Msg: fmt.Sprintf("r.DB.Events: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
inputEvents := make([]api.InputRoomEvent, 0, len(memberEvents))
|
inputEvents := make([]api.InputRoomEvent, 0, len(memberEvents))
|
||||||
@ -89,7 +89,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
|||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.Queryer.QueryLatestEventsAndState: %s", err),
|
Msg: fmt.Sprintf("r.Queryer.QueryLatestEventsAndState: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
prevEvents := latestRes.LatestEvents
|
prevEvents := latestRes.LatestEvents
|
||||||
@ -104,7 +104,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
|||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("json.Unmarshal: %s", err),
|
Msg: fmt.Sprintf("json.Unmarshal: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
memberContent.Membership = gomatrixserverlib.Leave
|
memberContent.Membership = gomatrixserverlib.Leave
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
|||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("json.Marshal: %s", err),
|
Msg: fmt.Sprintf("json.Marshal: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(fledglingEvent)
|
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(fledglingEvent)
|
||||||
@ -131,7 +131,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
|||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("gomatrixserverlib.StateNeededForEventBuilder: %s", err),
|
Msg: fmt.Sprintf("gomatrixserverlib.StateNeededForEventBuilder: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
event, err := eventutil.BuildEvent(ctx, fledglingEvent, r.Cfg.Matrix, time.Now(), &eventsNeeded, latestRes)
|
event, err := eventutil.BuildEvent(ctx, fledglingEvent, r.Cfg.Matrix, time.Now(), &eventsNeeded, latestRes)
|
||||||
@ -140,7 +140,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
|||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("eventutil.BuildEvent: %s", err),
|
Msg: fmt.Sprintf("eventutil.BuildEvent: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
inputEvents = append(inputEvents, api.InputRoomEvent{
|
inputEvents = append(inputEvents, api.InputRoomEvent{
|
||||||
@ -160,28 +160,28 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
|||||||
Asynchronous: true,
|
Asynchronous: true,
|
||||||
}
|
}
|
||||||
inputRes := &api.InputRoomEventsResponse{}
|
inputRes := &api.InputRoomEventsResponse{}
|
||||||
r.Inputer.InputRoomEvents(ctx, inputReq, inputRes)
|
return r.Inputer.InputRoomEvents(ctx, inputReq, inputRes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Admin) PerformAdminEvacuateUser(
|
func (r *Admin) PerformAdminEvacuateUser(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformAdminEvacuateUserRequest,
|
req *api.PerformAdminEvacuateUserRequest,
|
||||||
res *api.PerformAdminEvacuateUserResponse,
|
res *api.PerformAdminEvacuateUserResponse,
|
||||||
) {
|
) error {
|
||||||
_, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
|
_, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("Malformed user ID: %s", err),
|
Msg: fmt.Sprintf("Malformed user ID: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if domain != r.Cfg.Matrix.ServerName {
|
if domain != r.Cfg.Matrix.ServerName {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: "Can only evacuate local users using this endpoint",
|
Msg: "Can only evacuate local users using this endpoint",
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
roomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, gomatrixserverlib.Join)
|
roomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, gomatrixserverlib.Join)
|
||||||
@ -190,7 +190,7 @@ func (r *Admin) PerformAdminEvacuateUser(
|
|||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.DB.GetRoomsByMembership: %s", err),
|
Msg: fmt.Sprintf("r.DB.GetRoomsByMembership: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
inviteRoomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, gomatrixserverlib.Invite)
|
inviteRoomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, gomatrixserverlib.Invite)
|
||||||
@ -199,7 +199,7 @@ func (r *Admin) PerformAdminEvacuateUser(
|
|||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.DB.GetRoomsByMembership: %s", err),
|
Msg: fmt.Sprintf("r.DB.GetRoomsByMembership: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, roomID := range append(roomIDs, inviteRoomIDs...) {
|
for _, roomID := range append(roomIDs, inviteRoomIDs...) {
|
||||||
@ -214,7 +214,7 @@ func (r *Admin) PerformAdminEvacuateUser(
|
|||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.Leaver.PerformLeave: %s", err),
|
Msg: fmt.Sprintf("r.Leaver.PerformLeave: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if len(outputEvents) == 0 {
|
if len(outputEvents) == 0 {
|
||||||
continue
|
continue
|
||||||
@ -224,9 +224,10 @@ func (r *Admin) PerformAdminEvacuateUser(
|
|||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.Inputer.WriteOutputEvents: %s", err),
|
Msg: fmt.Sprintf("r.Inputer.WriteOutputEvents: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Affected = append(res.Affected, roomID)
|
res.Affected = append(res.Affected, roomID)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,9 @@ func (r *Inviter) PerformInvite(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
inputRes := &api.InputRoomEventsResponse{}
|
inputRes := &api.InputRoomEventsResponse{}
|
||||||
r.Inputer.InputRoomEvents(context.Background(), inputReq, inputRes)
|
if err = r.Inputer.InputRoomEvents(context.Background(), inputReq, inputRes); err != nil {
|
||||||
|
return nil, fmt.Errorf("r.Inputer.InputRoomEvents: %w", err)
|
||||||
|
}
|
||||||
if err = inputRes.Err(); err != nil {
|
if err = inputRes.Err(); err != nil {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Msg: fmt.Sprintf("r.InputRoomEvents: %s", err.Error()),
|
Msg: fmt.Sprintf("r.InputRoomEvents: %s", err.Error()),
|
||||||
|
@ -52,7 +52,7 @@ func (r *Joiner) PerformJoin(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *rsAPI.PerformJoinRequest,
|
req *rsAPI.PerformJoinRequest,
|
||||||
res *rsAPI.PerformJoinResponse,
|
res *rsAPI.PerformJoinResponse,
|
||||||
) {
|
) error {
|
||||||
logger := logrus.WithContext(ctx).WithFields(logrus.Fields{
|
logger := logrus.WithContext(ctx).WithFields(logrus.Fields{
|
||||||
"room_id": req.RoomIDOrAlias,
|
"room_id": req.RoomIDOrAlias,
|
||||||
"user_id": req.UserID,
|
"user_id": req.UserID,
|
||||||
@ -71,11 +71,12 @@ func (r *Joiner) PerformJoin(
|
|||||||
Msg: err.Error(),
|
Msg: err.Error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
logger.Info("User joined room successfully")
|
logger.Info("User joined room successfully")
|
||||||
res.RoomID = roomID
|
res.RoomID = roomID
|
||||||
res.JoinedVia = joinedVia
|
res.JoinedVia = joinedVia
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Joiner) performJoin(
|
func (r *Joiner) performJoin(
|
||||||
@ -291,7 +292,12 @@ func (r *Joiner) performJoinRoomByID(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
inputRes := rsAPI.InputRoomEventsResponse{}
|
inputRes := rsAPI.InputRoomEventsResponse{}
|
||||||
r.Inputer.InputRoomEvents(ctx, &inputReq, &inputRes)
|
if err = r.Inputer.InputRoomEvents(ctx, &inputReq, &inputRes); err != nil {
|
||||||
|
return "", "", &rsAPI.PerformError{
|
||||||
|
Code: rsAPI.PerformErrorNoOperation,
|
||||||
|
Msg: fmt.Sprintf("InputRoomEvents failed: %s", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
if err = inputRes.Err(); err != nil {
|
if err = inputRes.Err(); err != nil {
|
||||||
return "", "", &rsAPI.PerformError{
|
return "", "", &rsAPI.PerformError{
|
||||||
Code: rsAPI.PerformErrorNotAllowed,
|
Code: rsAPI.PerformErrorNotAllowed,
|
||||||
|
@ -186,7 +186,9 @@ func (r *Leaver) performLeaveRoomByID(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
inputRes := api.InputRoomEventsResponse{}
|
inputRes := api.InputRoomEventsResponse{}
|
||||||
r.Inputer.InputRoomEvents(ctx, &inputReq, &inputRes)
|
if err = r.Inputer.InputRoomEvents(ctx, &inputReq, &inputRes); err != nil {
|
||||||
|
return nil, fmt.Errorf("r.Inputer.InputRoomEvents: %w", err)
|
||||||
|
}
|
||||||
if err = inputRes.Err(); err != nil {
|
if err = inputRes.Err(); err != nil {
|
||||||
return nil, fmt.Errorf("r.InputRoomEvents: %w", err)
|
return nil, fmt.Errorf("r.InputRoomEvents: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func (r *Peeker) PerformPeek(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformPeekRequest,
|
req *api.PerformPeekRequest,
|
||||||
res *api.PerformPeekResponse,
|
res *api.PerformPeekResponse,
|
||||||
) {
|
) error {
|
||||||
roomID, err := r.performPeek(ctx, req)
|
roomID, err := r.performPeek(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
perr, ok := err.(*api.PerformError)
|
perr, ok := err.(*api.PerformError)
|
||||||
@ -57,6 +57,7 @@ func (r *Peeker) PerformPeek(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.RoomID = roomID
|
res.RoomID = roomID
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Peeker) performPeek(
|
func (r *Peeker) performPeek(
|
||||||
|
@ -29,11 +29,12 @@ func (r *Publisher) PerformPublish(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformPublishRequest,
|
req *api.PerformPublishRequest,
|
||||||
res *api.PerformPublishResponse,
|
res *api.PerformPublishResponse,
|
||||||
) {
|
) error {
|
||||||
err := r.DB.PublishRoom(ctx, req.RoomID, req.Visibility == "public")
|
err := r.DB.PublishRoom(ctx, req.RoomID, req.Visibility == "public")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Msg: err.Error(),
|
Msg: err.Error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func (r *Unpeeker) PerformUnpeek(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformUnpeekRequest,
|
req *api.PerformUnpeekRequest,
|
||||||
res *api.PerformUnpeekResponse,
|
res *api.PerformUnpeekResponse,
|
||||||
) {
|
) error {
|
||||||
if err := r.performUnpeek(ctx, req); err != nil {
|
if err := r.performUnpeek(ctx, req); err != nil {
|
||||||
perr, ok := err.(*api.PerformError)
|
perr, ok := err.(*api.PerformError)
|
||||||
if ok {
|
if ok {
|
||||||
@ -52,6 +52,7 @@ func (r *Unpeeker) PerformUnpeek(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Unpeeker) performUnpeek(
|
func (r *Unpeeker) performUnpeek(
|
||||||
|
@ -45,12 +45,13 @@ func (r *Upgrader) PerformRoomUpgrade(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformRoomUpgradeRequest,
|
req *api.PerformRoomUpgradeRequest,
|
||||||
res *api.PerformRoomUpgradeResponse,
|
res *api.PerformRoomUpgradeResponse,
|
||||||
) {
|
) error {
|
||||||
res.NewRoomID, res.Error = r.performRoomUpgrade(ctx, req)
|
res.NewRoomID, res.Error = r.performRoomUpgrade(ctx, req)
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
res.NewRoomID = ""
|
res.NewRoomID = ""
|
||||||
logrus.WithContext(ctx).WithError(res.Error).Error("Room upgrade failed")
|
logrus.WithContext(ctx).WithError(res.Error).Error("Room upgrade failed")
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Upgrader) performRoomUpgrade(
|
func (r *Upgrader) performRoomUpgrade(
|
||||||
@ -286,22 +287,24 @@ func publishNewRoomAndUnpublishOldRoom(
|
|||||||
) {
|
) {
|
||||||
// expose this room in the published room list
|
// expose this room in the published room list
|
||||||
var pubNewRoomRes api.PerformPublishResponse
|
var pubNewRoomRes api.PerformPublishResponse
|
||||||
URSAPI.PerformPublish(ctx, &api.PerformPublishRequest{
|
if err := URSAPI.PerformPublish(ctx, &api.PerformPublishRequest{
|
||||||
RoomID: newRoomID,
|
RoomID: newRoomID,
|
||||||
Visibility: "public",
|
Visibility: "public",
|
||||||
}, &pubNewRoomRes)
|
}, &pubNewRoomRes); err != nil {
|
||||||
if pubNewRoomRes.Error != nil {
|
util.GetLogger(ctx).WithError(err).Error("failed to reach internal API")
|
||||||
|
} else if pubNewRoomRes.Error != nil {
|
||||||
// treat as non-fatal since the room is already made by this point
|
// treat as non-fatal since the room is already made by this point
|
||||||
util.GetLogger(ctx).WithError(pubNewRoomRes.Error).Error("failed to visibility:public")
|
util.GetLogger(ctx).WithError(pubNewRoomRes.Error).Error("failed to visibility:public")
|
||||||
}
|
}
|
||||||
|
|
||||||
var unpubOldRoomRes api.PerformPublishResponse
|
var unpubOldRoomRes api.PerformPublishResponse
|
||||||
// remove the old room from the published room list
|
// remove the old room from the published room list
|
||||||
URSAPI.PerformPublish(ctx, &api.PerformPublishRequest{
|
if err := URSAPI.PerformPublish(ctx, &api.PerformPublishRequest{
|
||||||
RoomID: oldRoomID,
|
RoomID: oldRoomID,
|
||||||
Visibility: "private",
|
Visibility: "private",
|
||||||
}, &unpubOldRoomRes)
|
}, &unpubOldRoomRes); err != nil {
|
||||||
if unpubOldRoomRes.Error != nil {
|
util.GetLogger(ctx).WithError(err).Error("failed to reach internal API")
|
||||||
|
} else if unpubOldRoomRes.Error != nil {
|
||||||
// treat as non-fatal since the room is already made by this point
|
// treat as non-fatal since the room is already made by this point
|
||||||
util.GetLogger(ctx).WithError(unpubOldRoomRes.Error).Error("failed to visibility:private")
|
util.GetLogger(ctx).WithError(unpubOldRoomRes.Error).Error("failed to visibility:private")
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package inthttp
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
asAPI "github.com/matrix-org/dendrite/appservice/api"
|
asAPI "github.com/matrix-org/dendrite/appservice/api"
|
||||||
@ -14,7 +13,6 @@ import (
|
|||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/opentracing/opentracing-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -106,11 +104,10 @@ func (h *httpRoomserverInternalAPI) SetRoomAlias(
|
|||||||
request *api.SetRoomAliasRequest,
|
request *api.SetRoomAliasRequest,
|
||||||
response *api.SetRoomAliasResponse,
|
response *api.SetRoomAliasResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "SetRoomAlias")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"SetRoomAlias", h.roomserverURL+RoomserverSetRoomAliasPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverSetRoomAliasPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRoomIDForAlias implements RoomserverAliasAPI
|
// GetRoomIDForAlias implements RoomserverAliasAPI
|
||||||
@ -119,11 +116,10 @@ func (h *httpRoomserverInternalAPI) GetRoomIDForAlias(
|
|||||||
request *api.GetRoomIDForAliasRequest,
|
request *api.GetRoomIDForAliasRequest,
|
||||||
response *api.GetRoomIDForAliasResponse,
|
response *api.GetRoomIDForAliasResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "GetRoomIDForAlias")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"GetRoomIDForAlias", h.roomserverURL+RoomserverGetRoomIDForAliasPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverGetRoomIDForAliasPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAliasesForRoomID implements RoomserverAliasAPI
|
// GetAliasesForRoomID implements RoomserverAliasAPI
|
||||||
@ -132,11 +128,10 @@ func (h *httpRoomserverInternalAPI) GetAliasesForRoomID(
|
|||||||
request *api.GetAliasesForRoomIDRequest,
|
request *api.GetAliasesForRoomIDRequest,
|
||||||
response *api.GetAliasesForRoomIDResponse,
|
response *api.GetAliasesForRoomIDResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "GetAliasesForRoomID")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"GetAliasesForRoomID", h.roomserverURL+RoomserverGetAliasesForRoomIDPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverGetAliasesForRoomIDPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveRoomAlias implements RoomserverAliasAPI
|
// RemoveRoomAlias implements RoomserverAliasAPI
|
||||||
@ -145,11 +140,10 @@ func (h *httpRoomserverInternalAPI) RemoveRoomAlias(
|
|||||||
request *api.RemoveRoomAliasRequest,
|
request *api.RemoveRoomAliasRequest,
|
||||||
response *api.RemoveRoomAliasResponse,
|
response *api.RemoveRoomAliasResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "RemoveRoomAlias")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"RemoveRoomAlias", h.roomserverURL+RoomserverRemoveRoomAliasPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverRemoveRoomAliasPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputRoomEvents implements RoomserverInputAPI
|
// InputRoomEvents implements RoomserverInputAPI
|
||||||
@ -157,15 +151,14 @@ func (h *httpRoomserverInternalAPI) InputRoomEvents(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.InputRoomEventsRequest,
|
request *api.InputRoomEventsRequest,
|
||||||
response *api.InputRoomEventsResponse,
|
response *api.InputRoomEventsResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "InputRoomEvents")
|
if err := httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"InputRoomEvents", h.roomserverURL+RoomserverInputRoomEventsPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverInputRoomEventsPath
|
); err != nil {
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.ErrMsg = err.Error()
|
response.ErrMsg = err.Error()
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformInvite(
|
func (h *httpRoomserverInternalAPI) PerformInvite(
|
||||||
@ -173,45 +166,32 @@ func (h *httpRoomserverInternalAPI) PerformInvite(
|
|||||||
request *api.PerformInviteRequest,
|
request *api.PerformInviteRequest,
|
||||||
response *api.PerformInviteResponse,
|
response *api.PerformInviteResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformInvite")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformInvite", h.roomserverURL+RoomserverPerformInvitePath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverPerformInvitePath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformJoin(
|
func (h *httpRoomserverInternalAPI) PerformJoin(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformJoinRequest,
|
request *api.PerformJoinRequest,
|
||||||
response *api.PerformJoinResponse,
|
response *api.PerformJoinResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformJoin")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformJoin", h.roomserverURL+RoomserverPerformJoinPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverPerformJoinPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.PerformError{
|
|
||||||
Msg: fmt.Sprintf("failed to communicate with roomserver: %s", err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformPeek(
|
func (h *httpRoomserverInternalAPI) PerformPeek(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformPeekRequest,
|
request *api.PerformPeekRequest,
|
||||||
response *api.PerformPeekResponse,
|
response *api.PerformPeekResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformPeek")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformPeek", h.roomserverURL+RoomserverPerformPeekPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverPerformPeekPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.PerformError{
|
|
||||||
Msg: fmt.Sprintf("failed to communicate with roomserver: %s", err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformInboundPeek(
|
func (h *httpRoomserverInternalAPI) PerformInboundPeek(
|
||||||
@ -219,45 +199,32 @@ func (h *httpRoomserverInternalAPI) PerformInboundPeek(
|
|||||||
request *api.PerformInboundPeekRequest,
|
request *api.PerformInboundPeekRequest,
|
||||||
response *api.PerformInboundPeekResponse,
|
response *api.PerformInboundPeekResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformInboundPeek")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformInboundPeek", h.roomserverURL+RoomserverPerformInboundPeekPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverPerformInboundPeekPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformUnpeek(
|
func (h *httpRoomserverInternalAPI) PerformUnpeek(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformUnpeekRequest,
|
request *api.PerformUnpeekRequest,
|
||||||
response *api.PerformUnpeekResponse,
|
response *api.PerformUnpeekResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformUnpeek")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformUnpeek", h.roomserverURL+RoomserverPerformUnpeekPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverPerformUnpeekPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.PerformError{
|
|
||||||
Msg: fmt.Sprintf("failed to communicate with roomserver: %s", err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformRoomUpgrade(
|
func (h *httpRoomserverInternalAPI) PerformRoomUpgrade(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformRoomUpgradeRequest,
|
request *api.PerformRoomUpgradeRequest,
|
||||||
response *api.PerformRoomUpgradeResponse,
|
response *api.PerformRoomUpgradeResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformRoomUpgrade")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformRoomUpgrade", h.roomserverURL+RoomserverPerformRoomUpgradePath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverPerformRoomUpgradePath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err != nil {
|
|
||||||
response.Error = &api.PerformError{
|
|
||||||
Msg: fmt.Sprintf("failed to communicate with roomserver: %s", err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformLeave(
|
func (h *httpRoomserverInternalAPI) PerformLeave(
|
||||||
@ -265,62 +232,43 @@ func (h *httpRoomserverInternalAPI) PerformLeave(
|
|||||||
request *api.PerformLeaveRequest,
|
request *api.PerformLeaveRequest,
|
||||||
response *api.PerformLeaveResponse,
|
response *api.PerformLeaveResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformLeave")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformLeave", h.roomserverURL+RoomserverPerformLeavePath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverPerformLeavePath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformPublish(
|
func (h *httpRoomserverInternalAPI) PerformPublish(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformPublishRequest,
|
request *api.PerformPublishRequest,
|
||||||
res *api.PerformPublishResponse,
|
response *api.PerformPublishResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformPublish")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformPublish", h.roomserverURL+RoomserverPerformPublishPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverPerformPublishPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
||||||
if err != nil {
|
|
||||||
res.Error = &api.PerformError{
|
|
||||||
Msg: fmt.Sprintf("failed to communicate with roomserver: %s", err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformAdminEvacuateRoom(
|
func (h *httpRoomserverInternalAPI) PerformAdminEvacuateRoom(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformAdminEvacuateRoomRequest,
|
request *api.PerformAdminEvacuateRoomRequest,
|
||||||
res *api.PerformAdminEvacuateRoomResponse,
|
response *api.PerformAdminEvacuateRoomResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformAdminEvacuateRoom")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformAdminEvacuateRoom", h.roomserverURL+RoomserverPerformAdminEvacuateRoomPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverPerformAdminEvacuateRoomPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
||||||
if err != nil {
|
|
||||||
res.Error = &api.PerformError{
|
|
||||||
Msg: fmt.Sprintf("failed to communicate with roomserver: %s", err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformAdminEvacuateUser(
|
func (h *httpRoomserverInternalAPI) PerformAdminEvacuateUser(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformAdminEvacuateUserRequest,
|
request *api.PerformAdminEvacuateUserRequest,
|
||||||
res *api.PerformAdminEvacuateUserResponse,
|
response *api.PerformAdminEvacuateUserResponse,
|
||||||
) {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformAdminEvacuateUser")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformAdminEvacuateUser", h.roomserverURL+RoomserverPerformAdminEvacuateUserPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverPerformAdminEvacuateUserPath
|
)
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
||||||
if err != nil {
|
|
||||||
res.Error = &api.PerformError{
|
|
||||||
Msg: fmt.Sprintf("failed to communicate with roomserver: %s", err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryLatestEventsAndState implements RoomserverQueryAPI
|
// QueryLatestEventsAndState implements RoomserverQueryAPI
|
||||||
@ -329,11 +277,10 @@ func (h *httpRoomserverInternalAPI) QueryLatestEventsAndState(
|
|||||||
request *api.QueryLatestEventsAndStateRequest,
|
request *api.QueryLatestEventsAndStateRequest,
|
||||||
response *api.QueryLatestEventsAndStateResponse,
|
response *api.QueryLatestEventsAndStateResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryLatestEventsAndState")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryLatestEventsAndState", h.roomserverURL+RoomserverQueryLatestEventsAndStatePath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryLatestEventsAndStatePath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryStateAfterEvents implements RoomserverQueryAPI
|
// QueryStateAfterEvents implements RoomserverQueryAPI
|
||||||
@ -342,11 +289,10 @@ func (h *httpRoomserverInternalAPI) QueryStateAfterEvents(
|
|||||||
request *api.QueryStateAfterEventsRequest,
|
request *api.QueryStateAfterEventsRequest,
|
||||||
response *api.QueryStateAfterEventsResponse,
|
response *api.QueryStateAfterEventsResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryStateAfterEvents")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryStateAfterEvents", h.roomserverURL+RoomserverQueryStateAfterEventsPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryStateAfterEventsPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryEventsByID implements RoomserverQueryAPI
|
// QueryEventsByID implements RoomserverQueryAPI
|
||||||
@ -355,11 +301,10 @@ func (h *httpRoomserverInternalAPI) QueryEventsByID(
|
|||||||
request *api.QueryEventsByIDRequest,
|
request *api.QueryEventsByIDRequest,
|
||||||
response *api.QueryEventsByIDResponse,
|
response *api.QueryEventsByIDResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryEventsByID")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryEventsByID", h.roomserverURL+RoomserverQueryEventsByIDPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryEventsByIDPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) QueryPublishedRooms(
|
func (h *httpRoomserverInternalAPI) QueryPublishedRooms(
|
||||||
@ -367,11 +312,10 @@ func (h *httpRoomserverInternalAPI) QueryPublishedRooms(
|
|||||||
request *api.QueryPublishedRoomsRequest,
|
request *api.QueryPublishedRoomsRequest,
|
||||||
response *api.QueryPublishedRoomsResponse,
|
response *api.QueryPublishedRoomsResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryPublishedRooms")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryPublishedRooms", h.roomserverURL+RoomserverQueryPublishedRoomsPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryPublishedRoomsPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryMembershipForUser implements RoomserverQueryAPI
|
// QueryMembershipForUser implements RoomserverQueryAPI
|
||||||
@ -380,11 +324,10 @@ func (h *httpRoomserverInternalAPI) QueryMembershipForUser(
|
|||||||
request *api.QueryMembershipForUserRequest,
|
request *api.QueryMembershipForUserRequest,
|
||||||
response *api.QueryMembershipForUserResponse,
|
response *api.QueryMembershipForUserResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryMembershipForUser")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryMembershipForUser", h.roomserverURL+RoomserverQueryMembershipForUserPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryMembershipForUserPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryMembershipsForRoom implements RoomserverQueryAPI
|
// QueryMembershipsForRoom implements RoomserverQueryAPI
|
||||||
@ -393,11 +336,10 @@ func (h *httpRoomserverInternalAPI) QueryMembershipsForRoom(
|
|||||||
request *api.QueryMembershipsForRoomRequest,
|
request *api.QueryMembershipsForRoomRequest,
|
||||||
response *api.QueryMembershipsForRoomResponse,
|
response *api.QueryMembershipsForRoomResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryMembershipsForRoom")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryMembershipsForRoom", h.roomserverURL+RoomserverQueryMembershipsForRoomPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryMembershipsForRoomPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryMembershipsForRoom implements RoomserverQueryAPI
|
// QueryMembershipsForRoom implements RoomserverQueryAPI
|
||||||
@ -406,11 +348,10 @@ func (h *httpRoomserverInternalAPI) QueryServerJoinedToRoom(
|
|||||||
request *api.QueryServerJoinedToRoomRequest,
|
request *api.QueryServerJoinedToRoomRequest,
|
||||||
response *api.QueryServerJoinedToRoomResponse,
|
response *api.QueryServerJoinedToRoomResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryServerJoinedToRoom")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryServerJoinedToRoom", h.roomserverURL+RoomserverQueryServerJoinedToRoomPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryServerJoinedToRoomPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryServerAllowedToSeeEvent implements RoomserverQueryAPI
|
// QueryServerAllowedToSeeEvent implements RoomserverQueryAPI
|
||||||
@ -419,11 +360,10 @@ func (h *httpRoomserverInternalAPI) QueryServerAllowedToSeeEvent(
|
|||||||
request *api.QueryServerAllowedToSeeEventRequest,
|
request *api.QueryServerAllowedToSeeEventRequest,
|
||||||
response *api.QueryServerAllowedToSeeEventResponse,
|
response *api.QueryServerAllowedToSeeEventResponse,
|
||||||
) (err error) {
|
) (err error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryServerAllowedToSeeEvent")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryServerAllowedToSeeEvent", h.roomserverURL+RoomserverQueryServerAllowedToSeeEventPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryServerAllowedToSeeEventPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryMissingEvents implements RoomServerQueryAPI
|
// QueryMissingEvents implements RoomServerQueryAPI
|
||||||
@ -432,11 +372,10 @@ func (h *httpRoomserverInternalAPI) QueryMissingEvents(
|
|||||||
request *api.QueryMissingEventsRequest,
|
request *api.QueryMissingEventsRequest,
|
||||||
response *api.QueryMissingEventsResponse,
|
response *api.QueryMissingEventsResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryMissingEvents")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryMissingEvents", h.roomserverURL+RoomserverQueryMissingEventsPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryMissingEventsPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryStateAndAuthChain implements RoomserverQueryAPI
|
// QueryStateAndAuthChain implements RoomserverQueryAPI
|
||||||
@ -445,11 +384,10 @@ func (h *httpRoomserverInternalAPI) QueryStateAndAuthChain(
|
|||||||
request *api.QueryStateAndAuthChainRequest,
|
request *api.QueryStateAndAuthChainRequest,
|
||||||
response *api.QueryStateAndAuthChainResponse,
|
response *api.QueryStateAndAuthChainResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryStateAndAuthChain")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryStateAndAuthChain", h.roomserverURL+RoomserverQueryStateAndAuthChainPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryStateAndAuthChainPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerformBackfill implements RoomServerQueryAPI
|
// PerformBackfill implements RoomServerQueryAPI
|
||||||
@ -458,11 +396,10 @@ func (h *httpRoomserverInternalAPI) PerformBackfill(
|
|||||||
request *api.PerformBackfillRequest,
|
request *api.PerformBackfillRequest,
|
||||||
response *api.PerformBackfillResponse,
|
response *api.PerformBackfillResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformBackfill")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformBackfill", h.roomserverURL+RoomserverPerformBackfillPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverPerformBackfillPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryRoomVersionCapabilities implements RoomServerQueryAPI
|
// QueryRoomVersionCapabilities implements RoomServerQueryAPI
|
||||||
@ -471,11 +408,10 @@ func (h *httpRoomserverInternalAPI) QueryRoomVersionCapabilities(
|
|||||||
request *api.QueryRoomVersionCapabilitiesRequest,
|
request *api.QueryRoomVersionCapabilitiesRequest,
|
||||||
response *api.QueryRoomVersionCapabilitiesResponse,
|
response *api.QueryRoomVersionCapabilitiesResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryRoomVersionCapabilities")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryRoomVersionCapabilities", h.roomserverURL+RoomserverQueryRoomVersionCapabilitiesPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryRoomVersionCapabilitiesPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryRoomVersionForRoom implements RoomServerQueryAPI
|
// QueryRoomVersionForRoom implements RoomServerQueryAPI
|
||||||
@ -488,16 +424,10 @@ func (h *httpRoomserverInternalAPI) QueryRoomVersionForRoom(
|
|||||||
response.RoomVersion = roomVersion
|
response.RoomVersion = roomVersion
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
return httputil.CallInternalRPCAPI(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryRoomVersionForRoom")
|
"QueryRoomVersionForRoom", h.roomserverURL+RoomserverQueryRoomVersionForRoomPath,
|
||||||
defer span.Finish()
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
apiURL := h.roomserverURL + RoomserverQueryRoomVersionForRoomPath
|
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
if err == nil {
|
|
||||||
h.cache.StoreRoomVersion(request.RoomID, response.RoomVersion)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) QueryCurrentState(
|
func (h *httpRoomserverInternalAPI) QueryCurrentState(
|
||||||
@ -505,11 +435,10 @@ func (h *httpRoomserverInternalAPI) QueryCurrentState(
|
|||||||
request *api.QueryCurrentStateRequest,
|
request *api.QueryCurrentStateRequest,
|
||||||
response *api.QueryCurrentStateResponse,
|
response *api.QueryCurrentStateResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryCurrentState")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryCurrentState", h.roomserverURL+RoomserverQueryCurrentStatePath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryCurrentStatePath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) QueryRoomsForUser(
|
func (h *httpRoomserverInternalAPI) QueryRoomsForUser(
|
||||||
@ -517,11 +446,10 @@ func (h *httpRoomserverInternalAPI) QueryRoomsForUser(
|
|||||||
request *api.QueryRoomsForUserRequest,
|
request *api.QueryRoomsForUserRequest,
|
||||||
response *api.QueryRoomsForUserResponse,
|
response *api.QueryRoomsForUserResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryRoomsForUser")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryRoomsForUser", h.roomserverURL+RoomserverQueryRoomsForUserPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryRoomsForUserPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) QueryBulkStateContent(
|
func (h *httpRoomserverInternalAPI) QueryBulkStateContent(
|
||||||
@ -529,68 +457,75 @@ func (h *httpRoomserverInternalAPI) QueryBulkStateContent(
|
|||||||
request *api.QueryBulkStateContentRequest,
|
request *api.QueryBulkStateContentRequest,
|
||||||
response *api.QueryBulkStateContentResponse,
|
response *api.QueryBulkStateContentResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryBulkStateContent")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryBulkStateContent", h.roomserverURL+RoomserverQueryBulkStateContentPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryBulkStateContentPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) QuerySharedUsers(
|
func (h *httpRoomserverInternalAPI) QuerySharedUsers(
|
||||||
ctx context.Context, req *api.QuerySharedUsersRequest, res *api.QuerySharedUsersResponse,
|
ctx context.Context,
|
||||||
|
request *api.QuerySharedUsersRequest,
|
||||||
|
response *api.QuerySharedUsersResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QuerySharedUsers")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QuerySharedUsers", h.roomserverURL+RoomserverQuerySharedUsersPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQuerySharedUsersPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) QueryKnownUsers(
|
func (h *httpRoomserverInternalAPI) QueryKnownUsers(
|
||||||
ctx context.Context, req *api.QueryKnownUsersRequest, res *api.QueryKnownUsersResponse,
|
ctx context.Context,
|
||||||
|
request *api.QueryKnownUsersRequest,
|
||||||
|
response *api.QueryKnownUsersResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryKnownUsers")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryKnownUsers", h.roomserverURL+RoomserverQueryKnownUsersPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryKnownUsersPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) QueryAuthChain(
|
func (h *httpRoomserverInternalAPI) QueryAuthChain(
|
||||||
ctx context.Context, req *api.QueryAuthChainRequest, res *api.QueryAuthChainResponse,
|
ctx context.Context,
|
||||||
|
request *api.QueryAuthChainRequest,
|
||||||
|
response *api.QueryAuthChainResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryAuthChain")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryAuthChain", h.roomserverURL+RoomserverQueryAuthChainPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryAuthChainPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) QueryServerBannedFromRoom(
|
func (h *httpRoomserverInternalAPI) QueryServerBannedFromRoom(
|
||||||
ctx context.Context, req *api.QueryServerBannedFromRoomRequest, res *api.QueryServerBannedFromRoomResponse,
|
ctx context.Context,
|
||||||
|
request *api.QueryServerBannedFromRoomRequest,
|
||||||
|
response *api.QueryServerBannedFromRoomResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryServerBannedFromRoom")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryServerBannedFromRoom", h.roomserverURL+RoomserverQueryServerBannedFromRoomPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryServerBannedFromRoomPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) QueryRestrictedJoinAllowed(
|
func (h *httpRoomserverInternalAPI) QueryRestrictedJoinAllowed(
|
||||||
ctx context.Context, req *api.QueryRestrictedJoinAllowedRequest, res *api.QueryRestrictedJoinAllowedResponse,
|
ctx context.Context,
|
||||||
|
request *api.QueryRestrictedJoinAllowedRequest,
|
||||||
|
response *api.QueryRestrictedJoinAllowedResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryRestrictedJoinAllowed")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryRestrictedJoinAllowed", h.roomserverURL+RoomserverQueryRestrictedJoinAllowed,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.roomserverURL + RoomserverQueryRestrictedJoinAllowed
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformForget(ctx context.Context, req *api.PerformForgetRequest, res *api.PerformForgetResponse) error {
|
func (h *httpRoomserverInternalAPI) PerformForget(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformForget")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.PerformForgetRequest,
|
||||||
|
response *api.PerformForgetResponse,
|
||||||
apiURL := h.roomserverURL + RoomserverPerformForgetPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"PerformForget", h.roomserverURL+RoomserverPerformForgetPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,499 +1,196 @@
|
|||||||
package inthttp
|
package inthttp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddRoutes adds the RoomserverInternalAPI handlers to the http.ServeMux.
|
// AddRoutes adds the RoomserverInternalAPI handlers to the http.ServeMux.
|
||||||
// nolint: gocyclo
|
// nolint: gocyclo
|
||||||
func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
||||||
internalAPIMux.Handle(RoomserverInputRoomEventsPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse {
|
RoomserverInputRoomEventsPath,
|
||||||
var request api.InputRoomEventsRequest
|
httputil.MakeInternalRPCAPI("RoomserverInputRoomEvents", r.InputRoomEvents),
|
||||||
var response api.InputRoomEventsResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.InputRoomEvents(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformInvitePath,
|
|
||||||
httputil.MakeInternalAPI("performInvite", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformInviteRequest
|
RoomserverPerformInvitePath,
|
||||||
var response api.PerformInviteResponse
|
httputil.MakeInternalRPCAPI("RoomserverPerformInvite", r.PerformInvite),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.PerformInvite(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformJoinPath,
|
|
||||||
httputil.MakeInternalAPI("performJoin", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformJoinRequest
|
RoomserverPerformJoinPath,
|
||||||
var response api.PerformJoinResponse
|
httputil.MakeInternalRPCAPI("RoomserverPerformJoin", r.PerformJoin),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformJoin(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformLeavePath,
|
|
||||||
httputil.MakeInternalAPI("performLeave", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformLeaveRequest
|
RoomserverPerformLeavePath,
|
||||||
var response api.PerformLeaveResponse
|
httputil.MakeInternalRPCAPI("RoomserverPerformLeave", r.PerformLeave),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.PerformLeave(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformPeekPath,
|
|
||||||
httputil.MakeInternalAPI("performPeek", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformPeekRequest
|
RoomserverPerformPeekPath,
|
||||||
var response api.PerformPeekResponse
|
httputil.MakeInternalRPCAPI("RoomserverPerformPeek", r.PerformPeek),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformPeek(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformInboundPeekPath,
|
|
||||||
httputil.MakeInternalAPI("performInboundPeek", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformInboundPeekRequest
|
RoomserverPerformInboundPeekPath,
|
||||||
var response api.PerformInboundPeekResponse
|
httputil.MakeInternalRPCAPI("RoomserverPerformInboundPeek", r.PerformInboundPeek),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.PerformInboundPeek(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformPeekPath,
|
|
||||||
httputil.MakeInternalAPI("performUnpeek", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformUnpeekRequest
|
RoomserverPerformUnpeekPath,
|
||||||
var response api.PerformUnpeekResponse
|
httputil.MakeInternalRPCAPI("RoomserverPerformUnpeek", r.PerformUnpeek),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformUnpeek(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformRoomUpgradePath,
|
|
||||||
httputil.MakeInternalAPI("performRoomUpgrade", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformRoomUpgradeRequest
|
RoomserverPerformRoomUpgradePath,
|
||||||
var response api.PerformRoomUpgradeResponse
|
httputil.MakeInternalRPCAPI("RoomserverPerformRoomUpgrade", r.PerformRoomUpgrade),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformRoomUpgrade(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformPublishPath,
|
|
||||||
httputil.MakeInternalAPI("performPublish", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformPublishRequest
|
RoomserverPerformPublishPath,
|
||||||
var response api.PerformPublishResponse
|
httputil.MakeInternalRPCAPI("RoomserverPerformPublish", r.PerformPublish),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformPublish(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformAdminEvacuateRoomPath,
|
|
||||||
httputil.MakeInternalAPI("performAdminEvacuateRoom", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformAdminEvacuateRoomRequest
|
RoomserverPerformAdminEvacuateRoomPath,
|
||||||
var response api.PerformAdminEvacuateRoomResponse
|
httputil.MakeInternalRPCAPI("RoomserverPerformAdminEvacuateRoom", r.PerformAdminEvacuateRoom),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformAdminEvacuateRoom(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformAdminEvacuateUserPath,
|
|
||||||
httputil.MakeInternalAPI("performAdminEvacuateUser", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformAdminEvacuateUserRequest
|
RoomserverPerformAdminEvacuateUserPath,
|
||||||
var response api.PerformAdminEvacuateUserResponse
|
httputil.MakeInternalRPCAPI("RoomserverPerformAdminEvacuateUser", r.PerformAdminEvacuateUser),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformAdminEvacuateUser(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryPublishedRoomsPath,
|
RoomserverQueryPublishedRoomsPath,
|
||||||
httputil.MakeInternalAPI("queryPublishedRooms", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverQueryPublishedRooms", r.QueryPublishedRooms),
|
||||||
var request api.QueryPublishedRoomsRequest
|
|
||||||
var response api.QueryPublishedRoomsResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryPublishedRooms(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryLatestEventsAndStatePath,
|
RoomserverQueryLatestEventsAndStatePath,
|
||||||
httputil.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverQueryLatestEventsAndState", r.QueryLatestEventsAndState),
|
||||||
var request api.QueryLatestEventsAndStateRequest
|
|
||||||
var response api.QueryLatestEventsAndStateResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryLatestEventsAndState(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryStateAfterEventsPath,
|
RoomserverQueryStateAfterEventsPath,
|
||||||
httputil.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverQueryStateAfterEvents", r.QueryStateAfterEvents),
|
||||||
var request api.QueryStateAfterEventsRequest
|
|
||||||
var response api.QueryStateAfterEventsResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryStateAfterEvents(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryEventsByIDPath,
|
RoomserverQueryEventsByIDPath,
|
||||||
httputil.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverQueryEventsByID", r.QueryEventsByID),
|
||||||
var request api.QueryEventsByIDRequest
|
|
||||||
var response api.QueryEventsByIDResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryEventsByID(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryMembershipForUserPath,
|
RoomserverQueryMembershipForUserPath,
|
||||||
httputil.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverQueryMembershipForUser", r.QueryMembershipForUser),
|
||||||
var request api.QueryMembershipForUserRequest
|
|
||||||
var response api.QueryMembershipForUserResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryMembershipForUser(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryMembershipsForRoomPath,
|
RoomserverQueryMembershipsForRoomPath,
|
||||||
httputil.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverQueryMembershipsForRoom", r.QueryMembershipsForRoom),
|
||||||
var request api.QueryMembershipsForRoomRequest
|
|
||||||
var response api.QueryMembershipsForRoomResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryMembershipsForRoom(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryServerJoinedToRoomPath,
|
RoomserverQueryServerJoinedToRoomPath,
|
||||||
httputil.MakeInternalAPI("queryServerJoinedToRoom", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverQueryServerJoinedToRoom", r.QueryServerJoinedToRoom),
|
||||||
var request api.QueryServerJoinedToRoomRequest
|
|
||||||
var response api.QueryServerJoinedToRoomResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryServerJoinedToRoom(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryServerAllowedToSeeEventPath,
|
RoomserverQueryServerAllowedToSeeEventPath,
|
||||||
httputil.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverQueryServerAllowedToSeeEvent", r.QueryServerAllowedToSeeEvent),
|
||||||
var request api.QueryServerAllowedToSeeEventRequest
|
|
||||||
var response api.QueryServerAllowedToSeeEventResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryServerAllowedToSeeEvent(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryMissingEventsPath,
|
RoomserverQueryMissingEventsPath,
|
||||||
httputil.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverQueryMissingEvents", r.QueryMissingEvents),
|
||||||
var request api.QueryMissingEventsRequest
|
|
||||||
var response api.QueryMissingEventsResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryMissingEvents(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryStateAndAuthChainPath,
|
RoomserverQueryStateAndAuthChainPath,
|
||||||
httputil.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverQueryStateAndAuthChain", r.QueryStateAndAuthChain),
|
||||||
var request api.QueryStateAndAuthChainRequest
|
|
||||||
var response api.QueryStateAndAuthChainResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryStateAndAuthChain(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverPerformBackfillPath,
|
RoomserverPerformBackfillPath,
|
||||||
httputil.MakeInternalAPI("PerformBackfill", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverPerformBackfill", r.PerformBackfill),
|
||||||
var request api.PerformBackfillRequest
|
|
||||||
var response api.PerformBackfillResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.PerformBackfill(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverPerformForgetPath,
|
RoomserverPerformForgetPath,
|
||||||
httputil.MakeInternalAPI("PerformForget", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverPerformForget", r.PerformForget),
|
||||||
var request api.PerformForgetRequest
|
|
||||||
var response api.PerformForgetResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.PerformForget(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryRoomVersionCapabilitiesPath,
|
RoomserverQueryRoomVersionCapabilitiesPath,
|
||||||
httputil.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverQueryRoomVersionCapabilities", r.QueryRoomVersionCapabilities),
|
||||||
var request api.QueryRoomVersionCapabilitiesRequest
|
|
||||||
var response api.QueryRoomVersionCapabilitiesResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryRoomVersionCapabilities(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryRoomVersionForRoomPath,
|
RoomserverQueryRoomVersionForRoomPath,
|
||||||
httputil.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverQueryRoomVersionForRoom", r.QueryRoomVersionForRoom),
|
||||||
var request api.QueryRoomVersionForRoomRequest
|
|
||||||
var response api.QueryRoomVersionForRoomResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryRoomVersionForRoom(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverSetRoomAliasPath,
|
RoomserverSetRoomAliasPath,
|
||||||
httputil.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverSetRoomAlias", r.SetRoomAlias),
|
||||||
var request api.SetRoomAliasRequest
|
|
||||||
var response api.SetRoomAliasResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.SetRoomAlias(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverGetRoomIDForAliasPath,
|
RoomserverGetRoomIDForAliasPath,
|
||||||
httputil.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverGetRoomIDForAlias", r.GetRoomIDForAlias),
|
||||||
var request api.GetRoomIDForAliasRequest
|
|
||||||
var response api.GetRoomIDForAliasResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.GetRoomIDForAlias(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverGetAliasesForRoomIDPath,
|
RoomserverGetAliasesForRoomIDPath,
|
||||||
httputil.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverGetAliasesForRoomID", r.GetAliasesForRoomID),
|
||||||
var request api.GetAliasesForRoomIDRequest
|
|
||||||
var response api.GetAliasesForRoomIDResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.GetAliasesForRoomID(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverRemoveRoomAliasPath,
|
RoomserverRemoveRoomAliasPath,
|
||||||
httputil.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RoomserverRemoveRoomAlias", r.RemoveRoomAlias),
|
||||||
var request api.RemoveRoomAliasRequest
|
|
||||||
var response api.RemoveRoomAliasResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.RemoveRoomAlias(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryCurrentStatePath,
|
|
||||||
httputil.MakeInternalAPI("queryCurrentState", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryCurrentStateRequest{}
|
RoomserverQueryCurrentStatePath,
|
||||||
response := api.QueryCurrentStateResponse{}
|
httputil.MakeInternalRPCAPI("RoomserverQueryCurrentState", r.QueryCurrentState),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryCurrentState(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryRoomsForUserPath,
|
|
||||||
httputil.MakeInternalAPI("queryRoomsForUser", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryRoomsForUserRequest{}
|
RoomserverQueryRoomsForUserPath,
|
||||||
response := api.QueryRoomsForUserResponse{}
|
httputil.MakeInternalRPCAPI("RoomserverQueryRoomsForUser", r.QueryRoomsForUser),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryRoomsForUser(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryBulkStateContentPath,
|
|
||||||
httputil.MakeInternalAPI("queryBulkStateContent", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryBulkStateContentRequest{}
|
RoomserverQueryBulkStateContentPath,
|
||||||
response := api.QueryBulkStateContentResponse{}
|
httputil.MakeInternalRPCAPI("RoomserverQueryBulkStateContent", r.QueryBulkStateContent),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryBulkStateContent(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQuerySharedUsersPath,
|
|
||||||
httputil.MakeInternalAPI("querySharedUsers", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QuerySharedUsersRequest{}
|
RoomserverQuerySharedUsersPath,
|
||||||
response := api.QuerySharedUsersResponse{}
|
httputil.MakeInternalRPCAPI("RoomserverQuerySharedUsers", r.QuerySharedUsers),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QuerySharedUsers(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryKnownUsersPath,
|
|
||||||
httputil.MakeInternalAPI("queryKnownUsers", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryKnownUsersRequest{}
|
RoomserverQueryKnownUsersPath,
|
||||||
response := api.QueryKnownUsersResponse{}
|
httputil.MakeInternalRPCAPI("RoomserverQueryKnownUsers", r.QueryKnownUsers),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryKnownUsers(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryServerBannedFromRoomPath,
|
|
||||||
httputil.MakeInternalAPI("queryServerBannedFromRoom", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryServerBannedFromRoomRequest{}
|
RoomserverQueryServerBannedFromRoomPath,
|
||||||
response := api.QueryServerBannedFromRoomResponse{}
|
httputil.MakeInternalRPCAPI("RoomserverQueryServerBannedFromRoom", r.QueryServerBannedFromRoom),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryServerBannedFromRoom(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryAuthChainPath,
|
|
||||||
httputil.MakeInternalAPI("queryAuthChain", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryAuthChainRequest{}
|
RoomserverQueryAuthChainPath,
|
||||||
response := api.QueryAuthChainResponse{}
|
httputil.MakeInternalRPCAPI("RoomserverQueryAuthChain", r.QueryAuthChain),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryAuthChain(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryRestrictedJoinAllowed,
|
|
||||||
httputil.MakeInternalAPI("queryRestrictedJoinAllowed", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryRestrictedJoinAllowedRequest{}
|
RoomserverQueryRestrictedJoinAllowed,
|
||||||
response := api.QueryRestrictedJoinAllowedResponse{}
|
httputil.MakeInternalRPCAPI("RoomserverQueryRestrictedJoinAllowed", r.QueryRestrictedJoinAllowed),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryRestrictedJoinAllowed(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -164,9 +164,9 @@ func TestMSC2836(t *testing.T) {
|
|||||||
// make everyone joined to each other's rooms
|
// make everyone joined to each other's rooms
|
||||||
nopRsAPI := &testRoomserverAPI{
|
nopRsAPI := &testRoomserverAPI{
|
||||||
userToJoinedRooms: map[string][]string{
|
userToJoinedRooms: map[string][]string{
|
||||||
alice: []string{roomID},
|
alice: {roomID},
|
||||||
bob: []string{roomID},
|
bob: {roomID},
|
||||||
charlie: []string{roomID},
|
charlie: {roomID},
|
||||||
},
|
},
|
||||||
events: map[string]*gomatrixserverlib.HeaderedEvent{
|
events: map[string]*gomatrixserverlib.HeaderedEvent{
|
||||||
eventA.EventID(): eventA,
|
eventA.EventID(): eventA,
|
||||||
|
@ -31,7 +31,7 @@ import (
|
|||||||
// DeviceOTKCounts adds one-time key counts to the /sync response
|
// DeviceOTKCounts adds one-time key counts to the /sync response
|
||||||
func DeviceOTKCounts(ctx context.Context, keyAPI keyapi.SyncKeyAPI, userID, deviceID string, res *types.Response) error {
|
func DeviceOTKCounts(ctx context.Context, keyAPI keyapi.SyncKeyAPI, userID, deviceID string, res *types.Response) error {
|
||||||
var queryRes keyapi.QueryOneTimeKeysResponse
|
var queryRes keyapi.QueryOneTimeKeysResponse
|
||||||
keyAPI.QueryOneTimeKeys(ctx, &keyapi.QueryOneTimeKeysRequest{
|
_ = keyAPI.QueryOneTimeKeys(ctx, &keyapi.QueryOneTimeKeysRequest{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
DeviceID: deviceID,
|
DeviceID: deviceID,
|
||||||
}, &queryRes)
|
}, &queryRes)
|
||||||
@ -73,7 +73,7 @@ func DeviceListCatchup(
|
|||||||
offset = int64(from)
|
offset = int64(from)
|
||||||
}
|
}
|
||||||
var queryRes keyapi.QueryKeyChangesResponse
|
var queryRes keyapi.QueryKeyChangesResponse
|
||||||
keyAPI.QueryKeyChanges(ctx, &keyapi.QueryKeyChangesRequest{
|
_ = keyAPI.QueryKeyChanges(ctx, &keyapi.QueryKeyChangesRequest{
|
||||||
Offset: offset,
|
Offset: offset,
|
||||||
ToOffset: toOffset,
|
ToOffset: toOffset,
|
||||||
}, &queryRes)
|
}, &queryRes)
|
||||||
|
@ -22,31 +22,41 @@ var (
|
|||||||
|
|
||||||
type mockKeyAPI struct{}
|
type mockKeyAPI struct{}
|
||||||
|
|
||||||
func (k *mockKeyAPI) PerformUploadKeys(ctx context.Context, req *keyapi.PerformUploadKeysRequest, res *keyapi.PerformUploadKeysResponse) {
|
func (k *mockKeyAPI) PerformUploadKeys(ctx context.Context, req *keyapi.PerformUploadKeysRequest, res *keyapi.PerformUploadKeysResponse) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *mockKeyAPI) SetUserAPI(i userapi.UserInternalAPI) {}
|
func (k *mockKeyAPI) SetUserAPI(i userapi.UserInternalAPI) {}
|
||||||
|
|
||||||
// PerformClaimKeys claims one-time keys for use in pre-key messages
|
// PerformClaimKeys claims one-time keys for use in pre-key messages
|
||||||
func (k *mockKeyAPI) PerformClaimKeys(ctx context.Context, req *keyapi.PerformClaimKeysRequest, res *keyapi.PerformClaimKeysResponse) {
|
func (k *mockKeyAPI) PerformClaimKeys(ctx context.Context, req *keyapi.PerformClaimKeysRequest, res *keyapi.PerformClaimKeysResponse) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
func (k *mockKeyAPI) PerformDeleteKeys(ctx context.Context, req *keyapi.PerformDeleteKeysRequest, res *keyapi.PerformDeleteKeysResponse) {
|
func (k *mockKeyAPI) PerformDeleteKeys(ctx context.Context, req *keyapi.PerformDeleteKeysRequest, res *keyapi.PerformDeleteKeysResponse) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
func (k *mockKeyAPI) PerformUploadDeviceKeys(ctx context.Context, req *keyapi.PerformUploadDeviceKeysRequest, res *keyapi.PerformUploadDeviceKeysResponse) {
|
func (k *mockKeyAPI) PerformUploadDeviceKeys(ctx context.Context, req *keyapi.PerformUploadDeviceKeysRequest, res *keyapi.PerformUploadDeviceKeysResponse) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
func (k *mockKeyAPI) PerformUploadDeviceSignatures(ctx context.Context, req *keyapi.PerformUploadDeviceSignaturesRequest, res *keyapi.PerformUploadDeviceSignaturesResponse) {
|
func (k *mockKeyAPI) PerformUploadDeviceSignatures(ctx context.Context, req *keyapi.PerformUploadDeviceSignaturesRequest, res *keyapi.PerformUploadDeviceSignaturesResponse) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
func (k *mockKeyAPI) QueryKeys(ctx context.Context, req *keyapi.QueryKeysRequest, res *keyapi.QueryKeysResponse) {
|
func (k *mockKeyAPI) QueryKeys(ctx context.Context, req *keyapi.QueryKeysRequest, res *keyapi.QueryKeysResponse) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
func (k *mockKeyAPI) QueryKeyChanges(ctx context.Context, req *keyapi.QueryKeyChangesRequest, res *keyapi.QueryKeyChangesResponse) {
|
func (k *mockKeyAPI) QueryKeyChanges(ctx context.Context, req *keyapi.QueryKeyChangesRequest, res *keyapi.QueryKeyChangesResponse) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
func (k *mockKeyAPI) QueryOneTimeKeys(ctx context.Context, req *keyapi.QueryOneTimeKeysRequest, res *keyapi.QueryOneTimeKeysResponse) {
|
func (k *mockKeyAPI) QueryOneTimeKeys(ctx context.Context, req *keyapi.QueryOneTimeKeysRequest, res *keyapi.QueryOneTimeKeysResponse) error {
|
||||||
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
func (k *mockKeyAPI) QueryDeviceMessages(ctx context.Context, req *keyapi.QueryDeviceMessagesRequest, res *keyapi.QueryDeviceMessagesResponse) {
|
func (k *mockKeyAPI) QueryDeviceMessages(ctx context.Context, req *keyapi.QueryDeviceMessagesRequest, res *keyapi.QueryDeviceMessagesResponse) error {
|
||||||
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
func (k *mockKeyAPI) QuerySignatures(ctx context.Context, req *keyapi.QuerySignaturesRequest, res *keyapi.QuerySignaturesResponse) {
|
func (k *mockKeyAPI) QuerySignatures(ctx context.Context, req *keyapi.QuerySignaturesRequest, res *keyapi.QuerySignaturesResponse) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockRoomserverAPI struct {
|
type mockRoomserverAPI struct {
|
||||||
|
@ -78,10 +78,11 @@ type syncKeyAPI struct {
|
|||||||
keyapi.SyncKeyAPI
|
keyapi.SyncKeyAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *syncKeyAPI) QueryKeyChanges(ctx context.Context, req *keyapi.QueryKeyChangesRequest, res *keyapi.QueryKeyChangesResponse) {
|
func (s *syncKeyAPI) QueryKeyChanges(ctx context.Context, req *keyapi.QueryKeyChangesRequest, res *keyapi.QueryKeyChangesResponse) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
func (s *syncKeyAPI) QueryOneTimeKeys(ctx context.Context, req *keyapi.QueryOneTimeKeysRequest, res *keyapi.QueryOneTimeKeysResponse) {
|
func (s *syncKeyAPI) QueryOneTimeKeys(ctx context.Context, req *keyapi.QueryOneTimeKeysRequest, res *keyapi.QueryOneTimeKeysResponse) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncAPIAccessTokens(t *testing.T) {
|
func TestSyncAPIAccessTokens(t *testing.T) {
|
||||||
|
@ -100,7 +100,7 @@ type ClientUserAPI interface {
|
|||||||
QueryNotifications(ctx context.Context, req *QueryNotificationsRequest, res *QueryNotificationsResponse) error
|
QueryNotifications(ctx context.Context, req *QueryNotificationsRequest, res *QueryNotificationsResponse) error
|
||||||
InputAccountData(ctx context.Context, req *InputAccountDataRequest, res *InputAccountDataResponse) error
|
InputAccountData(ctx context.Context, req *InputAccountDataRequest, res *InputAccountDataResponse) error
|
||||||
PerformKeyBackup(ctx context.Context, req *PerformKeyBackupRequest, res *PerformKeyBackupResponse) error
|
PerformKeyBackup(ctx context.Context, req *PerformKeyBackupRequest, res *PerformKeyBackupResponse) error
|
||||||
QueryKeyBackup(ctx context.Context, req *QueryKeyBackupRequest, res *QueryKeyBackupResponse)
|
QueryKeyBackup(ctx context.Context, req *QueryKeyBackupRequest, res *QueryKeyBackupResponse) error
|
||||||
|
|
||||||
QueryThreePIDsForLocalpart(ctx context.Context, req *QueryThreePIDsForLocalpartRequest, res *QueryThreePIDsForLocalpartResponse) error
|
QueryThreePIDsForLocalpart(ctx context.Context, req *QueryThreePIDsForLocalpartRequest, res *QueryThreePIDsForLocalpartResponse) error
|
||||||
QueryLocalpartForThreePID(ctx context.Context, req *QueryLocalpartForThreePIDRequest, res *QueryLocalpartForThreePIDResponse) error
|
QueryLocalpartForThreePID(ctx context.Context, req *QueryLocalpartForThreePIDRequest, res *QueryLocalpartForThreePIDResponse) error
|
||||||
|
@ -94,9 +94,10 @@ func (t *UserInternalAPITrace) PerformPushRulesPut(ctx context.Context, req *Per
|
|||||||
util.GetLogger(ctx).Infof("PerformPushRulesPut req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).Infof("PerformPushRulesPut req=%+v res=%+v", js(req), js(res))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (t *UserInternalAPITrace) QueryKeyBackup(ctx context.Context, req *QueryKeyBackupRequest, res *QueryKeyBackupResponse) {
|
func (t *UserInternalAPITrace) QueryKeyBackup(ctx context.Context, req *QueryKeyBackupRequest, res *QueryKeyBackupResponse) error {
|
||||||
t.Impl.QueryKeyBackup(ctx, req, res)
|
err := t.Impl.QueryKeyBackup(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("QueryKeyBackup req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).Infof("QueryKeyBackup req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
func (t *UserInternalAPITrace) QueryProfile(ctx context.Context, req *QueryProfileRequest, res *QueryProfileResponse) error {
|
func (t *UserInternalAPITrace) QueryProfile(ctx context.Context, req *QueryProfileRequest, res *QueryProfileResponse) error {
|
||||||
err := t.Impl.QueryProfile(ctx, req, res)
|
err := t.Impl.QueryProfile(ctx, req, res)
|
||||||
|
@ -192,7 +192,9 @@ func (a *UserInternalAPI) PerformDeviceDeletion(ctx context.Context, req *api.Pe
|
|||||||
deleteReq.KeyIDs = append(deleteReq.KeyIDs, gomatrixserverlib.KeyID(keyID))
|
deleteReq.KeyIDs = append(deleteReq.KeyIDs, gomatrixserverlib.KeyID(keyID))
|
||||||
}
|
}
|
||||||
deleteRes := &keyapi.PerformDeleteKeysResponse{}
|
deleteRes := &keyapi.PerformDeleteKeysResponse{}
|
||||||
a.KeyAPI.PerformDeleteKeys(ctx, deleteReq, deleteRes)
|
if err := a.KeyAPI.PerformDeleteKeys(ctx, deleteReq, deleteRes); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := deleteRes.Error; err != nil {
|
if err := deleteRes.Error; err != nil {
|
||||||
return fmt.Errorf("a.KeyAPI.PerformDeleteKeys: %w", err)
|
return fmt.Errorf("a.KeyAPI.PerformDeleteKeys: %w", err)
|
||||||
}
|
}
|
||||||
@ -211,10 +213,12 @@ func (a *UserInternalAPI) deviceListUpdate(userID string, deviceIDs []string) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
var uploadRes keyapi.PerformUploadKeysResponse
|
var uploadRes keyapi.PerformUploadKeysResponse
|
||||||
a.KeyAPI.PerformUploadKeys(context.Background(), &keyapi.PerformUploadKeysRequest{
|
if err := a.KeyAPI.PerformUploadKeys(context.Background(), &keyapi.PerformUploadKeysRequest{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
DeviceKeys: deviceKeys,
|
DeviceKeys: deviceKeys,
|
||||||
}, &uploadRes)
|
}, &uploadRes); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if uploadRes.Error != nil {
|
if uploadRes.Error != nil {
|
||||||
return fmt.Errorf("failed to delete device keys: %v", uploadRes.Error)
|
return fmt.Errorf("failed to delete device keys: %v", uploadRes.Error)
|
||||||
}
|
}
|
||||||
@ -268,7 +272,7 @@ func (a *UserInternalAPI) PerformDeviceUpdate(ctx context.Context, req *api.Perf
|
|||||||
if req.DisplayName != nil && dev.DisplayName != *req.DisplayName {
|
if req.DisplayName != nil && dev.DisplayName != *req.DisplayName {
|
||||||
// display name has changed: update the device key
|
// display name has changed: update the device key
|
||||||
var uploadRes keyapi.PerformUploadKeysResponse
|
var uploadRes keyapi.PerformUploadKeysResponse
|
||||||
a.KeyAPI.PerformUploadKeys(context.Background(), &keyapi.PerformUploadKeysRequest{
|
if err := a.KeyAPI.PerformUploadKeys(context.Background(), &keyapi.PerformUploadKeysRequest{
|
||||||
UserID: req.RequestingUserID,
|
UserID: req.RequestingUserID,
|
||||||
DeviceKeys: []keyapi.DeviceKeys{
|
DeviceKeys: []keyapi.DeviceKeys{
|
||||||
{
|
{
|
||||||
@ -279,7 +283,9 @@ func (a *UserInternalAPI) PerformDeviceUpdate(ctx context.Context, req *api.Perf
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
OnlyDisplayNameUpdates: true,
|
OnlyDisplayNameUpdates: true,
|
||||||
}, &uploadRes)
|
}, &uploadRes); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if uploadRes.Error != nil {
|
if uploadRes.Error != nil {
|
||||||
return fmt.Errorf("failed to update device key display name: %v", uploadRes.Error)
|
return fmt.Errorf("failed to update device key display name: %v", uploadRes.Error)
|
||||||
}
|
}
|
||||||
@ -479,7 +485,9 @@ func (a *UserInternalAPI) PerformAccountDeactivation(ctx context.Context, req *a
|
|||||||
UserID: fmt.Sprintf("@%s:%s", req.Localpart, a.ServerName),
|
UserID: fmt.Sprintf("@%s:%s", req.Localpart, a.ServerName),
|
||||||
}
|
}
|
||||||
evacuateRes := &rsapi.PerformAdminEvacuateUserResponse{}
|
evacuateRes := &rsapi.PerformAdminEvacuateUserResponse{}
|
||||||
a.RSAPI.PerformAdminEvacuateUser(ctx, evacuateReq, evacuateRes)
|
if err := a.RSAPI.PerformAdminEvacuateUser(ctx, evacuateReq, evacuateRes); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := evacuateRes.Error; err != nil {
|
if err := evacuateRes.Error; err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to evacuate user after account deactivation")
|
logrus.WithError(err).Errorf("Failed to evacuate user after account deactivation")
|
||||||
}
|
}
|
||||||
@ -538,9 +546,6 @@ func (a *UserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.Perform
|
|||||||
if req.Version == "" {
|
if req.Version == "" {
|
||||||
res.BadInput = true
|
res.BadInput = true
|
||||||
res.Error = "must specify a version to delete"
|
res.Error = "must specify a version to delete"
|
||||||
if res.Error != "" {
|
|
||||||
return fmt.Errorf(res.Error)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
exists, err := a.DB.DeleteKeyBackup(ctx, req.UserID, req.Version)
|
exists, err := a.DB.DeleteKeyBackup(ctx, req.UserID, req.Version)
|
||||||
@ -549,9 +554,6 @@ func (a *UserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.Perform
|
|||||||
}
|
}
|
||||||
res.Exists = exists
|
res.Exists = exists
|
||||||
res.Version = req.Version
|
res.Version = req.Version
|
||||||
if res.Error != "" {
|
|
||||||
return fmt.Errorf(res.Error)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// Create metadata
|
// Create metadata
|
||||||
@ -562,9 +564,6 @@ func (a *UserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.Perform
|
|||||||
}
|
}
|
||||||
res.Exists = err == nil
|
res.Exists = err == nil
|
||||||
res.Version = version
|
res.Version = version
|
||||||
if res.Error != "" {
|
|
||||||
return fmt.Errorf(res.Error)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// Update metadata
|
// Update metadata
|
||||||
@ -575,16 +574,10 @@ func (a *UserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.Perform
|
|||||||
}
|
}
|
||||||
res.Exists = err == nil
|
res.Exists = err == nil
|
||||||
res.Version = req.Version
|
res.Version = req.Version
|
||||||
if res.Error != "" {
|
|
||||||
return fmt.Errorf(res.Error)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// Upload Keys for a specific version metadata
|
// Upload Keys for a specific version metadata
|
||||||
a.uploadBackupKeys(ctx, req, res)
|
a.uploadBackupKeys(ctx, req, res)
|
||||||
if res.Error != "" {
|
|
||||||
return fmt.Errorf(res.Error)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,16 +620,16 @@ func (a *UserInternalAPI) uploadBackupKeys(ctx context.Context, req *api.Perform
|
|||||||
res.KeyETag = etag
|
res.KeyETag = etag
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *UserInternalAPI) QueryKeyBackup(ctx context.Context, req *api.QueryKeyBackupRequest, res *api.QueryKeyBackupResponse) {
|
func (a *UserInternalAPI) QueryKeyBackup(ctx context.Context, req *api.QueryKeyBackupRequest, res *api.QueryKeyBackupResponse) error {
|
||||||
version, algorithm, authData, etag, deleted, err := a.DB.GetKeyBackup(ctx, req.UserID, req.Version)
|
version, algorithm, authData, etag, deleted, err := a.DB.GetKeyBackup(ctx, req.UserID, req.Version)
|
||||||
res.Version = version
|
res.Version = version
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
res.Exists = false
|
res.Exists = false
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
res.Error = fmt.Sprintf("failed to query key backup: %s", err)
|
res.Error = fmt.Sprintf("failed to query key backup: %s", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
res.Algorithm = algorithm
|
res.Algorithm = algorithm
|
||||||
res.AuthData = authData
|
res.AuthData = authData
|
||||||
@ -648,15 +641,16 @@ func (a *UserInternalAPI) QueryKeyBackup(ctx context.Context, req *api.QueryKeyB
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = fmt.Sprintf("failed to count keys: %s", err)
|
res.Error = fmt.Sprintf("failed to count keys: %s", err)
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := a.DB.GetBackupKeys(ctx, version, req.UserID, req.KeysForRoomID, req.KeysForSessionID)
|
result, err := a.DB.GetBackupKeys(ctx, version, req.UserID, req.KeysForRoomID, req.KeysForSessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = fmt.Sprintf("failed to query keys: %s", err)
|
res.Error = fmt.Sprintf("failed to query keys: %s", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
res.Keys = result
|
res.Keys = result
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *UserInternalAPI) QueryNotifications(ctx context.Context, req *api.QueryNotificationsRequest, res *api.QueryNotificationsResponse) error {
|
func (a *UserInternalAPI) QueryNotifications(ctx context.Context, req *api.QueryNotificationsRequest, res *api.QueryNotificationsResponse) error {
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/opentracing/opentracing-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTP paths for the internal HTTP APIs
|
// HTTP paths for the internal HTTP APIs
|
||||||
@ -84,11 +83,10 @@ type httpUserInternalAPI struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) InputAccountData(ctx context.Context, req *api.InputAccountDataRequest, res *api.InputAccountDataResponse) error {
|
func (h *httpUserInternalAPI) InputAccountData(ctx context.Context, req *api.InputAccountDataRequest, res *api.InputAccountDataResponse) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "InputAccountData")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"InputAccountData", h.apiURL+InputAccountDataPath,
|
||||||
|
h.httpClient, ctx, req, res,
|
||||||
apiURL := h.apiURL + InputAccountDataPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformAccountCreation(
|
func (h *httpUserInternalAPI) PerformAccountCreation(
|
||||||
@ -96,11 +94,10 @@ func (h *httpUserInternalAPI) PerformAccountCreation(
|
|||||||
request *api.PerformAccountCreationRequest,
|
request *api.PerformAccountCreationRequest,
|
||||||
response *api.PerformAccountCreationResponse,
|
response *api.PerformAccountCreationResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformAccountCreation")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformAccountCreation", h.apiURL+PerformAccountCreationPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformAccountCreationPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformPasswordUpdate(
|
func (h *httpUserInternalAPI) PerformPasswordUpdate(
|
||||||
@ -108,11 +105,10 @@ func (h *httpUserInternalAPI) PerformPasswordUpdate(
|
|||||||
request *api.PerformPasswordUpdateRequest,
|
request *api.PerformPasswordUpdateRequest,
|
||||||
response *api.PerformPasswordUpdateResponse,
|
response *api.PerformPasswordUpdateResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformPasswordUpdate")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformPasswordUpdate", h.apiURL+PerformPasswordUpdatePath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformPasswordUpdatePath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformDeviceCreation(
|
func (h *httpUserInternalAPI) PerformDeviceCreation(
|
||||||
@ -120,11 +116,10 @@ func (h *httpUserInternalAPI) PerformDeviceCreation(
|
|||||||
request *api.PerformDeviceCreationRequest,
|
request *api.PerformDeviceCreationRequest,
|
||||||
response *api.PerformDeviceCreationResponse,
|
response *api.PerformDeviceCreationResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformDeviceCreation")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformDeviceCreation", h.apiURL+PerformDeviceCreationPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformDeviceCreationPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformDeviceDeletion(
|
func (h *httpUserInternalAPI) PerformDeviceDeletion(
|
||||||
@ -132,47 +127,54 @@ func (h *httpUserInternalAPI) PerformDeviceDeletion(
|
|||||||
request *api.PerformDeviceDeletionRequest,
|
request *api.PerformDeviceDeletionRequest,
|
||||||
response *api.PerformDeviceDeletionResponse,
|
response *api.PerformDeviceDeletionResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformDeviceDeletion")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformDeviceDeletion", h.apiURL+PerformDeviceDeletionPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformDeviceDeletionPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformLastSeenUpdate(
|
func (h *httpUserInternalAPI) PerformLastSeenUpdate(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformLastSeenUpdateRequest,
|
request *api.PerformLastSeenUpdateRequest,
|
||||||
res *api.PerformLastSeenUpdateResponse,
|
response *api.PerformLastSeenUpdateResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformLastSeen")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformLastSeen", h.apiURL+PerformLastSeenUpdatePath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformLastSeenUpdatePath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformDeviceUpdate(ctx context.Context, req *api.PerformDeviceUpdateRequest, res *api.PerformDeviceUpdateResponse) error {
|
func (h *httpUserInternalAPI) PerformDeviceUpdate(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformDeviceUpdate")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.PerformDeviceUpdateRequest,
|
||||||
|
response *api.PerformDeviceUpdateResponse,
|
||||||
apiURL := h.apiURL + PerformDeviceUpdatePath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"PerformDeviceUpdate", h.apiURL+PerformDeviceUpdatePath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformAccountDeactivation(ctx context.Context, req *api.PerformAccountDeactivationRequest, res *api.PerformAccountDeactivationResponse) error {
|
func (h *httpUserInternalAPI) PerformAccountDeactivation(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformAccountDeactivation")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.PerformAccountDeactivationRequest,
|
||||||
|
response *api.PerformAccountDeactivationResponse,
|
||||||
apiURL := h.apiURL + PerformAccountDeactivationPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"PerformAccountDeactivation", h.apiURL+PerformAccountDeactivationPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformOpenIDTokenCreation(ctx context.Context, request *api.PerformOpenIDTokenCreationRequest, response *api.PerformOpenIDTokenCreationResponse) error {
|
func (h *httpUserInternalAPI) PerformOpenIDTokenCreation(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformOpenIDTokenCreation")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.PerformOpenIDTokenCreationRequest,
|
||||||
|
response *api.PerformOpenIDTokenCreationResponse,
|
||||||
apiURL := h.apiURL + PerformOpenIDTokenCreationPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"PerformOpenIDTokenCreation", h.apiURL+PerformOpenIDTokenCreationPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryProfile(
|
func (h *httpUserInternalAPI) QueryProfile(
|
||||||
@ -180,11 +182,10 @@ func (h *httpUserInternalAPI) QueryProfile(
|
|||||||
request *api.QueryProfileRequest,
|
request *api.QueryProfileRequest,
|
||||||
response *api.QueryProfileResponse,
|
response *api.QueryProfileResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryProfile")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryProfile", h.apiURL+QueryProfilePath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + QueryProfilePath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryDeviceInfos(
|
func (h *httpUserInternalAPI) QueryDeviceInfos(
|
||||||
@ -192,11 +193,10 @@ func (h *httpUserInternalAPI) QueryDeviceInfos(
|
|||||||
request *api.QueryDeviceInfosRequest,
|
request *api.QueryDeviceInfosRequest,
|
||||||
response *api.QueryDeviceInfosResponse,
|
response *api.QueryDeviceInfosResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryDeviceInfos")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryDeviceInfos", h.apiURL+QueryDeviceInfosPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + QueryDeviceInfosPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryAccessToken(
|
func (h *httpUserInternalAPI) QueryAccessToken(
|
||||||
@ -204,72 +204,87 @@ func (h *httpUserInternalAPI) QueryAccessToken(
|
|||||||
request *api.QueryAccessTokenRequest,
|
request *api.QueryAccessTokenRequest,
|
||||||
response *api.QueryAccessTokenResponse,
|
response *api.QueryAccessTokenResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryAccessToken")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryAccessToken", h.apiURL+QueryAccessTokenPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + QueryAccessTokenPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryDevices(ctx context.Context, req *api.QueryDevicesRequest, res *api.QueryDevicesResponse) error {
|
func (h *httpUserInternalAPI) QueryDevices(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryDevices")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.QueryDevicesRequest,
|
||||||
|
response *api.QueryDevicesResponse,
|
||||||
apiURL := h.apiURL + QueryDevicesPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"QueryDevices", h.apiURL+QueryDevicesPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryAccountData(ctx context.Context, req *api.QueryAccountDataRequest, res *api.QueryAccountDataResponse) error {
|
func (h *httpUserInternalAPI) QueryAccountData(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryAccountData")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.QueryAccountDataRequest,
|
||||||
|
response *api.QueryAccountDataResponse,
|
||||||
apiURL := h.apiURL + QueryAccountDataPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"QueryAccountData", h.apiURL+QueryAccountDataPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QuerySearchProfiles(ctx context.Context, req *api.QuerySearchProfilesRequest, res *api.QuerySearchProfilesResponse) error {
|
func (h *httpUserInternalAPI) QuerySearchProfiles(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QuerySearchProfiles")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.QuerySearchProfilesRequest,
|
||||||
|
response *api.QuerySearchProfilesResponse,
|
||||||
apiURL := h.apiURL + QuerySearchProfilesPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"QuerySearchProfiles", h.apiURL+QuerySearchProfilesPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryOpenIDToken(ctx context.Context, req *api.QueryOpenIDTokenRequest, res *api.QueryOpenIDTokenResponse) error {
|
func (h *httpUserInternalAPI) QueryOpenIDToken(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryOpenIDToken")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.QueryOpenIDTokenRequest,
|
||||||
|
response *api.QueryOpenIDTokenResponse,
|
||||||
apiURL := h.apiURL + QueryOpenIDTokenPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"QueryOpenIDToken", h.apiURL+QueryOpenIDTokenPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.PerformKeyBackupRequest, res *api.PerformKeyBackupResponse) error {
|
func (h *httpUserInternalAPI) PerformKeyBackup(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformKeyBackup")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.PerformKeyBackupRequest,
|
||||||
|
response *api.PerformKeyBackupResponse,
|
||||||
apiURL := h.apiURL + PerformKeyBackupPath
|
) error {
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
if err != nil {
|
"PerformKeyBackup", h.apiURL+PerformKeyBackupPath,
|
||||||
res.Error = err.Error()
|
h.httpClient, ctx, request, response,
|
||||||
}
|
)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (h *httpUserInternalAPI) QueryKeyBackup(ctx context.Context, req *api.QueryKeyBackupRequest, res *api.QueryKeyBackupResponse) {
|
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryKeyBackup")
|
|
||||||
defer span.Finish()
|
|
||||||
|
|
||||||
apiURL := h.apiURL + QueryKeyBackupPath
|
|
||||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
||||||
if err != nil {
|
|
||||||
res.Error = err.Error()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryNotifications(ctx context.Context, req *api.QueryNotificationsRequest, res *api.QueryNotificationsResponse) error {
|
func (h *httpUserInternalAPI) QueryKeyBackup(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryNotifications")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.QueryKeyBackupRequest,
|
||||||
|
response *api.QueryKeyBackupResponse,
|
||||||
|
) error {
|
||||||
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"QueryKeyBackup", h.apiURL+QueryKeyBackupPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, h.apiURL+QueryNotificationsPath, req, res)
|
func (h *httpUserInternalAPI) QueryNotifications(
|
||||||
|
ctx context.Context,
|
||||||
|
request *api.QueryNotificationsRequest,
|
||||||
|
response *api.QueryNotificationsResponse,
|
||||||
|
) error {
|
||||||
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"QueryNotifications", h.apiURL+QueryNotificationsPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformPusherSet(
|
func (h *httpUserInternalAPI) PerformPusherSet(
|
||||||
@ -277,27 +292,32 @@ func (h *httpUserInternalAPI) PerformPusherSet(
|
|||||||
request *api.PerformPusherSetRequest,
|
request *api.PerformPusherSetRequest,
|
||||||
response *struct{},
|
response *struct{},
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformPusherSet")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformPusherSet", h.apiURL+PerformPusherSetPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformPusherSetPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformPusherDeletion(ctx context.Context, req *api.PerformPusherDeletionRequest, res *struct{}) error {
|
func (h *httpUserInternalAPI) PerformPusherDeletion(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformPusherDeletion")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.PerformPusherDeletionRequest,
|
||||||
|
response *struct{},
|
||||||
apiURL := h.apiURL + PerformPusherDeletionPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"PerformPusherDeletion", h.apiURL+PerformPusherDeletionPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryPushers(ctx context.Context, req *api.QueryPushersRequest, res *api.QueryPushersResponse) error {
|
func (h *httpUserInternalAPI) QueryPushers(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryPushers")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.QueryPushersRequest,
|
||||||
|
response *api.QueryPushersResponse,
|
||||||
apiURL := h.apiURL + QueryPushersPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"QueryPushers", h.apiURL+QueryPushersPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformPushRulesPut(
|
func (h *httpUserInternalAPI) PerformPushRulesPut(
|
||||||
@ -305,89 +325,117 @@ func (h *httpUserInternalAPI) PerformPushRulesPut(
|
|||||||
request *api.PerformPushRulesPutRequest,
|
request *api.PerformPushRulesPutRequest,
|
||||||
response *struct{},
|
response *struct{},
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformPushRulesPut")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformPushRulesPut", h.apiURL+PerformPushRulesPutPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformPushRulesPutPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryPushRules(ctx context.Context, req *api.QueryPushRulesRequest, res *api.QueryPushRulesResponse) error {
|
func (h *httpUserInternalAPI) QueryPushRules(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryPushRules")
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.QueryPushRulesRequest,
|
||||||
|
response *api.QueryPushRulesResponse,
|
||||||
apiURL := h.apiURL + QueryPushRulesPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"QueryPushRules", h.apiURL+QueryPushRulesPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) SetAvatarURL(ctx context.Context, req *api.PerformSetAvatarURLRequest, res *api.PerformSetAvatarURLResponse) error {
|
func (h *httpUserInternalAPI) SetAvatarURL(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, PerformSetAvatarURLPath)
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.PerformSetAvatarURLRequest,
|
||||||
|
response *api.PerformSetAvatarURLResponse,
|
||||||
apiURL := h.apiURL + PerformSetAvatarURLPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"SetAvatarURL", h.apiURL+PerformSetAvatarURLPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryNumericLocalpart(ctx context.Context, res *api.QueryNumericLocalpartResponse) error {
|
func (h *httpUserInternalAPI) QueryNumericLocalpart(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, QueryNumericLocalpartPath)
|
ctx context.Context,
|
||||||
defer span.Finish()
|
response *api.QueryNumericLocalpartResponse,
|
||||||
|
) error {
|
||||||
apiURL := h.apiURL + QueryNumericLocalpartPath
|
return httputil.CallInternalRPCAPI(
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, struct{}{}, res)
|
"QueryNumericLocalpart", h.apiURL+QueryNumericLocalpartPath,
|
||||||
|
h.httpClient, ctx, &struct{}{}, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryAccountAvailability(ctx context.Context, req *api.QueryAccountAvailabilityRequest, res *api.QueryAccountAvailabilityResponse) error {
|
func (h *httpUserInternalAPI) QueryAccountAvailability(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, QueryAccountAvailabilityPath)
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.QueryAccountAvailabilityRequest,
|
||||||
|
response *api.QueryAccountAvailabilityResponse,
|
||||||
apiURL := h.apiURL + QueryAccountAvailabilityPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"QueryAccountAvailability", h.apiURL+QueryAccountAvailabilityPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryAccountByPassword(ctx context.Context, req *api.QueryAccountByPasswordRequest, res *api.QueryAccountByPasswordResponse) error {
|
func (h *httpUserInternalAPI) QueryAccountByPassword(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, QueryAccountByPasswordPath)
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.QueryAccountByPasswordRequest,
|
||||||
|
response *api.QueryAccountByPasswordResponse,
|
||||||
apiURL := h.apiURL + QueryAccountByPasswordPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"QueryAccountByPassword", h.apiURL+QueryAccountByPasswordPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) SetDisplayName(ctx context.Context, req *api.PerformUpdateDisplayNameRequest, res *struct{}) error {
|
func (h *httpUserInternalAPI) SetDisplayName(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, PerformSetDisplayNamePath)
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.PerformUpdateDisplayNameRequest,
|
||||||
|
response *struct{},
|
||||||
apiURL := h.apiURL + PerformSetDisplayNamePath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"SetDisplayName", h.apiURL+PerformSetDisplayNamePath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryLocalpartForThreePID(ctx context.Context, req *api.QueryLocalpartForThreePIDRequest, res *api.QueryLocalpartForThreePIDResponse) error {
|
func (h *httpUserInternalAPI) QueryLocalpartForThreePID(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, QueryLocalpartForThreePIDPath)
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.QueryLocalpartForThreePIDRequest,
|
||||||
|
response *api.QueryLocalpartForThreePIDResponse,
|
||||||
apiURL := h.apiURL + QueryLocalpartForThreePIDPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"QueryLocalpartForThreePID", h.apiURL+QueryLocalpartForThreePIDPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryThreePIDsForLocalpart(ctx context.Context, req *api.QueryThreePIDsForLocalpartRequest, res *api.QueryThreePIDsForLocalpartResponse) error {
|
func (h *httpUserInternalAPI) QueryThreePIDsForLocalpart(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, QueryThreePIDsForLocalpartPath)
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.QueryThreePIDsForLocalpartRequest,
|
||||||
|
response *api.QueryThreePIDsForLocalpartResponse,
|
||||||
apiURL := h.apiURL + QueryThreePIDsForLocalpartPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"QueryThreePIDsForLocalpart", h.apiURL+QueryThreePIDsForLocalpartPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformForgetThreePID(ctx context.Context, req *api.PerformForgetThreePIDRequest, res *struct{}) error {
|
func (h *httpUserInternalAPI) PerformForgetThreePID(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, PerformForgetThreePIDPath)
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.PerformForgetThreePIDRequest,
|
||||||
|
response *struct{},
|
||||||
apiURL := h.apiURL + PerformForgetThreePIDPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"PerformForgetThreePID", h.apiURL+PerformForgetThreePIDPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformSaveThreePIDAssociation(ctx context.Context, req *api.PerformSaveThreePIDAssociationRequest, res *struct{}) error {
|
func (h *httpUserInternalAPI) PerformSaveThreePIDAssociation(
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, PerformSaveThreePIDAssociationPath)
|
ctx context.Context,
|
||||||
defer span.Finish()
|
request *api.PerformSaveThreePIDAssociationRequest,
|
||||||
|
response *struct{},
|
||||||
apiURL := h.apiURL + PerformSaveThreePIDAssociationPath
|
) error {
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
return httputil.CallInternalRPCAPI(
|
||||||
|
"PerformSaveThreePIDAssociation", h.apiURL+PerformSaveThreePIDAssociationPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/opentracing/opentracing-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -33,11 +32,10 @@ func (h *httpUserInternalAPI) PerformLoginTokenCreation(
|
|||||||
request *api.PerformLoginTokenCreationRequest,
|
request *api.PerformLoginTokenCreationRequest,
|
||||||
response *api.PerformLoginTokenCreationResponse,
|
response *api.PerformLoginTokenCreationResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformLoginTokenCreation")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformLoginTokenCreation", h.apiURL+PerformLoginTokenCreationPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformLoginTokenCreationPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) PerformLoginTokenDeletion(
|
func (h *httpUserInternalAPI) PerformLoginTokenDeletion(
|
||||||
@ -45,11 +43,10 @@ func (h *httpUserInternalAPI) PerformLoginTokenDeletion(
|
|||||||
request *api.PerformLoginTokenDeletionRequest,
|
request *api.PerformLoginTokenDeletionRequest,
|
||||||
response *api.PerformLoginTokenDeletionResponse,
|
response *api.PerformLoginTokenDeletionResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformLoginTokenDeletion")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"PerformLoginTokenDeletion", h.apiURL+PerformLoginTokenDeletionPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + PerformLoginTokenDeletionPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpUserInternalAPI) QueryLoginToken(
|
func (h *httpUserInternalAPI) QueryLoginToken(
|
||||||
@ -57,9 +54,8 @@ func (h *httpUserInternalAPI) QueryLoginToken(
|
|||||||
request *api.QueryLoginTokenRequest,
|
request *api.QueryLoginTokenRequest,
|
||||||
response *api.QueryLoginTokenResponse,
|
response *api.QueryLoginTokenResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryLoginToken")
|
return httputil.CallInternalRPCAPI(
|
||||||
defer span.Finish()
|
"QueryLoginToken", h.apiURL+QueryLoginTokenPath,
|
||||||
|
h.httpClient, ctx, request, response,
|
||||||
apiURL := h.apiURL + QueryLoginTokenPath
|
)
|
||||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
package inthttp
|
package inthttp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@ -29,339 +27,134 @@ import (
|
|||||||
func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
||||||
addRoutesLoginToken(internalAPIMux, s)
|
addRoutesLoginToken(internalAPIMux, s)
|
||||||
|
|
||||||
internalAPIMux.Handle(PerformAccountCreationPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("performAccountCreation", func(req *http.Request) util.JSONResponse {
|
PerformAccountCreationPath,
|
||||||
request := api.PerformAccountCreationRequest{}
|
httputil.MakeInternalRPCAPI("UserAPIPerformAccountCreation", s.PerformAccountCreation),
|
||||||
response := api.PerformAccountCreationResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformAccountCreation(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformPasswordUpdatePath,
|
|
||||||
httputil.MakeInternalAPI("performPasswordUpdate", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformPasswordUpdateRequest{}
|
|
||||||
response := api.PerformPasswordUpdateResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformPasswordUpdate(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformDeviceCreationPath,
|
|
||||||
httputil.MakeInternalAPI("performDeviceCreation", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformDeviceCreationRequest{}
|
|
||||||
response := api.PerformDeviceCreationResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformDeviceCreation(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformLastSeenUpdatePath,
|
|
||||||
httputil.MakeInternalAPI("performLastSeenUpdate", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformLastSeenUpdateRequest{}
|
|
||||||
response := api.PerformLastSeenUpdateResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformLastSeenUpdate(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformDeviceUpdatePath,
|
|
||||||
httputil.MakeInternalAPI("performDeviceUpdate", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformDeviceUpdateRequest{}
|
|
||||||
response := api.PerformDeviceUpdateResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformDeviceUpdate(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformDeviceDeletionPath,
|
|
||||||
httputil.MakeInternalAPI("performDeviceDeletion", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformDeviceDeletionRequest{}
|
|
||||||
response := api.PerformDeviceDeletionResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformDeviceDeletion(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformAccountDeactivationPath,
|
|
||||||
httputil.MakeInternalAPI("performAccountDeactivation", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformAccountDeactivationRequest{}
|
|
||||||
response := api.PerformAccountDeactivationResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformAccountDeactivation(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformOpenIDTokenCreationPath,
|
|
||||||
httputil.MakeInternalAPI("performOpenIDTokenCreation", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformOpenIDTokenCreationRequest{}
|
|
||||||
response := api.PerformOpenIDTokenCreationResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformOpenIDTokenCreation(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryProfilePath,
|
|
||||||
httputil.MakeInternalAPI("queryProfile", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryProfileRequest{}
|
|
||||||
response := api.QueryProfileResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryProfile(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryAccessTokenPath,
|
|
||||||
httputil.MakeInternalAPI("queryAccessToken", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryAccessTokenRequest{}
|
|
||||||
response := api.QueryAccessTokenResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryAccessToken(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryDevicesPath,
|
|
||||||
httputil.MakeInternalAPI("queryDevices", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryDevicesRequest{}
|
|
||||||
response := api.QueryDevicesResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryDevices(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryAccountDataPath,
|
|
||||||
httputil.MakeInternalAPI("queryAccountData", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryAccountDataRequest{}
|
|
||||||
response := api.QueryAccountDataResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryAccountData(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryDeviceInfosPath,
|
|
||||||
httputil.MakeInternalAPI("queryDeviceInfos", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryDeviceInfosRequest{}
|
|
||||||
response := api.QueryDeviceInfosResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryDeviceInfos(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QuerySearchProfilesPath,
|
|
||||||
httputil.MakeInternalAPI("querySearchProfiles", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QuerySearchProfilesRequest{}
|
|
||||||
response := api.QuerySearchProfilesResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QuerySearchProfiles(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryOpenIDTokenPath,
|
|
||||||
httputil.MakeInternalAPI("queryOpenIDToken", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryOpenIDTokenRequest{}
|
|
||||||
response := api.QueryOpenIDTokenResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryOpenIDToken(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(InputAccountDataPath,
|
|
||||||
httputil.MakeInternalAPI("inputAccountDataPath", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.InputAccountDataRequest{}
|
|
||||||
response := api.InputAccountDataResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.InputAccountData(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryKeyBackupPath,
|
|
||||||
httputil.MakeInternalAPI("queryKeyBackup", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryKeyBackupRequest{}
|
|
||||||
response := api.QueryKeyBackupResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
s.QueryKeyBackup(req.Context(), &request, &response)
|
|
||||||
if response.Error != "" {
|
|
||||||
return util.ErrorResponse(fmt.Errorf("QueryKeyBackup: %s", response.Error))
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformKeyBackupPath,
|
|
||||||
httputil.MakeInternalAPI("performKeyBackup", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformKeyBackupRequest{}
|
|
||||||
response := api.PerformKeyBackupResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
err := s.PerformKeyBackup(req.Context(), &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return util.JSONResponse{Code: http.StatusBadRequest, JSON: &response}
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryNotificationsPath,
|
|
||||||
httputil.MakeInternalAPI("queryNotifications", func(req *http.Request) util.JSONResponse {
|
|
||||||
var request api.QueryNotificationsRequest
|
|
||||||
var response api.QueryNotificationsResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryNotifications(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(PerformPusherSetPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("performPusherSet", func(req *http.Request) util.JSONResponse {
|
PerformPasswordUpdatePath,
|
||||||
request := api.PerformPusherSetRequest{}
|
httputil.MakeInternalRPCAPI("UserAPIPerformPasswordUpdate", s.PerformPasswordUpdate),
|
||||||
response := struct{}{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformPusherSet(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformPusherDeletionPath,
|
|
||||||
httputil.MakeInternalAPI("performPusherDeletion", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformPusherDeletionRequest{}
|
|
||||||
response := struct{}{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformPusherDeletion(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(QueryPushersPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("queryPushers", func(req *http.Request) util.JSONResponse {
|
PerformDeviceCreationPath,
|
||||||
request := api.QueryPushersRequest{}
|
httputil.MakeInternalRPCAPI("UserAPIPerformDeviceCreation", s.PerformDeviceCreation),
|
||||||
response := api.QueryPushersResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryPushers(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(PerformPushRulesPutPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("performPushRulesPut", func(req *http.Request) util.JSONResponse {
|
PerformLastSeenUpdatePath,
|
||||||
request := api.PerformPushRulesPutRequest{}
|
httputil.MakeInternalRPCAPI("UserAPIPerformLastSeenUpdate", s.PerformLastSeenUpdate),
|
||||||
response := struct{}{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformPushRulesPut(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(QueryPushRulesPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("queryPushRules", func(req *http.Request) util.JSONResponse {
|
PerformDeviceUpdatePath,
|
||||||
request := api.QueryPushRulesRequest{}
|
httputil.MakeInternalRPCAPI("UserAPIPerformDeviceUpdate", s.PerformDeviceUpdate),
|
||||||
response := api.QueryPushRulesResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryPushRules(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformSetAvatarURLPath,
|
|
||||||
httputil.MakeInternalAPI("performSetAvatarURL", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformSetAvatarURLRequest{}
|
PerformDeviceDeletionPath,
|
||||||
response := api.PerformSetAvatarURLResponse{}
|
httputil.MakeInternalRPCAPI("UserAPIPerformDeviceDeletion", s.PerformDeviceDeletion),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.SetAvatarURL(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformAccountDeactivationPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIPerformAccountDeactivation", s.PerformAccountDeactivation),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformOpenIDTokenCreationPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIPerformOpenIDTokenCreation", s.PerformOpenIDTokenCreation),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryProfilePath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIQueryProfile", s.QueryProfile),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryAccessTokenPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIQueryAccessToken", s.QueryAccessToken),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryDevicesPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIQueryDevices", s.QueryDevices),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryAccountDataPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIQueryAccountData", s.QueryAccountData),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryDeviceInfosPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIQueryDeviceInfos", s.QueryDeviceInfos),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QuerySearchProfilesPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIQuerySearchProfiles", s.QuerySearchProfiles),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryOpenIDTokenPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIQueryOpenIDToken", s.QueryOpenIDToken),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
InputAccountDataPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIInputAccountData", s.InputAccountData),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryKeyBackupPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIQueryKeyBackup", s.QueryKeyBackup),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformKeyBackupPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIPerformKeyBackup", s.PerformKeyBackup),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryNotificationsPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIQueryNotifications", s.QueryNotifications),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformPusherSetPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIPerformPusherSet", s.PerformPusherSet),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformPusherDeletionPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIPerformPusherDeletion", s.PerformPusherDeletion),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryPushersPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIQueryPushers", s.QueryPushers),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformPushRulesPutPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIPerformPushRulesPut", s.PerformPushRulesPut),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryPushRulesPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIQueryPushRules", s.QueryPushRules),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformSetAvatarURLPath,
|
||||||
|
httputil.MakeInternalRPCAPI("UserAPIPerformSetAvatarURL", s.SetAvatarURL),
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: Look at the shape of this
|
||||||
internalAPIMux.Handle(QueryNumericLocalpartPath,
|
internalAPIMux.Handle(QueryNumericLocalpartPath,
|
||||||
httputil.MakeInternalAPI("queryNumericLocalpart", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalAPI("UserAPIQueryNumericLocalpart", func(req *http.Request) util.JSONResponse {
|
||||||
response := api.QueryNumericLocalpartResponse{}
|
response := api.QueryNumericLocalpartResponse{}
|
||||||
if err := s.QueryNumericLocalpart(req.Context(), &response); err != nil {
|
if err := s.QueryNumericLocalpart(req.Context(), &response); err != nil {
|
||||||
return util.ErrorResponse(err)
|
return util.ErrorResponse(err)
|
||||||
@ -369,92 +162,39 @@ func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
|||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryAccountAvailabilityPath,
|
|
||||||
httputil.MakeInternalAPI("queryAccountAvailability", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryAccountAvailabilityRequest{}
|
QueryAccountAvailabilityPath,
|
||||||
response := api.QueryAccountAvailabilityResponse{}
|
httputil.MakeInternalRPCAPI("UserAPIQueryAccountAvailability", s.QueryAccountAvailability),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryAccountAvailability(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryAccountByPasswordPath,
|
|
||||||
httputil.MakeInternalAPI("queryAccountByPassword", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryAccountByPasswordRequest{}
|
QueryAccountByPasswordPath,
|
||||||
response := api.QueryAccountByPasswordResponse{}
|
httputil.MakeInternalRPCAPI("UserAPIQueryAccountByPassword", s.QueryAccountByPassword),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryAccountByPassword(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformSetDisplayNamePath,
|
|
||||||
httputil.MakeInternalAPI("performSetDisplayName", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformUpdateDisplayNameRequest{}
|
PerformSetDisplayNamePath,
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
httputil.MakeInternalRPCAPI("UserAPISetDisplayName", s.SetDisplayName),
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.SetDisplayName(req.Context(), &request, &struct{}{}); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &struct{}{}}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryLocalpartForThreePIDPath,
|
|
||||||
httputil.MakeInternalAPI("queryLocalpartForThreePID", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryLocalpartForThreePIDRequest{}
|
QueryLocalpartForThreePIDPath,
|
||||||
response := api.QueryLocalpartForThreePIDResponse{}
|
httputil.MakeInternalRPCAPI("UserAPIQueryLocalpartForThreePID", s.QueryLocalpartForThreePID),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryLocalpartForThreePID(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryThreePIDsForLocalpartPath,
|
|
||||||
httputil.MakeInternalAPI("queryThreePIDsForLocalpart", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryThreePIDsForLocalpartRequest{}
|
QueryThreePIDsForLocalpartPath,
|
||||||
response := api.QueryThreePIDsForLocalpartResponse{}
|
httputil.MakeInternalRPCAPI("UserAPIQueryThreePIDsForLocalpart", s.QueryThreePIDsForLocalpart),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryThreePIDsForLocalpart(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformForgetThreePIDPath,
|
|
||||||
httputil.MakeInternalAPI("performForgetThreePID", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformForgetThreePIDRequest{}
|
PerformForgetThreePIDPath,
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
httputil.MakeInternalRPCAPI("UserAPIPerformForgetThreePID", s.PerformForgetThreePID),
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformForgetThreePID(req.Context(), &request, &struct{}{}); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &struct{}{}}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformSaveThreePIDAssociationPath,
|
|
||||||
httputil.MakeInternalAPI("performSaveThreePIDAssociation", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformSaveThreePIDAssociationRequest{}
|
PerformSaveThreePIDAssociationPath,
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
httputil.MakeInternalRPCAPI("UserAPIPerformSaveThreePIDAssociation", s.PerformSaveThreePIDAssociation),
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformSaveThreePIDAssociation(req.Context(), &request, &struct{}{}); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &struct{}{}}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -15,54 +15,25 @@
|
|||||||
package inthttp
|
package inthttp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// addRoutesLoginToken adds routes for all login token API calls.
|
// addRoutesLoginToken adds routes for all login token API calls.
|
||||||
func addRoutesLoginToken(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
func addRoutesLoginToken(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
||||||
internalAPIMux.Handle(PerformLoginTokenCreationPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("performLoginTokenCreation", func(req *http.Request) util.JSONResponse {
|
PerformLoginTokenCreationPath,
|
||||||
request := api.PerformLoginTokenCreationRequest{}
|
httputil.MakeInternalRPCAPI("UserAPIPerformLoginTokenCreation", s.PerformLoginTokenCreation),
|
||||||
response := api.PerformLoginTokenCreationResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformLoginTokenCreation(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformLoginTokenDeletionPath,
|
|
||||||
httputil.MakeInternalAPI("performLoginTokenDeletion", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformLoginTokenDeletionRequest{}
|
PerformLoginTokenDeletionPath,
|
||||||
response := api.PerformLoginTokenDeletionResponse{}
|
httputil.MakeInternalRPCAPI("UserAPIPerformLoginTokenDeletion", s.PerformLoginTokenDeletion),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformLoginTokenDeletion(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryLoginTokenPath,
|
|
||||||
httputil.MakeInternalAPI("queryLoginToken", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryLoginTokenRequest{}
|
QueryLoginTokenPath,
|
||||||
response := api.QueryLoginTokenResponse{}
|
httputil.MakeInternalRPCAPI("UserAPIQueryLoginToken", s.QueryLoginToken),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryLoginToken(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -117,16 +117,20 @@ func TestQueryProfile(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
runCases := func(testAPI api.UserInternalAPI) {
|
runCases := func(testAPI api.UserInternalAPI, http bool) {
|
||||||
|
mode := "monolith"
|
||||||
|
if http {
|
||||||
|
mode = "HTTP"
|
||||||
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
var gotRes api.QueryProfileResponse
|
var gotRes api.QueryProfileResponse
|
||||||
gotErr := testAPI.QueryProfile(context.TODO(), &tc.req, &gotRes)
|
gotErr := testAPI.QueryProfile(context.TODO(), &tc.req, &gotRes)
|
||||||
if tc.wantErr == nil && gotErr != nil || tc.wantErr != nil && gotErr == nil {
|
if tc.wantErr == nil && gotErr != nil || tc.wantErr != nil && gotErr == nil {
|
||||||
t.Errorf("QueryProfile error, got %s want %s", gotErr, tc.wantErr)
|
t.Errorf("QueryProfile %s error, got %s want %s", mode, gotErr, tc.wantErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(tc.wantRes, gotRes) {
|
if !reflect.DeepEqual(tc.wantRes, gotRes) {
|
||||||
t.Errorf("QueryProfile response got %+v want %+v", gotRes, tc.wantRes)
|
t.Errorf("QueryProfile %s response got %+v want %+v", mode, gotRes, tc.wantRes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,10 +144,10 @@ func TestQueryProfile(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create HTTP client")
|
t.Fatalf("failed to create HTTP client")
|
||||||
}
|
}
|
||||||
runCases(httpAPI)
|
runCases(httpAPI, true)
|
||||||
})
|
})
|
||||||
t.Run("Monolith", func(t *testing.T) {
|
t.Run("Monolith", func(t *testing.T) {
|
||||||
runCases(userAPI)
|
runCases(userAPI, false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user