aboutsummaryrefslogtreecommitdiff
path: root/federationapi
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-04-03 14:29:06 +0100
committerGitHub <noreply@github.com>2020-04-03 14:29:06 +0100
commit067b87506357c996fd6ddb11271db9469ad4ce80 (patch)
treee9127d78567b7676ba5ee607e9381ef4e0358911 /federationapi
parent955244c09298d0e6c870377dad3af2ffa1f5e578 (diff)
Invites v2 endpoint (#952)
* Start converting v1 invite endpoint to v2 * Update gomatrixserverlib * Early federationsender code for sending invites * Sending invites sorta happens now * Populate invite request with stripped state * Remodel a bit, don't reflect received invites * Handle invite_room_state * Handle room versions a bit better * Update gomatrixserverlib * Tweak order in destinationQueue.next * Revert check in processMessage * Tweak federation sender destination queue code a bit * Add comments
Diffstat (limited to 'federationapi')
-rw-r--r--federationapi/routing/invite.go37
-rw-r--r--federationapi/routing/routing.go2
2 files changed, 12 insertions, 27 deletions
diff --git a/federationapi/routing/invite.go b/federationapi/routing/invite.go
index 09c3734b..6c3e12e2 100644
--- a/federationapi/routing/invite.go
+++ b/federationapi/routing/invite.go
@@ -15,18 +15,17 @@
package routing
import (
- "context"
+ "encoding/json"
"net/http"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/clientapi/producers"
"github.com/matrix-org/dendrite/common/config"
- "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
)
-// Invite implements /_matrix/federation/v1/invite/{roomID}/{eventID}
+// Invite implements /_matrix/federation/v2/invite/{roomID}/{eventID}
func Invite(
httpReq *http.Request,
request *gomatrixserverlib.FederationRequest,
@@ -36,24 +35,14 @@ func Invite(
producer *producers.RoomserverProducer,
keys gomatrixserverlib.KeyRing,
) util.JSONResponse {
- // Look up the room version for the room.
- verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
- verRes := api.QueryRoomVersionForRoomResponse{}
- if err := producer.QueryAPI.QueryRoomVersionForRoom(context.Background(), &verReq, &verRes); err != nil {
+ inviteReq := gomatrixserverlib.InviteV2Request{}
+ if err := json.Unmarshal(request.Content(), &inviteReq); err != nil {
return util.JSONResponse{
Code: http.StatusBadRequest,
- JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
- }
- }
-
- // Decode the event JSON from the request.
- event, err := gomatrixserverlib.NewEventFromUntrustedJSON(request.Content(), verRes.RoomVersion)
- if err != nil {
- return util.JSONResponse{
- Code: http.StatusBadRequest,
- JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()),
+ JSON: jsonerror.NotJSON("The request body could not be decoded into an invite request. " + err.Error()),
}
}
+ event := inviteReq.Event()
// Check that the room ID is correct.
if event.RoomID() != roomID {
@@ -71,14 +60,6 @@ func Invite(
}
}
- // Check that the event is from the server sending the request.
- if event.Origin() != request.Origin() {
- return util.JSONResponse{
- Code: http.StatusForbidden,
- JSON: jsonerror.Forbidden("The invite must be sent by the server it originated on"),
- }
- }
-
// Check that the event is signed by the server sending the request.
redacted := event.Redact()
verifyRequests := []gomatrixserverlib.VerifyJSONRequest{{
@@ -104,7 +85,11 @@ func Invite(
)
// Add the invite event to the roomserver.
- if err = producer.SendInvite(httpReq.Context(), signedEvent); err != nil {
+ if err = producer.SendInvite(
+ httpReq.Context(),
+ signedEvent.Headered(inviteReq.RoomVersion()),
+ inviteReq.InviteRoomState(),
+ ); err != nil {
util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendInvite failed")
return jsonerror.InternalServerError()
}
diff --git a/federationapi/routing/routing.go b/federationapi/routing/routing.go
index 9ac53576..a2b9dc21 100644
--- a/federationapi/routing/routing.go
+++ b/federationapi/routing/routing.go
@@ -85,7 +85,7 @@ func Setup(
},
)).Methods(http.MethodPut, http.MethodOptions)
- v1fedmux.Handle("/invite/{roomID}/{eventID}", common.MakeFedAPI(
+ v2fedmux.Handle("/invite/{roomID}/{eventID}", common.MakeFedAPI(
"federation_invite", cfg.Matrix.ServerName, keys,
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))