aboutsummaryrefslogtreecommitdiff
path: root/roomserver
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-08-11 15:29:33 +0100
committerGitHub <noreply@github.com>2022-08-11 15:29:33 +0100
commitc45d0936b59b0eb65f12fe22a3da3690ae0b5494 (patch)
treefffe20dcf4c1d4efd8e6d8b6af1d21ef25a9539c /roomserver
parent240ae257deb74b7be8a17500b77d5e1bca56e8f5 (diff)
Generic-based internal HTTP API (#2626)
* Generic-based internal HTTP API (tested out on a few endpoints in the federation API) * Add `PerformInvite` * More tweaks * Fix metric name * Fix LookupStateIDs * Lots of changes to clients * Some serverside stuff * Some error handling * Use paths as metric names * Revert "Use paths as metric names" This reverts commit a9323a6a343f5ce6461a2e5bd570fe06465f1b15. * Namespace metric names * Remove duplicate entry * Remove another duplicate entry * Tweak error handling * Some more tweaks * Update error behaviour * Some more error tweaking * Fix API path for `PerformDeleteKeys` * Fix another path * Tweak federation client proxying * Fix another path * Don't return typed nils * Some more tweaks, not that it makes any difference * Tweak federation client proxying * Maybe fix the key backup test
Diffstat (limited to 'roomserver')
-rw-r--r--roomserver/api/api.go18
-rw-r--r--roomserver/api/api_trace.go63
-rw-r--r--roomserver/api/wrapper.go4
-rw-r--r--roomserver/internal/input/input.go10
-rw-r--r--roomserver/internal/perform/perform_admin.go37
-rw-r--r--roomserver/internal/perform/perform_invite.go4
-rw-r--r--roomserver/internal/perform/perform_join.go12
-rw-r--r--roomserver/internal/perform/perform_leave.go4
-rw-r--r--roomserver/internal/perform/perform_peek.go3
-rw-r--r--roomserver/internal/perform/perform_publish.go3
-rw-r--r--roomserver/internal/perform/perform_unpeek.go3
-rw-r--r--roomserver/internal/perform/perform_upgrade.go17
-rw-r--r--roomserver/inthttp/client.go431
-rw-r--r--roomserver/inthttp/server.go561
14 files changed, 416 insertions, 754 deletions
diff --git a/roomserver/api/api.go b/roomserver/api/api.go
index 38baa617..ee0212ec 100644
--- a/roomserver/api/api.go
+++ b/roomserver/api/api.go
@@ -40,7 +40,7 @@ type InputRoomEventsAPI interface {
ctx context.Context,
req *InputRoomEventsRequest,
res *InputRoomEventsResponse,
- )
+ ) error
}
// 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
// PerformRoomUpgrade upgrades a room to a newer version
- PerformRoomUpgrade(ctx context.Context, req *PerformRoomUpgradeRequest, resp *PerformRoomUpgradeResponse)
- PerformAdminEvacuateRoom(ctx context.Context, req *PerformAdminEvacuateRoomRequest, res *PerformAdminEvacuateRoomResponse)
- PerformAdminEvacuateUser(ctx context.Context, req *PerformAdminEvacuateUserRequest, res *PerformAdminEvacuateUserResponse)
- PerformPeek(ctx context.Context, req *PerformPeekRequest, res *PerformPeekResponse)
- PerformUnpeek(ctx context.Context, req *PerformUnpeekRequest, res *PerformUnpeekResponse)
+ PerformRoomUpgrade(ctx context.Context, req *PerformRoomUpgradeRequest, resp *PerformRoomUpgradeResponse) error
+ PerformAdminEvacuateRoom(ctx context.Context, req *PerformAdminEvacuateRoomRequest, res *PerformAdminEvacuateRoomResponse) error
+ PerformAdminEvacuateUser(ctx context.Context, req *PerformAdminEvacuateUserRequest, res *PerformAdminEvacuateUserResponse) error
+ PerformPeek(ctx context.Context, req *PerformPeekRequest, res *PerformPeekResponse) error
+ PerformUnpeek(ctx context.Context, req *PerformUnpeekRequest, res *PerformUnpeekResponse) 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
- 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(ctx context.Context, req *PerformForgetRequest, resp *PerformForgetResponse) error
SetRoomAlias(ctx context.Context, req *SetRoomAliasRequest, res *SetRoomAliasResponse) error
@@ -158,7 +158,7 @@ type UserRoomserverAPI interface {
QueryLatestEventsAndStateAPI
QueryCurrentState(ctx context.Context, req *QueryCurrentStateRequest, res *QueryCurrentStateResponse) 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 {
diff --git a/roomserver/api/api_trace.go b/roomserver/api/api_trace.go
index 211f320f..18a61733 100644
--- a/roomserver/api/api_trace.go
+++ b/roomserver/api/api_trace.go
@@ -35,9 +35,10 @@ func (t *RoomserverInternalAPITrace) InputRoomEvents(
ctx context.Context,
req *InputRoomEventsRequest,
res *InputRoomEventsResponse,
-) {
- t.Impl.InputRoomEvents(ctx, req, res)
- util.GetLogger(ctx).Infof("InputRoomEvents req=%+v res=%+v", js(req), js(res))
+) error {
+ err := t.Impl.InputRoomEvents(ctx, req, res)
+ util.GetLogger(ctx).WithError(err).Infof("InputRoomEvents req=%+v res=%+v", js(req), js(res))
+ return err
}
func (t *RoomserverInternalAPITrace) PerformInvite(
@@ -45,44 +46,49 @@ func (t *RoomserverInternalAPITrace) PerformInvite(
req *PerformInviteRequest,
res *PerformInviteResponse,
) error {
- util.GetLogger(ctx).Infof("PerformInvite req=%+v res=%+v", js(req), js(res))
- return t.Impl.PerformInvite(ctx, req, res)
+ err := 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(
ctx context.Context,
req *PerformPeekRequest,
res *PerformPeekResponse,
-) {
- t.Impl.PerformPeek(ctx, req, res)
- util.GetLogger(ctx).Infof("PerformPeek req=%+v res=%+v", js(req), js(res))
+) error {
+ err := t.Impl.PerformPeek(ctx, req, res)
+ util.GetLogger(ctx).WithError(err).Infof("PerformPeek req=%+v res=%+v", js(req), js(res))
+ return err
}
func (t *RoomserverInternalAPITrace) PerformUnpeek(
ctx context.Context,
req *PerformUnpeekRequest,
res *PerformUnpeekResponse,
-) {
- t.Impl.PerformUnpeek(ctx, req, res)
- util.GetLogger(ctx).Infof("PerformUnpeek req=%+v res=%+v", js(req), js(res))
+) error {
+ err := t.Impl.PerformUnpeek(ctx, req, res)
+ util.GetLogger(ctx).WithError(err).Infof("PerformUnpeek req=%+v res=%+v", js(req), js(res))
+ return err
}
func (t *RoomserverInternalAPITrace) PerformRoomUpgrade(
ctx context.Context,
req *PerformRoomUpgradeRequest,
res *PerformRoomUpgradeResponse,
-) {
- t.Impl.PerformRoomUpgrade(ctx, req, res)
- util.GetLogger(ctx).Infof("PerformRoomUpgrade req=%+v res=%+v", js(req), js(res))
+) error {
+ err := t.Impl.PerformRoomUpgrade(ctx, req, res)
+ util.GetLogger(ctx).WithError(err).Infof("PerformRoomUpgrade req=%+v res=%+v", js(req), js(res))
+ return err
}
func (t *RoomserverInternalAPITrace) PerformJoin(
ctx context.Context,
req *PerformJoinRequest,
res *PerformJoinResponse,
-) {
- t.Impl.PerformJoin(ctx, req, res)
- util.GetLogger(ctx).Infof("PerformJoin req=%+v res=%+v", js(req), js(res))
+) error {
+ err := t.Impl.PerformJoin(ctx, req, res)
+ util.GetLogger(ctx).WithError(err).Infof("PerformJoin req=%+v res=%+v", js(req), js(res))
+ return err
}
func (t *RoomserverInternalAPITrace) PerformLeave(
@@ -99,27 +105,30 @@ func (t *RoomserverInternalAPITrace) PerformPublish(
ctx context.Context,
req *PerformPublishRequest,
res *PerformPublishResponse,
-) {
- t.Impl.PerformPublish(ctx, req, res)
- util.GetLogger(ctx).Infof("PerformPublish req=%+v res=%+v", js(req), js(res))
+) error {
+ err := t.Impl.PerformPublish(ctx, req, res)
+ util.GetLogger(ctx).WithError(err).Infof("PerformPublish req=%+v res=%+v", js(req), js(res))
+ return err
}
func (t *RoomserverInternalAPITrace) PerformAdminEvacuateRoom(
ctx context.Context,
req *PerformAdminEvacuateRoomRequest,
res *PerformAdminEvacuateRoomResponse,
-) {
- t.Impl.PerformAdminEvacuateRoom(ctx, req, res)
- util.GetLogger(ctx).Infof("PerformAdminEvacuateRoom req=%+v res=%+v", js(req), js(res))
+) error {
+ err := t.Impl.PerformAdminEvacuateRoom(ctx, req, res)
+ util.GetLogger(ctx).WithError(err).Infof("PerformAdminEvacuateRoom req=%+v res=%+v", js(req), js(res))
+ return err
}
func (t *RoomserverInternalAPITrace) PerformAdminEvacuateUser(
ctx context.Context,
req *PerformAdminEvacuateUserRequest,
res *PerformAdminEvacuateUserResponse,
-) {
- t.Impl.PerformAdminEvacuateUser(ctx, req, res)
- util.GetLogger(ctx).Infof("PerformAdminEvacuateUser req=%+v res=%+v", js(req), js(res))
+) error {
+ err := t.Impl.PerformAdminEvacuateUser(ctx, req, res)
+ util.GetLogger(ctx).WithError(err).Infof("PerformAdminEvacuateUser req=%+v res=%+v", js(req), js(res))
+ return err
}
func (t *RoomserverInternalAPITrace) PerformInboundPeek(
@@ -128,7 +137,7 @@ func (t *RoomserverInternalAPITrace) PerformInboundPeek(
res *PerformInboundPeekResponse,
) error {
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
}
diff --git a/roomserver/api/wrapper.go b/roomserver/api/wrapper.go
index 344e9b07..bc2f2817 100644
--- a/roomserver/api/wrapper.go
+++ b/roomserver/api/wrapper.go
@@ -90,7 +90,9 @@ func SendInputRoomEvents(
Asynchronous: async,
}
var response InputRoomEventsResponse
- rsAPI.InputRoomEvents(ctx, &request, &response)
+ if err := rsAPI.InputRoomEvents(ctx, &request, &response); err != nil {
+ return err
+ }
return response.Err()
}
diff --git a/roomserver/internal/input/input.go b/roomserver/internal/input/input.go
index 339c9796..8d24f3c5 100644
--- a/roomserver/internal/input/input.go
+++ b/roomserver/internal/input/input.go
@@ -337,18 +337,18 @@ func (r *Inputer) InputRoomEvents(
ctx context.Context,
request *api.InputRoomEventsRequest,
response *api.InputRoomEventsResponse,
-) {
+) error {
// Queue up the event into the roomserver.
replySub, err := r.queueInputRoomEvents(ctx, request)
if err != nil {
response.ErrMsg = err.Error()
- return
+ return nil
}
// If we aren't waiting for synchronous responses then we can
// give up here, there is nothing further to do.
if replySub == nil {
- return
+ return nil
}
// Otherwise, we'll want to sit and wait for the responses
@@ -360,12 +360,14 @@ func (r *Inputer) InputRoomEvents(
msg, err := replySub.NextMsgWithContext(ctx)
if err != nil {
response.ErrMsg = err.Error()
- return
+ return nil
}
if len(msg.Data) > 0 {
response.ErrMsg = string(msg.Data)
}
}
+
+ return nil
}
var roomserverInputBackpressure = prometheus.NewGaugeVec(
diff --git a/roomserver/internal/perform/perform_admin.go b/roomserver/internal/perform/perform_admin.go
index 6c7c6c98..cb6b22d3 100644
--- a/roomserver/internal/perform/perform_admin.go
+++ b/roomserver/internal/perform/perform_admin.go
@@ -43,21 +43,21 @@ func (r *Admin) PerformAdminEvacuateRoom(
ctx context.Context,
req *api.PerformAdminEvacuateRoomRequest,
res *api.PerformAdminEvacuateRoomResponse,
-) {
+) error {
roomInfo, err := r.DB.RoomInfo(ctx, req.RoomID)
if err != nil {
res.Error = &api.PerformError{
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("r.DB.RoomInfo: %s", err),
}
- return
+ return nil
}
if roomInfo == nil || roomInfo.IsStub() {
res.Error = &api.PerformError{
Code: api.PerformErrorNoRoom,
Msg: fmt.Sprintf("Room %s not found", req.RoomID),
}
- return
+ return nil
}
memberNIDs, err := r.DB.GetMembershipEventNIDsForRoom(ctx, roomInfo.RoomNID, true, true)
@@ -66,7 +66,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("r.DB.GetMembershipEventNIDsForRoom: %s", err),
}
- return
+ return nil
}
memberEvents, err := r.DB.Events(ctx, memberNIDs)
@@ -75,7 +75,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("r.DB.Events: %s", err),
}
- return
+ return nil
}
inputEvents := make([]api.InputRoomEvent, 0, len(memberEvents))
@@ -89,7 +89,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("r.Queryer.QueryLatestEventsAndState: %s", err),
}
- return
+ return nil
}
prevEvents := latestRes.LatestEvents
@@ -104,7 +104,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("json.Unmarshal: %s", err),
}
- return
+ return nil
}
memberContent.Membership = gomatrixserverlib.Leave
@@ -122,7 +122,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("json.Marshal: %s", err),
}
- return
+ return nil
}
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(fledglingEvent)
@@ -131,7 +131,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("gomatrixserverlib.StateNeededForEventBuilder: %s", err),
}
- return
+ return nil
}
event, err := eventutil.BuildEvent(ctx, fledglingEvent, r.Cfg.Matrix, time.Now(), &eventsNeeded, latestRes)
@@ -140,7 +140,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("eventutil.BuildEvent: %s", err),
}
- return
+ return nil
}
inputEvents = append(inputEvents, api.InputRoomEvent{
@@ -160,28 +160,28 @@ func (r *Admin) PerformAdminEvacuateRoom(
Asynchronous: true,
}
inputRes := &api.InputRoomEventsResponse{}
- r.Inputer.InputRoomEvents(ctx, inputReq, inputRes)
+ return r.Inputer.InputRoomEvents(ctx, inputReq, inputRes)
}
func (r *Admin) PerformAdminEvacuateUser(
ctx context.Context,
req *api.PerformAdminEvacuateUserRequest,
res *api.PerformAdminEvacuateUserResponse,
-) {
+) error {
_, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
if err != nil {
res.Error = &api.PerformError{
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("Malformed user ID: %s", err),
}
- return
+ return nil
}
if domain != r.Cfg.Matrix.ServerName {
res.Error = &api.PerformError{
Code: api.PerformErrorBadRequest,
Msg: "Can only evacuate local users using this endpoint",
}
- return
+ return nil
}
roomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, gomatrixserverlib.Join)
@@ -190,7 +190,7 @@ func (r *Admin) PerformAdminEvacuateUser(
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("r.DB.GetRoomsByMembership: %s", err),
}
- return
+ return nil
}
inviteRoomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, gomatrixserverlib.Invite)
@@ -199,7 +199,7 @@ func (r *Admin) PerformAdminEvacuateUser(
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("r.DB.GetRoomsByMembership: %s", err),
}
- return
+ return nil
}
for _, roomID := range append(roomIDs, inviteRoomIDs...) {
@@ -214,7 +214,7 @@ func (r *Admin) PerformAdminEvacuateUser(
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("r.Leaver.PerformLeave: %s", err),
}
- return
+ return nil
}
if len(outputEvents) == 0 {
continue
@@ -224,9 +224,10 @@ func (r *Admin) PerformAdminEvacuateUser(
Code: api.PerformErrorBadRequest,
Msg: fmt.Sprintf("r.Inputer.WriteOutputEvents: %s", err),
}
- return
+ return nil
}
res.Affected = append(res.Affected, roomID)
}
+ return nil
}
diff --git a/roomserver/internal/perform/perform_invite.go b/roomserver/internal/perform/perform_invite.go
index e1ff4eab..483e78c3 100644
--- a/roomserver/internal/perform/perform_invite.go
+++ b/roomserver/internal/perform/perform_invite.go
@@ -241,7 +241,9 @@ func (r *Inviter) PerformInvite(
},
}
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 {
res.Error = &api.PerformError{
Msg: fmt.Sprintf("r.InputRoomEvents: %s", err.Error()),
diff --git a/roomserver/internal/perform/perform_join.go b/roomserver/internal/perform/perform_join.go
index 1445b408..43be54be 100644
--- a/roomserver/internal/perform/perform_join.go
+++ b/roomserver/internal/perform/perform_join.go
@@ -52,7 +52,7 @@ func (r *Joiner) PerformJoin(
ctx context.Context,
req *rsAPI.PerformJoinRequest,
res *rsAPI.PerformJoinResponse,
-) {
+) error {
logger := logrus.WithContext(ctx).WithFields(logrus.Fields{
"room_id": req.RoomIDOrAlias,
"user_id": req.UserID,
@@ -71,11 +71,12 @@ func (r *Joiner) PerformJoin(
Msg: err.Error(),
}
}
- return
+ return nil
}
logger.Info("User joined room successfully")
res.RoomID = roomID
res.JoinedVia = joinedVia
+ return nil
}
func (r *Joiner) performJoin(
@@ -291,7 +292,12 @@ func (r *Joiner) performJoinRoomByID(
},
}
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 {
return "", "", &rsAPI.PerformError{
Code: rsAPI.PerformErrorNotAllowed,
diff --git a/roomserver/internal/perform/perform_leave.go b/roomserver/internal/perform/perform_leave.go
index 56e7240d..036404cd 100644
--- a/roomserver/internal/perform/perform_leave.go
+++ b/roomserver/internal/perform/perform_leave.go
@@ -186,7 +186,9 @@ func (r *Leaver) performLeaveRoomByID(
},
}
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 {
return nil, fmt.Errorf("r.InputRoomEvents: %w", err)
}
diff --git a/roomserver/internal/perform/perform_peek.go b/roomserver/internal/perform/perform_peek.go
index 5560916b..74d87a5b 100644
--- a/roomserver/internal/perform/perform_peek.go
+++ b/roomserver/internal/perform/perform_peek.go
@@ -44,7 +44,7 @@ func (r *Peeker) PerformPeek(
ctx context.Context,
req *api.PerformPeekRequest,
res *api.PerformPeekResponse,
-) {
+) error {
roomID, err := r.performPeek(ctx, req)
if err != nil {
perr, ok := err.(*api.PerformError)
@@ -57,6 +57,7 @@ func (r *Peeker) PerformPeek(
}
}
res.RoomID = roomID
+ return nil
}
func (r *Peeker) performPeek(
diff --git a/roomserver/internal/perform/perform_publish.go b/roomserver/internal/perform/perform_publish.go
index 6ff42ac1..1631fc65 100644
--- a/roomserver/internal/perform/perform_publish.go
+++ b/roomserver/internal/perform/perform_publish.go
@@ -29,11 +29,12 @@ func (r *Publisher) PerformPublish(
ctx context.Context,
req *api.PerformPublishRequest,
res *api.PerformPublishResponse,
-) {
+) error {
err := r.DB.PublishRoom(ctx, req.RoomID, req.Visibility == "public")
if err != nil {
res.Error = &api.PerformError{
Msg: err.Error(),
}
}
+ return nil
}
diff --git a/roomserver/internal/perform/perform_unpeek.go b/roomserver/internal/perform/perform_unpeek.go
index 1fe8d5a0..49e9067c 100644
--- a/roomserver/internal/perform/perform_unpeek.go
+++ b/roomserver/internal/perform/perform_unpeek.go
@@ -41,7 +41,7 @@ func (r *Unpeeker) PerformUnpeek(
ctx context.Context,
req *api.PerformUnpeekRequest,
res *api.PerformUnpeekResponse,
-) {
+) error {
if err := r.performUnpeek(ctx, req); err != nil {
perr, ok := err.(*api.PerformError)
if ok {
@@ -52,6 +52,7 @@ func (r *Unpeeker) PerformUnpeek(
}
}
}
+ return nil
}
func (r *Unpeeker) performUnpeek(
diff --git a/roomserver/internal/perform/perform_upgrade.go b/roomserver/internal/perform/perform_upgrade.go
index 393d7dd1..d6dc9708 100644
--- a/roomserver/internal/perform/perform_upgrade.go
+++ b/roomserver/internal/perform/perform_upgrade.go
@@ -45,12 +45,13 @@ func (r *Upgrader) PerformRoomUpgrade(
ctx context.Context,
req *api.PerformRoomUpgradeRequest,
res *api.PerformRoomUpgradeResponse,
-) {
+) error {
res.NewRoomID, res.Error = r.performRoomUpgrade(ctx, req)
if res.Error != nil {
res.NewRoomID = ""
logrus.WithContext(ctx).WithError(res.Error).Error("Room upgrade failed")
}
+ return nil
}
func (r *Upgrader) performRoomUpgrade(
@@ -286,22 +287,24 @@ func publishNewRoomAndUnpublishOldRoom(
) {
// expose this room in the published room list
var pubNewRoomRes api.PerformPublishResponse
- URSAPI.PerformPublish(ctx, &api.PerformPublishRequest{
+ if err := URSAPI.PerformPublish(ctx, &api.PerformPublishRequest{
RoomID: newRoomID,
Visibility: "public",
- }, &pubNewRoomRes)
- if pubNewRoomRes.Error != nil {
+ }, &pubNewRoomRes); err != 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
util.GetLogger(ctx).WithError(pubNewRoomRes.Error).Error("failed to visibility:public")
}
var unpubOldRoomRes api.PerformPublishResponse
// remove the old room from the published room list
- URSAPI.PerformPublish(ctx, &api.PerformPublishRequest{
+ if err := URSAPI.PerformPublish(ctx, &api.PerformPublishRequest{
RoomID: oldRoomID,
Visibility: "private",
- }, &unpubOldRoomRes)
- if unpubOldRoomRes.Error != nil {
+ }, &unpubOldRoomRes); err != 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
util.GetLogger(ctx).WithError(unpubOldRoomRes.Error).Error("failed to visibility:private")
}
diff --git a/roomserver/inthttp/client.go b/roomserver/inthttp/client.go
index 2fa8afc4..d16f67c6 100644
--- a/roomserver/inthttp/client.go
+++ b/roomserver/inthttp/client.go
@@ -3,7 +3,6 @@ package inthttp
import (
"context"
"errors"
- "fmt"
"net/http"
asAPI "github.com/matrix-org/dendrite/appservice/api"
@@ -14,7 +13,6 @@ import (
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
- "github.com/opentracing/opentracing-go"
)
const (
@@ -106,11 +104,10 @@ func (h *httpRoomserverInternalAPI) SetRoomAlias(
request *api.SetRoomAliasRequest,
response *api.SetRoomAliasResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "SetRoomAlias")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverSetRoomAliasPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "SetRoomAlias", h.roomserverURL+RoomserverSetRoomAliasPath,
+ h.httpClient, ctx, request, response,
+ )
}
// GetRoomIDForAlias implements RoomserverAliasAPI
@@ -119,11 +116,10 @@ func (h *httpRoomserverInternalAPI) GetRoomIDForAlias(
request *api.GetRoomIDForAliasRequest,
response *api.GetRoomIDForAliasResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "GetRoomIDForAlias")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverGetRoomIDForAliasPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "GetRoomIDForAlias", h.roomserverURL+RoomserverGetRoomIDForAliasPath,
+ h.httpClient, ctx, request, response,
+ )
}
// GetAliasesForRoomID implements RoomserverAliasAPI
@@ -132,11 +128,10 @@ func (h *httpRoomserverInternalAPI) GetAliasesForRoomID(
request *api.GetAliasesForRoomIDRequest,
response *api.GetAliasesForRoomIDResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "GetAliasesForRoomID")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverGetAliasesForRoomIDPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "GetAliasesForRoomID", h.roomserverURL+RoomserverGetAliasesForRoomIDPath,
+ h.httpClient, ctx, request, response,
+ )
}
// RemoveRoomAlias implements RoomserverAliasAPI
@@ -145,11 +140,10 @@ func (h *httpRoomserverInternalAPI) RemoveRoomAlias(
request *api.RemoveRoomAliasRequest,
response *api.RemoveRoomAliasResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "RemoveRoomAlias")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverRemoveRoomAliasPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "RemoveRoomAlias", h.roomserverURL+RoomserverRemoveRoomAliasPath,
+ h.httpClient, ctx, request, response,
+ )
}
// InputRoomEvents implements RoomserverInputAPI
@@ -157,15 +151,14 @@ func (h *httpRoomserverInternalAPI) InputRoomEvents(
ctx context.Context,
request *api.InputRoomEventsRequest,
response *api.InputRoomEventsResponse,
-) {
- span, ctx := opentracing.StartSpanFromContext(ctx, "InputRoomEvents")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverInputRoomEventsPath
- err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
- if err != nil {
+) error {
+ if err := httputil.CallInternalRPCAPI(
+ "InputRoomEvents", h.roomserverURL+RoomserverInputRoomEventsPath,
+ h.httpClient, ctx, request, response,
+ ); err != nil {
response.ErrMsg = err.Error()
}
+ return nil
}
func (h *httpRoomserverInternalAPI) PerformInvite(
@@ -173,45 +166,32 @@ func (h *httpRoomserverInternalAPI) PerformInvite(
request *api.PerformInviteRequest,
response *api.PerformInviteResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "PerformInvite")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverPerformInvitePath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "PerformInvite", h.roomserverURL+RoomserverPerformInvitePath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) PerformJoin(
ctx context.Context,
request *api.PerformJoinRequest,
response *api.PerformJoinResponse,
-) {
- span, ctx := opentracing.StartSpanFromContext(ctx, "PerformJoin")
- defer span.Finish()
-
- 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),
- }
- }
+) error {
+ return httputil.CallInternalRPCAPI(
+ "PerformJoin", h.roomserverURL+RoomserverPerformJoinPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) PerformPeek(
ctx context.Context,
request *api.PerformPeekRequest,
response *api.PerformPeekResponse,
-) {
- span, ctx := opentracing.StartSpanFromContext(ctx, "PerformPeek")
- defer span.Finish()
-
- 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),
- }
- }
+) error {
+ return httputil.CallInternalRPCAPI(
+ "PerformPeek", h.roomserverURL+RoomserverPerformPeekPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) PerformInboundPeek(
@@ -219,45 +199,32 @@ func (h *httpRoomserverInternalAPI) PerformInboundPeek(
request *api.PerformInboundPeekRequest,
response *api.PerformInboundPeekResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "PerformInboundPeek")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverPerformInboundPeekPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "PerformInboundPeek", h.roomserverURL+RoomserverPerformInboundPeekPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) PerformUnpeek(
ctx context.Context,
request *api.PerformUnpeekRequest,
response *api.PerformUnpeekResponse,
-) {
- span, ctx := opentracing.StartSpanFromContext(ctx, "PerformUnpeek")
- defer span.Finish()
-
- 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),
- }
- }
+) error {
+ return httputil.CallInternalRPCAPI(
+ "PerformUnpeek", h.roomserverURL+RoomserverPerformUnpeekPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) PerformRoomUpgrade(
ctx context.Context,
request *api.PerformRoomUpgradeRequest,
response *api.PerformRoomUpgradeResponse,
-) {
- span, ctx := opentracing.StartSpanFromContext(ctx, "PerformRoomUpgrade")
- defer span.Finish()
-
- 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),
- }
- }
+) error {
+ return httputil.CallInternalRPCAPI(
+ "PerformRoomUpgrade", h.roomserverURL+RoomserverPerformRoomUpgradePath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) PerformLeave(
@@ -265,62 +232,43 @@ func (h *httpRoomserverInternalAPI) PerformLeave(
request *api.PerformLeaveRequest,
response *api.PerformLeaveResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "PerformLeave")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverPerformLeavePath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "PerformLeave", h.roomserverURL+RoomserverPerformLeavePath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) PerformPublish(
ctx context.Context,
- req *api.PerformPublishRequest,
- res *api.PerformPublishResponse,
-) {
- span, ctx := opentracing.StartSpanFromContext(ctx, "PerformPublish")
- defer span.Finish()
-
- 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),
- }
- }
+ request *api.PerformPublishRequest,
+ response *api.PerformPublishResponse,
+) error {
+ return httputil.CallInternalRPCAPI(
+ "PerformPublish", h.roomserverURL+RoomserverPerformPublishPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) PerformAdminEvacuateRoom(
ctx context.Context,
- req *api.PerformAdminEvacuateRoomRequest,
- res *api.PerformAdminEvacuateRoomResponse,
-) {
- span, ctx := opentracing.StartSpanFromContext(ctx, "PerformAdminEvacuateRoom")
- defer span.Finish()
-
- 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),
- }
- }
+ request *api.PerformAdminEvacuateRoomRequest,
+ response *api.PerformAdminEvacuateRoomResponse,
+) error {
+ return httputil.CallInternalRPCAPI(
+ "PerformAdminEvacuateRoom", h.roomserverURL+RoomserverPerformAdminEvacuateRoomPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) PerformAdminEvacuateUser(
ctx context.Context,
- req *api.PerformAdminEvacuateUserRequest,
- res *api.PerformAdminEvacuateUserResponse,
-) {
- span, ctx := opentracing.StartSpanFromContext(ctx, "PerformAdminEvacuateUser")
- defer span.Finish()
-
- 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),
- }
- }
+ request *api.PerformAdminEvacuateUserRequest,
+ response *api.PerformAdminEvacuateUserResponse,
+) error {
+ return httputil.CallInternalRPCAPI(
+ "PerformAdminEvacuateUser", h.roomserverURL+RoomserverPerformAdminEvacuateUserPath,
+ h.httpClient, ctx, request, response,
+ )
}
// QueryLatestEventsAndState implements RoomserverQueryAPI
@@ -329,11 +277,10 @@ func (h *httpRoomserverInternalAPI) QueryLatestEventsAndState(
request *api.QueryLatestEventsAndStateRequest,
response *api.QueryLatestEventsAndStateResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryLatestEventsAndState")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryLatestEventsAndStatePath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryLatestEventsAndState", h.roomserverURL+RoomserverQueryLatestEventsAndStatePath,
+ h.httpClient, ctx, request, response,
+ )
}
// QueryStateAfterEvents implements RoomserverQueryAPI
@@ -342,11 +289,10 @@ func (h *httpRoomserverInternalAPI) QueryStateAfterEvents(
request *api.QueryStateAfterEventsRequest,
response *api.QueryStateAfterEventsResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryStateAfterEvents")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryStateAfterEventsPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryStateAfterEvents", h.roomserverURL+RoomserverQueryStateAfterEventsPath,
+ h.httpClient, ctx, request, response,
+ )
}
// QueryEventsByID implements RoomserverQueryAPI
@@ -355,11 +301,10 @@ func (h *httpRoomserverInternalAPI) QueryEventsByID(
request *api.QueryEventsByIDRequest,
response *api.QueryEventsByIDResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryEventsByID")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryEventsByIDPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryEventsByID", h.roomserverURL+RoomserverQueryEventsByIDPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) QueryPublishedRooms(
@@ -367,11 +312,10 @@ func (h *httpRoomserverInternalAPI) QueryPublishedRooms(
request *api.QueryPublishedRoomsRequest,
response *api.QueryPublishedRoomsResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryPublishedRooms")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryPublishedRoomsPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryPublishedRooms", h.roomserverURL+RoomserverQueryPublishedRoomsPath,
+ h.httpClient, ctx, request, response,
+ )
}
// QueryMembershipForUser implements RoomserverQueryAPI
@@ -380,11 +324,10 @@ func (h *httpRoomserverInternalAPI) QueryMembershipForUser(
request *api.QueryMembershipForUserRequest,
response *api.QueryMembershipForUserResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryMembershipForUser")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryMembershipForUserPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryMembershipForUser", h.roomserverURL+RoomserverQueryMembershipForUserPath,
+ h.httpClient, ctx, request, response,
+ )
}
// QueryMembershipsForRoom implements RoomserverQueryAPI
@@ -393,11 +336,10 @@ func (h *httpRoomserverInternalAPI) QueryMembershipsForRoom(
request *api.QueryMembershipsForRoomRequest,
response *api.QueryMembershipsForRoomResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryMembershipsForRoom")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryMembershipsForRoomPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryMembershipsForRoom", h.roomserverURL+RoomserverQueryMembershipsForRoomPath,
+ h.httpClient, ctx, request, response,
+ )
}
// QueryMembershipsForRoom implements RoomserverQueryAPI
@@ -406,11 +348,10 @@ func (h *httpRoomserverInternalAPI) QueryServerJoinedToRoom(
request *api.QueryServerJoinedToRoomRequest,
response *api.QueryServerJoinedToRoomResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryServerJoinedToRoom")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryServerJoinedToRoomPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryServerJoinedToRoom", h.roomserverURL+RoomserverQueryServerJoinedToRoomPath,
+ h.httpClient, ctx, request, response,
+ )
}
// QueryServerAllowedToSeeEvent implements RoomserverQueryAPI
@@ -419,11 +360,10 @@ func (h *httpRoomserverInternalAPI) QueryServerAllowedToSeeEvent(
request *api.QueryServerAllowedToSeeEventRequest,
response *api.QueryServerAllowedToSeeEventResponse,
) (err error) {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryServerAllowedToSeeEvent")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryServerAllowedToSeeEventPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryServerAllowedToSeeEvent", h.roomserverURL+RoomserverQueryServerAllowedToSeeEventPath,
+ h.httpClient, ctx, request, response,
+ )
}
// QueryMissingEvents implements RoomServerQueryAPI
@@ -432,11 +372,10 @@ func (h *httpRoomserverInternalAPI) QueryMissingEvents(
request *api.QueryMissingEventsRequest,
response *api.QueryMissingEventsResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryMissingEvents")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryMissingEventsPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryMissingEvents", h.roomserverURL+RoomserverQueryMissingEventsPath,
+ h.httpClient, ctx, request, response,
+ )
}
// QueryStateAndAuthChain implements RoomserverQueryAPI
@@ -445,11 +384,10 @@ func (h *httpRoomserverInternalAPI) QueryStateAndAuthChain(
request *api.QueryStateAndAuthChainRequest,
response *api.QueryStateAndAuthChainResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryStateAndAuthChain")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryStateAndAuthChainPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryStateAndAuthChain", h.roomserverURL+RoomserverQueryStateAndAuthChainPath,
+ h.httpClient, ctx, request, response,
+ )
}
// PerformBackfill implements RoomServerQueryAPI
@@ -458,11 +396,10 @@ func (h *httpRoomserverInternalAPI) PerformBackfill(
request *api.PerformBackfillRequest,
response *api.PerformBackfillResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "PerformBackfill")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverPerformBackfillPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "PerformBackfill", h.roomserverURL+RoomserverPerformBackfillPath,
+ h.httpClient, ctx, request, response,
+ )
}
// QueryRoomVersionCapabilities implements RoomServerQueryAPI
@@ -471,11 +408,10 @@ func (h *httpRoomserverInternalAPI) QueryRoomVersionCapabilities(
request *api.QueryRoomVersionCapabilitiesRequest,
response *api.QueryRoomVersionCapabilitiesResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryRoomVersionCapabilities")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryRoomVersionCapabilitiesPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryRoomVersionCapabilities", h.roomserverURL+RoomserverQueryRoomVersionCapabilitiesPath,
+ h.httpClient, ctx, request, response,
+ )
}
// QueryRoomVersionForRoom implements RoomServerQueryAPI
@@ -488,16 +424,10 @@ func (h *httpRoomserverInternalAPI) QueryRoomVersionForRoom(
response.RoomVersion = roomVersion
return nil
}
-
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryRoomVersionForRoom")
- defer span.Finish()
-
- 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
+ return httputil.CallInternalRPCAPI(
+ "QueryRoomVersionForRoom", h.roomserverURL+RoomserverQueryRoomVersionForRoomPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) QueryCurrentState(
@@ -505,11 +435,10 @@ func (h *httpRoomserverInternalAPI) QueryCurrentState(
request *api.QueryCurrentStateRequest,
response *api.QueryCurrentStateResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryCurrentState")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryCurrentStatePath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryCurrentState", h.roomserverURL+RoomserverQueryCurrentStatePath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) QueryRoomsForUser(
@@ -517,11 +446,10 @@ func (h *httpRoomserverInternalAPI) QueryRoomsForUser(
request *api.QueryRoomsForUserRequest,
response *api.QueryRoomsForUserResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryRoomsForUser")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryRoomsForUserPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryRoomsForUser", h.roomserverURL+RoomserverQueryRoomsForUserPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) QueryBulkStateContent(
@@ -529,68 +457,75 @@ func (h *httpRoomserverInternalAPI) QueryBulkStateContent(
request *api.QueryBulkStateContentRequest,
response *api.QueryBulkStateContentResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryBulkStateContent")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryBulkStateContentPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+ return httputil.CallInternalRPCAPI(
+ "QueryBulkStateContent", h.roomserverURL+RoomserverQueryBulkStateContentPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) QuerySharedUsers(
- ctx context.Context, req *api.QuerySharedUsersRequest, res *api.QuerySharedUsersResponse,
+ ctx context.Context,
+ request *api.QuerySharedUsersRequest,
+ response *api.QuerySharedUsersResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QuerySharedUsers")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQuerySharedUsersPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
+ return httputil.CallInternalRPCAPI(
+ "QuerySharedUsers", h.roomserverURL+RoomserverQuerySharedUsersPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) QueryKnownUsers(
- ctx context.Context, req *api.QueryKnownUsersRequest, res *api.QueryKnownUsersResponse,
+ ctx context.Context,
+ request *api.QueryKnownUsersRequest,
+ response *api.QueryKnownUsersResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryKnownUsers")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryKnownUsersPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
+ return httputil.CallInternalRPCAPI(
+ "QueryKnownUsers", h.roomserverURL+RoomserverQueryKnownUsersPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) QueryAuthChain(
- ctx context.Context, req *api.QueryAuthChainRequest, res *api.QueryAuthChainResponse,
+ ctx context.Context,
+ request *api.QueryAuthChainRequest,
+ response *api.QueryAuthChainResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryAuthChain")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryAuthChainPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
+ return httputil.CallInternalRPCAPI(
+ "QueryAuthChain", h.roomserverURL+RoomserverQueryAuthChainPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) QueryServerBannedFromRoom(
- ctx context.Context, req *api.QueryServerBannedFromRoomRequest, res *api.QueryServerBannedFromRoomResponse,
+ ctx context.Context,
+ request *api.QueryServerBannedFromRoomRequest,
+ response *api.QueryServerBannedFromRoomResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryServerBannedFromRoom")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryServerBannedFromRoomPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
+ return httputil.CallInternalRPCAPI(
+ "QueryServerBannedFromRoom", h.roomserverURL+RoomserverQueryServerBannedFromRoomPath,
+ h.httpClient, ctx, request, response,
+ )
}
func (h *httpRoomserverInternalAPI) QueryRestrictedJoinAllowed(
- ctx context.Context, req *api.QueryRestrictedJoinAllowedRequest, res *api.QueryRestrictedJoinAllowedResponse,
+ ctx context.Context,
+ request *api.QueryRestrictedJoinAllowedRequest,
+ response *api.QueryRestrictedJoinAllowedResponse,
) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "QueryRestrictedJoinAllowed")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverQueryRestrictedJoinAllowed
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
+ return httputil.CallInternalRPCAPI(
+ "QueryRestrictedJoinAllowed", h.roomserverURL+RoomserverQueryRestrictedJoinAllowed,
+ h.httpClient, ctx, request, response,
+ )
}
-func (h *httpRoomserverInternalAPI) PerformForget(ctx context.Context, req *api.PerformForgetRequest, res *api.PerformForgetResponse) error {
- span, ctx := opentracing.StartSpanFromContext(ctx, "PerformForget")
- defer span.Finish()
-
- apiURL := h.roomserverURL + RoomserverPerformForgetPath
- return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
+func (h *httpRoomserverInternalAPI) PerformForget(
+ ctx context.Context,
+ request *api.PerformForgetRequest,
+ response *api.PerformForgetResponse,
+) error {
+ return httputil.CallInternalRPCAPI(
+ "PerformForget", h.roomserverURL+RoomserverPerformForgetPath,
+ h.httpClient, ctx, request, response,
+ )
}
diff --git a/roomserver/inthttp/server.go b/roomserver/inthttp/server.go
index 99338158..e325d76a 100644
--- a/roomserver/inthttp/server.go
+++ b/roomserver/inthttp/server.go
@@ -1,499 +1,196 @@
package inthttp
import (
- "encoding/json"
- "net/http"
-
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/roomserver/api"
- "github.com/matrix-org/util"
)
// AddRoutes adds the RoomserverInternalAPI handlers to the http.ServeMux.
// nolint: gocyclo
func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
- internalAPIMux.Handle(RoomserverInputRoomEventsPath,
- httputil.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse {
- var request api.InputRoomEventsRequest
- 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 {
- 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 := 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 {
- 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())
- }
- 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 {
- 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 := 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 {
- var request api.PerformPeekRequest
- var response api.PerformPeekResponse
- 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 {
- var request api.PerformInboundPeekRequest
- var response api.PerformInboundPeekResponse
- 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 {
- var request api.PerformUnpeekRequest
- var response api.PerformUnpeekResponse
- 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 {
- var request api.PerformRoomUpgradeRequest
- var response api.PerformRoomUpgradeResponse
- 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 {
- var request api.PerformPublishRequest
- var response api.PerformPublishResponse
- 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 {
- var request api.PerformAdminEvacuateRoomRequest
- var response api.PerformAdminEvacuateRoomResponse
- 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 {
- var request api.PerformAdminEvacuateUserRequest
- var response api.PerformAdminEvacuateUserResponse
- 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(
+ RoomserverInputRoomEventsPath,
+ httputil.MakeInternalRPCAPI("RoomserverInputRoomEvents", r.InputRoomEvents),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverPerformInvitePath,
+ httputil.MakeInternalRPCAPI("RoomserverPerformInvite", r.PerformInvite),
)
+
+ internalAPIMux.Handle(
+ RoomserverPerformJoinPath,
+ httputil.MakeInternalRPCAPI("RoomserverPerformJoin", r.PerformJoin),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverPerformLeavePath,
+ httputil.MakeInternalRPCAPI("RoomserverPerformLeave", r.PerformLeave),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverPerformPeekPath,
+ httputil.MakeInternalRPCAPI("RoomserverPerformPeek", r.PerformPeek),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverPerformInboundPeekPath,
+ httputil.MakeInternalRPCAPI("RoomserverPerformInboundPeek", r.PerformInboundPeek),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverPerformUnpeekPath,
+ httputil.MakeInternalRPCAPI("RoomserverPerformUnpeek", r.PerformUnpeek),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverPerformRoomUpgradePath,
+ httputil.MakeInternalRPCAPI("RoomserverPerformRoomUpgrade", r.PerformRoomUpgrade),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverPerformPublishPath,
+ httputil.MakeInternalRPCAPI("RoomserverPerformPublish", r.PerformPublish),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverPerformAdminEvacuateRoomPath,
+ httputil.MakeInternalRPCAPI("RoomserverPerformAdminEvacuateRoom", r.PerformAdminEvacuateRoom),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverPerformAdminEvacuateUserPath,
+ httputil.MakeInternalRPCAPI("RoomserverPerformAdminEvacuateUser", r.PerformAdminEvacuateUser),
+ )
+
internalAPIMux.Handle(
RoomserverQueryPublishedRoomsPath,
- httputil.MakeInternalAPI("queryPublishedRooms", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverQueryPublishedRooms", r.QueryPublishedRooms),
)
+
internalAPIMux.Handle(
RoomserverQueryLatestEventsAndStatePath,
- httputil.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverQueryLatestEventsAndState", r.QueryLatestEventsAndState),
)
+
internalAPIMux.Handle(
RoomserverQueryStateAfterEventsPath,
- httputil.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverQueryStateAfterEvents", r.QueryStateAfterEvents),
)
+
internalAPIMux.Handle(
RoomserverQueryEventsByIDPath,
- httputil.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverQueryEventsByID", r.QueryEventsByID),
)
+
internalAPIMux.Handle(
RoomserverQueryMembershipForUserPath,
- httputil.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverQueryMembershipForUser", r.QueryMembershipForUser),
)
+
internalAPIMux.Handle(
RoomserverQueryMembershipsForRoomPath,
- httputil.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverQueryMembershipsForRoom", r.QueryMembershipsForRoom),
)
+
internalAPIMux.Handle(
RoomserverQueryServerJoinedToRoomPath,
- httputil.MakeInternalAPI("queryServerJoinedToRoom", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverQueryServerJoinedToRoom", r.QueryServerJoinedToRoom),
)
+
internalAPIMux.Handle(
RoomserverQueryServerAllowedToSeeEventPath,
- httputil.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverQueryServerAllowedToSeeEvent", r.QueryServerAllowedToSeeEvent),
)
+
internalAPIMux.Handle(
RoomserverQueryMissingEventsPath,
- httputil.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverQueryMissingEvents", r.QueryMissingEvents),
)
+
internalAPIMux.Handle(
RoomserverQueryStateAndAuthChainPath,
- httputil.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverQueryStateAndAuthChain", r.QueryStateAndAuthChain),
)
+
internalAPIMux.Handle(
RoomserverPerformBackfillPath,
- httputil.MakeInternalAPI("PerformBackfill", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverPerformBackfill", r.PerformBackfill),
)
+
internalAPIMux.Handle(
RoomserverPerformForgetPath,
- httputil.MakeInternalAPI("PerformForget", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverPerformForget", r.PerformForget),
)
+
internalAPIMux.Handle(
RoomserverQueryRoomVersionCapabilitiesPath,
- httputil.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverQueryRoomVersionCapabilities", r.QueryRoomVersionCapabilities),
)
+
internalAPIMux.Handle(
RoomserverQueryRoomVersionForRoomPath,
- httputil.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverQueryRoomVersionForRoom", r.QueryRoomVersionForRoom),
)
+
internalAPIMux.Handle(
RoomserverSetRoomAliasPath,
- httputil.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverSetRoomAlias", r.SetRoomAlias),
)
+
internalAPIMux.Handle(
RoomserverGetRoomIDForAliasPath,
- httputil.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverGetRoomIDForAlias", r.GetRoomIDForAlias),
)
+
internalAPIMux.Handle(
RoomserverGetAliasesForRoomIDPath,
- httputil.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse {
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverGetAliasesForRoomID", r.GetAliasesForRoomID),
)
+
internalAPIMux.Handle(
RoomserverRemoveRoomAliasPath,
- httputil.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse {
- 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 {
- request := api.QueryCurrentStateRequest{}
- response := api.QueryCurrentStateResponse{}
- 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 {
- request := api.QueryRoomsForUserRequest{}
- response := api.QueryRoomsForUserResponse{}
- 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 {
- request := api.QueryBulkStateContentRequest{}
- response := api.QueryBulkStateContentResponse{}
- 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 {
- request := api.QuerySharedUsersRequest{}
- response := api.QuerySharedUsersResponse{}
- 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 {
- request := api.QueryKnownUsersRequest{}
- response := api.QueryKnownUsersResponse{}
- 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 {
- request := api.QueryServerBannedFromRoomRequest{}
- response := api.QueryServerBannedFromRoomResponse{}
- 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 {
- request := api.QueryAuthChainRequest{}
- response := api.QueryAuthChainResponse{}
- 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 {
- request := api.QueryRestrictedJoinAllowedRequest{}
- response := api.QueryRestrictedJoinAllowedResponse{}
- 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}
- }),
+ httputil.MakeInternalRPCAPI("RoomserverRemoveRoomAlias", r.RemoveRoomAlias),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverQueryCurrentStatePath,
+ httputil.MakeInternalRPCAPI("RoomserverQueryCurrentState", r.QueryCurrentState),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverQueryRoomsForUserPath,
+ httputil.MakeInternalRPCAPI("RoomserverQueryRoomsForUser", r.QueryRoomsForUser),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverQueryBulkStateContentPath,
+ httputil.MakeInternalRPCAPI("RoomserverQueryBulkStateContent", r.QueryBulkStateContent),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverQuerySharedUsersPath,
+ httputil.MakeInternalRPCAPI("RoomserverQuerySharedUsers", r.QuerySharedUsers),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverQueryKnownUsersPath,
+ httputil.MakeInternalRPCAPI("RoomserverQueryKnownUsers", r.QueryKnownUsers),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverQueryServerBannedFromRoomPath,
+ httputil.MakeInternalRPCAPI("RoomserverQueryServerBannedFromRoom", r.QueryServerBannedFromRoom),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverQueryAuthChainPath,
+ httputil.MakeInternalRPCAPI("RoomserverQueryAuthChain", r.QueryAuthChain),
+ )
+
+ internalAPIMux.Handle(
+ RoomserverQueryRestrictedJoinAllowed,
+ httputil.MakeInternalRPCAPI("RoomserverQueryRestrictedJoinAllowed", r.QueryRestrictedJoinAllowed),
)
}