From 6cdfaa2b6b9c7ee5a4213431ab3de0da95ae3e9f Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Wed, 24 May 2023 19:18:18 +0200 Subject: [PATCH 01/12] Move send_leave to GMSL --- federationapi/routing/leave.go | 170 ++++------------------------- roomserver/api/api.go | 1 + roomserver/internal/query/query.go | 24 ++++ 3 files changed, 48 insertions(+), 147 deletions(-) diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go index 3e576e09c6..aa7f693606 100644 --- a/federationapi/routing/leave.go +++ b/federationapi/routing/leave.go @@ -165,165 +165,41 @@ func SendLeave( } } - verImpl, err := gomatrixserverlib.GetRoomVersion(roomVersion) - if err != nil { - return util.JSONResponse{ - Code: http.StatusInternalServerError, - JSON: spec.UnsupportedRoomVersion( - fmt.Sprintf("QueryRoomVersionForRoom returned unknown version: %s", roomVersion), - ), - } - } + event, err := gomatrixserverlib.HandleSendLeave( + httpReq.Context(), request.Content(), request.Origin(), roomVersion, eventID, roomID, rsAPI, keys, + ) - // Decode the event JSON from the request. - event, err := verImpl.NewEventFromUntrustedJSON(request.Content()) - switch err.(type) { - case gomatrixserverlib.BadJSONError: - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: spec.BadJSON(err.Error()), - } + switch e := err.(type) { case nil: - default: - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: spec.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()), - } - } - - // Check that the room ID is correct. - if event.RoomID() != roomID { - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: spec.BadJSON("The room ID in the request path must match the room ID in the leave event JSON"), - } - } - - // Check that the event ID is correct. - if event.EventID() != eventID { - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: spec.BadJSON("The event ID in the request path must match the event ID in the leave event JSON"), - } - } - - if event.StateKey() == nil || event.StateKeyEquals("") { - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: spec.BadJSON("No state key was provided in the leave event."), - } - } - if !event.StateKeyEquals(event.Sender()) { - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: spec.BadJSON("Event state key must match the event sender."), - } - } - - // Check that the sender belongs to the server that is sending us - // the request. By this point we've already asserted that the sender - // and the state key are equal so we don't need to check both. - var serverName spec.ServerName - if _, serverName, err = gomatrixserverlib.SplitID('@', event.Sender()); err != nil { - return util.JSONResponse{ - Code: http.StatusForbidden, - JSON: spec.Forbidden("The sender of the join is invalid"), - } - } else if serverName != request.Origin() { - return util.JSONResponse{ - Code: http.StatusForbidden, - JSON: spec.Forbidden("The sender does not match the server that originated the request"), - } - } - - // Check if the user has already left. If so, no-op! - queryReq := &api.QueryLatestEventsAndStateRequest{ - RoomID: roomID, - StateToFetch: []gomatrixserverlib.StateKeyTuple{ - { - EventType: spec.MRoomMember, - StateKey: *event.StateKey(), - }, - }, - } - queryRes := &api.QueryLatestEventsAndStateResponse{} - err = rsAPI.QueryLatestEventsAndState(httpReq.Context(), queryReq, queryRes) - if err != nil { - util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryLatestEventsAndState failed") - return util.JSONResponse{ - Code: http.StatusInternalServerError, - JSON: spec.InternalServerError{}, - } - } - // The room doesn't exist or we weren't ever joined to it. Might as well - // no-op here. - if !queryRes.RoomExists || len(queryRes.StateEvents) == 0 { - return util.JSONResponse{ - Code: http.StatusOK, - JSON: struct{}{}, - } - } - // Check if we're recycling a previous leave event. - if event.EventID() == queryRes.StateEvents[0].EventID() { - return util.JSONResponse{ - Code: http.StatusOK, - JSON: struct{}{}, - } - } - // We are/were joined/invited/banned or something. Check if - // we can no-op here. - if len(queryRes.StateEvents) == 1 { - if mem, merr := queryRes.StateEvents[0].Membership(); merr == nil && mem == spec.Leave { - return util.JSONResponse{ - Code: http.StatusOK, - JSON: struct{}{}, - } - } - } - - // Check that the event is signed by the server sending the request. - redacted, err := verImpl.RedactEventJSON(event.JSON()) - if err != nil { - logrus.WithError(err).Errorf("XXX: leave.go") - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: spec.BadJSON("The event JSON could not be redacted"), - } - } - verifyRequests := []gomatrixserverlib.VerifyJSONRequest{{ - ServerName: serverName, - Message: redacted, - AtTS: event.OriginServerTS(), - StrictValidityChecking: true, - }} - verifyResults, err := keys.VerifyJSONs(httpReq.Context(), verifyRequests) - if err != nil { - util.GetLogger(httpReq.Context()).WithError(err).Error("keys.VerifyJSONs failed") + case spec.InternalServerError: + util.GetLogger(httpReq.Context()).WithError(err).Error("failed to handle send_leave request") return util.JSONResponse{ Code: http.StatusInternalServerError, JSON: spec.InternalServerError{}, } - } - if verifyResults[0].Error != nil { - return util.JSONResponse{ - Code: http.StatusForbidden, - JSON: spec.Forbidden("The leave must be signed by the server it originated on"), + case spec.MatrixError: + util.GetLogger(httpReq.Context()).WithError(err).Error("failed to handle send_leave request") + code := http.StatusInternalServerError + switch e.ErrCode { + case spec.ErrorForbidden: + code = http.StatusForbidden + case spec.ErrorNotFound: + code = http.StatusNotFound + case spec.ErrorUnsupportedRoomVersion: + code = http.StatusInternalServerError + case spec.ErrorBadJSON: + code = http.StatusBadRequest } - } - // check membership is set to leave - mem, err := event.Membership() - if err != nil { - util.GetLogger(httpReq.Context()).WithError(err).Error("event.Membership failed") return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: spec.BadJSON("missing content.membership key"), + Code: code, + JSON: e, } - } - if mem != spec.Leave { + default: + util.GetLogger(httpReq.Context()).WithError(err).Error("failed to handle send_leave request") return util.JSONResponse{ Code: http.StatusBadRequest, - JSON: spec.BadJSON("The membership in the event content must be set to leave"), + JSON: spec.Unknown("unknown error"), } } diff --git a/roomserver/api/api.go b/roomserver/api/api.go index 213e16e5df..0627770f5e 100644 --- a/roomserver/api/api.go +++ b/roomserver/api/api.go @@ -197,6 +197,7 @@ type UserRoomserverAPI interface { } type FederationRoomserverAPI interface { + gomatrixserverlib.LatestStateQuerier InputRoomEventsAPI QueryLatestEventsAndStateAPI QueryBulkStateContentAPI diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index effcc90d7e..c81692ce17 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -55,6 +55,30 @@ func (r *Queryer) QueryLatestEventsAndState( return helpers.QueryLatestEventsAndState(ctx, r.DB, request, response) } +func (r *Queryer) LatestState( + ctx context.Context, roomID spec.RoomID, userID spec.UserID, +) ([]gomatrixserverlib.PDU, error) { + request := &api.QueryLatestEventsAndStateRequest{ + RoomID: roomID.String(), + StateToFetch: []gomatrixserverlib.StateKeyTuple{ + { + EventType: spec.MRoomMember, + StateKey: userID.String(), + }, + }, + } + response := &api.QueryLatestEventsAndStateResponse{} + err := helpers.QueryLatestEventsAndState(ctx, r.DB, request, response) + if err != nil { + return nil, err + } + res := make([]gomatrixserverlib.PDU, 0, len(response.StateEvents)) + for _, ev := range response.StateEvents { + res = append(res, ev.PDU) + } + return res, nil +} + // QueryStateAfterEvents implements api.RoomserverInternalAPI func (r *Queryer) QueryStateAfterEvents( ctx context.Context, From 254d53578986115ed856e9040fe3852f9eda862c Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Fri, 26 May 2023 10:30:57 +0200 Subject: [PATCH 02/12] Update GMSL --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 16e5adc8c8..55851fbe63 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 - github.com/matrix-org/gomatrixserverlib v0.0.0-20230524095531-95ba6c68efb6 + github.com/matrix-org/gomatrixserverlib v0.0.0-20230525131408-9e1377a918b6 github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 github.com/mattn/go-sqlite3 v1.14.16 diff --git a/go.sum b/go.sum index 98e7e839df..05e4b7d7ca 100644 --- a/go.sum +++ b/go.sum @@ -323,8 +323,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s= -github.com/matrix-org/gomatrixserverlib v0.0.0-20230524095531-95ba6c68efb6 h1:FQpdh/KGCCQJytz4GAdG6pbx3DJ1HNzdKFc/BCZ0hP0= -github.com/matrix-org/gomatrixserverlib v0.0.0-20230524095531-95ba6c68efb6/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU= +github.com/matrix-org/gomatrixserverlib v0.0.0-20230525131408-9e1377a918b6 h1:GZJdDQt/IJynQyWpHsYYWQUyCu9Y+asAdwfL7pJNQHU= +github.com/matrix-org/gomatrixserverlib v0.0.0-20230525131408-9e1377a918b6/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU= github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A= github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ= github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y= From 1e73175e27972ac0c49360267770cec64905310e Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Tue, 30 May 2023 18:01:19 +0200 Subject: [PATCH 03/12] Remove LatestState --- go.mod | 2 +- go.sum | 2 ++ roomserver/api/api.go | 1 - roomserver/internal/query/query.go | 24 ------------------------ 4 files changed, 3 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index 55851fbe63..521c98d70c 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 - github.com/matrix-org/gomatrixserverlib v0.0.0-20230525131408-9e1377a918b6 + github.com/matrix-org/gomatrixserverlib v0.0.0-20230530160030-2640a7efaaaa github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 github.com/mattn/go-sqlite3 v1.14.16 diff --git a/go.sum b/go.sum index 05e4b7d7ca..1d7518fadb 100644 --- a/go.sum +++ b/go.sum @@ -325,6 +325,8 @@ github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8 github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s= github.com/matrix-org/gomatrixserverlib v0.0.0-20230525131408-9e1377a918b6 h1:GZJdDQt/IJynQyWpHsYYWQUyCu9Y+asAdwfL7pJNQHU= github.com/matrix-org/gomatrixserverlib v0.0.0-20230525131408-9e1377a918b6/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU= +github.com/matrix-org/gomatrixserverlib v0.0.0-20230530160030-2640a7efaaaa h1:m0wWaq2qvMJdYrj5p/mLXV11gbFEKNd6o7C16poSlW0= +github.com/matrix-org/gomatrixserverlib v0.0.0-20230530160030-2640a7efaaaa/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU= github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A= github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ= github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y= diff --git a/roomserver/api/api.go b/roomserver/api/api.go index 0627770f5e..213e16e5df 100644 --- a/roomserver/api/api.go +++ b/roomserver/api/api.go @@ -197,7 +197,6 @@ type UserRoomserverAPI interface { } type FederationRoomserverAPI interface { - gomatrixserverlib.LatestStateQuerier InputRoomEventsAPI QueryLatestEventsAndStateAPI QueryBulkStateContentAPI diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index c81692ce17..effcc90d7e 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -55,30 +55,6 @@ func (r *Queryer) QueryLatestEventsAndState( return helpers.QueryLatestEventsAndState(ctx, r.DB, request, response) } -func (r *Queryer) LatestState( - ctx context.Context, roomID spec.RoomID, userID spec.UserID, -) ([]gomatrixserverlib.PDU, error) { - request := &api.QueryLatestEventsAndStateRequest{ - RoomID: roomID.String(), - StateToFetch: []gomatrixserverlib.StateKeyTuple{ - { - EventType: spec.MRoomMember, - StateKey: userID.String(), - }, - }, - } - response := &api.QueryLatestEventsAndStateResponse{} - err := helpers.QueryLatestEventsAndState(ctx, r.DB, request, response) - if err != nil { - return nil, err - } - res := make([]gomatrixserverlib.PDU, 0, len(response.StateEvents)) - for _, ev := range response.StateEvents { - res = append(res, ev.PDU) - } - return res, nil -} - // QueryStateAfterEvents implements api.RoomserverInternalAPI func (r *Queryer) QueryStateAfterEvents( ctx context.Context, From 246836517cfdb309450361a549a1fb78dc3bce26 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Wed, 31 May 2023 10:39:19 +0200 Subject: [PATCH 04/12] Fix unused stateKey variable --- roomserver/internal/query/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index effcc90d7e..9b520aa5cb 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -868,7 +868,7 @@ func (r *Queryer) QueryRoomInfo(ctx context.Context, roomID spec.RoomID) (*types } func (r *Queryer) CurrentStateEvent(ctx context.Context, roomID spec.RoomID, eventType string, stateKey string) (gomatrixserverlib.PDU, error) { - res, err := r.DB.GetStateEvent(ctx, roomID.String(), eventType, "") + res, err := r.DB.GetStateEvent(ctx, roomID.String(), eventType, stateKey) if res == nil { return nil, err } From 478a6339809f923550901f27063c9bf6659c7e17 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Thu, 1 Jun 2023 13:32:10 +0200 Subject: [PATCH 05/12] Update GMSL --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a20757bbcc..8906b8c66b 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 - github.com/matrix-org/gomatrixserverlib v0.0.0-20230531155817-0e3adf17bee6 + github.com/matrix-org/gomatrixserverlib v0.0.0-20230601112942-5d099f949e82 github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 github.com/mattn/go-sqlite3 v1.14.16 diff --git a/go.sum b/go.sum index a1946adaaf..0060419f24 100644 --- a/go.sum +++ b/go.sum @@ -323,8 +323,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s= -github.com/matrix-org/gomatrixserverlib v0.0.0-20230531155817-0e3adf17bee6 h1:Kh1TNvJDhWN5CdgtICNUC4G0wV2km51LGr46Dvl153A= -github.com/matrix-org/gomatrixserverlib v0.0.0-20230531155817-0e3adf17bee6/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU= +github.com/matrix-org/gomatrixserverlib v0.0.0-20230601112942-5d099f949e82 h1:VC9MCGI47z3ksNQt/sTcnwO//syibxgyz/6ckD6BjkY= +github.com/matrix-org/gomatrixserverlib v0.0.0-20230601112942-5d099f949e82/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU= github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A= github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ= github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y= From 94d2074eb52d7099f3fae6fbba7c48f8917914ac Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Fri, 2 Jun 2023 13:01:58 +0200 Subject: [PATCH 06/12] Move parsing the event back to Dendrite --- federationapi/routing/leave.go | 30 +++++++++++++++++++++++++++--- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go index 49c7771246..636ade7489 100644 --- a/federationapi/routing/leave.go +++ b/federationapi/routing/leave.go @@ -165,8 +165,32 @@ func SendLeave( } } - event, err := gomatrixserverlib.HandleSendLeave( - httpReq.Context(), request.Content(), request.Origin(), roomVersion, eventID, roomID, rsAPI, keys, + verImpl, err := gomatrixserverlib.GetRoomVersion(roomVersion) + if err != nil { + return util.JSONResponse{ + Code: http.StatusBadRequest, + JSON: spec.UnsupportedRoomVersion(err.Error()), + } + } + + // Decode the incomingEvent JSON from the request. + incomingEvent, err := verImpl.NewEventFromUntrustedJSON(request.Content()) + switch err.(type) { + case gomatrixserverlib.BadJSONError: + return util.JSONResponse{ + Code: http.StatusBadRequest, + JSON: spec.BadJSON(err.Error()), + } + case nil: + default: + return util.JSONResponse{ + Code: http.StatusBadRequest, + JSON: spec.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()), + } + } + + leaveEvent, err := verImpl.HandleSendLeave( + httpReq.Context(), incomingEvent, request.Origin(), eventID, roomID, rsAPI, keys, ) switch e := err.(type) { @@ -211,7 +235,7 @@ func SendLeave( InputRoomEvents: []api.InputRoomEvent{ { Kind: api.KindNew, - Event: &types.HeaderedEvent{PDU: event}, + Event: &types.HeaderedEvent{PDU: leaveEvent}, SendAsServer: string(cfg.Matrix.ServerName), TransactionID: nil, }, diff --git a/go.mod b/go.mod index 8906b8c66b..d206c91ede 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 - github.com/matrix-org/gomatrixserverlib v0.0.0-20230601112942-5d099f949e82 + github.com/matrix-org/gomatrixserverlib v0.0.0-20230602105922-540062a7516d github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 github.com/mattn/go-sqlite3 v1.14.16 diff --git a/go.sum b/go.sum index 0060419f24..a551bc5a48 100644 --- a/go.sum +++ b/go.sum @@ -323,8 +323,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s= -github.com/matrix-org/gomatrixserverlib v0.0.0-20230601112942-5d099f949e82 h1:VC9MCGI47z3ksNQt/sTcnwO//syibxgyz/6ckD6BjkY= -github.com/matrix-org/gomatrixserverlib v0.0.0-20230601112942-5d099f949e82/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU= +github.com/matrix-org/gomatrixserverlib v0.0.0-20230602105922-540062a7516d h1:7zP85gTIeoHb/GG0qRVi5uhwfnbSpt7G8SwDvGw7mUE= +github.com/matrix-org/gomatrixserverlib v0.0.0-20230602105922-540062a7516d/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU= github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A= github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ= github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y= From e5d2b23ad0fe2f492a25bf176c26874b90c7d444 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Thu, 23 Nov 2023 11:26:23 +0100 Subject: [PATCH 07/12] Revert changes --- federationapi/routing/leave.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go index 636ade7489..57d75ad21b 100644 --- a/federationapi/routing/leave.go +++ b/federationapi/routing/leave.go @@ -189,9 +189,8 @@ func SendLeave( } } - leaveEvent, err := verImpl.HandleSendLeave( - httpReq.Context(), incomingEvent, request.Origin(), eventID, roomID, rsAPI, keys, - ) + leaveEvent, err := gomatrixserverlib.HandleSendLeave( + httpReq.Context(), incomingEvent, request.Origin(), roomVersion, eventID, roomID, rsAPI, keys) switch e := err.(type) { case nil: From af860fc6fa6987d7eeeeafba9f26085fc4f8aa02 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Thu, 23 Nov 2023 12:21:01 +0100 Subject: [PATCH 08/12] Some tweaks --- federationapi/routing/leave.go | 37 +++++++++------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go index 5dc195f340..98a5810f00 100644 --- a/federationapi/routing/leave.go +++ b/federationapi/routing/leave.go @@ -184,34 +184,8 @@ func SendLeave( } } - verImpl, err := gomatrixserverlib.GetRoomVersion(roomVersion) - if err != nil { - return util.JSONResponse{ - Code: http.StatusInternalServerError, - JSON: spec.UnsupportedRoomVersion( - fmt.Sprintf("QueryRoomVersionForRoom returned unknown version: %s", roomVersion), - ), - } - } - - // Decode the event JSON from the request. - event, err := verImpl.NewEventFromUntrustedJSON(request.Content()) - switch err.(type) { - case gomatrixserverlib.BadJSONError: - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: spec.BadJSON(err.Error()), - } - case nil: - default: - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: spec.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()), - } - } - leaveEvent, err := gomatrixserverlib.HandleSendLeave( - httpReq.Context(), incomingEvent, request.Origin(), roomVersion, eventID, roomID, rsAPI, keys) + httpReq.Context(), request.Content(), request.Origin(), roomVersion, eventID, roomID, rsAPI, keys) switch e := err.(type) { case nil: @@ -247,6 +221,15 @@ func SendLeave( } } + // The user was never joined to the room, has already left, + // or we already processed this leave event, so this is a no-op. + if leaveEvent == nil { + return util.JSONResponse{ + Code: http.StatusOK, + JSON: struct{}{}, + } + } + // Send the events to the room server. // We are responsible for notifying other servers that the user has left // the room, so set SendAsServer to cfg.Matrix.ServerName From 57af9aede96b9b859f06423bdc201e605300add8 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Thu, 23 Nov 2023 12:23:29 +0100 Subject: [PATCH 09/12] Update GMSL --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a4bf8d341a..7b709a88e0 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 - github.com/matrix-org/gomatrixserverlib v0.0.0-20230602105922-540062a7516d + github.com/matrix-org/gomatrixserverlib v0.0.0-20231123112137-2369defc080e github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7 github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 github.com/mattn/go-sqlite3 v1.14.17 diff --git a/go.sum b/go.sum index f188b3eebc..213a5f1662 100644 --- a/go.sum +++ b/go.sum @@ -208,8 +208,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s= -github.com/matrix-org/gomatrixserverlib v0.0.0-20230602105922-540062a7516d h1:7zP85gTIeoHb/GG0qRVi5uhwfnbSpt7G8SwDvGw7mUE= -github.com/matrix-org/gomatrixserverlib v0.0.0-20230602105922-540062a7516d/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU= +github.com/matrix-org/gomatrixserverlib v0.0.0-20231123112137-2369defc080e h1:+E3txSR4+DEo39eoTlVxo9lNXfjJ8f8iXsyYwr1Yugs= +github.com/matrix-org/gomatrixserverlib v0.0.0-20231123112137-2369defc080e/go.mod h1:M8m7seOroO5ePlgxA7AFZymnG90Cnh94rYQyngSrZkk= github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7 h1:6t8kJr8i1/1I5nNttw6nn1ryQJgzVlBmSGgPiiaTdw4= github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7/go.mod h1:ReWMS/LoVnOiRAdq9sNUC2NZnd1mZkMNB52QhpTRWjg= github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y= From 55a01df5c905dca2c0c32db14b82628bb43a79b0 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Thu, 23 Nov 2023 12:51:50 +0100 Subject: [PATCH 10/12] Fix oopps --- federationapi/routing/leave.go | 23 +++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go index 98a5810f00..c4b46af934 100644 --- a/federationapi/routing/leave.go +++ b/federationapi/routing/leave.go @@ -176,6 +176,29 @@ func SendLeave( keys gomatrixserverlib.JSONVerifier, roomID, eventID string, ) util.JSONResponse { + parsedRoomID, err := spec.NewRoomID(roomID) + if err != nil { + return util.JSONResponse{ + Code: http.StatusInternalServerError, + JSON: spec.InternalServerError{}, + } + } + roomInfo, err := rsAPI.QueryRoomInfo(httpReq.Context(), *parsedRoomID) + if err != nil { + return util.JSONResponse{ + Code: http.StatusInternalServerError, + JSON: spec.InternalServerError{}, + } + } + // Either the room does not exist or does not + // have any events. + if roomInfo == nil || roomInfo.IsStub() { + return util.JSONResponse{ + Code: http.StatusOK, + JSON: struct{}{}, + } + } + roomVersion, err := rsAPI.QueryRoomVersionForRoom(httpReq.Context(), roomID) if err != nil { return util.JSONResponse{ diff --git a/go.mod b/go.mod index 7b709a88e0..709e679b81 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 - github.com/matrix-org/gomatrixserverlib v0.0.0-20231123112137-2369defc080e + github.com/matrix-org/gomatrixserverlib v0.0.0-20231123113708-498c48650dc9 github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7 github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 github.com/mattn/go-sqlite3 v1.14.17 diff --git a/go.sum b/go.sum index 213a5f1662..13960a7962 100644 --- a/go.sum +++ b/go.sum @@ -208,8 +208,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s= -github.com/matrix-org/gomatrixserverlib v0.0.0-20231123112137-2369defc080e h1:+E3txSR4+DEo39eoTlVxo9lNXfjJ8f8iXsyYwr1Yugs= -github.com/matrix-org/gomatrixserverlib v0.0.0-20231123112137-2369defc080e/go.mod h1:M8m7seOroO5ePlgxA7AFZymnG90Cnh94rYQyngSrZkk= +github.com/matrix-org/gomatrixserverlib v0.0.0-20231123113708-498c48650dc9 h1:jf2D3nqdpb/AWyKPeNScYMphaf0FnmoqdulKmTz8484= +github.com/matrix-org/gomatrixserverlib v0.0.0-20231123113708-498c48650dc9/go.mod h1:M8m7seOroO5ePlgxA7AFZymnG90Cnh94rYQyngSrZkk= github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7 h1:6t8kJr8i1/1I5nNttw6nn1ryQJgzVlBmSGgPiiaTdw4= github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7/go.mod h1:ReWMS/LoVnOiRAdq9sNUC2NZnd1mZkMNB52QhpTRWjg= github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y= From f4e8ed6f1f287bd409bd88506092da696dfdf069 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Thu, 23 Nov 2023 13:02:03 +0100 Subject: [PATCH 11/12] No need to get the roomVersion twice --- federationapi/routing/leave.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go index c4b46af934..2612f61013 100644 --- a/federationapi/routing/leave.go +++ b/federationapi/routing/leave.go @@ -199,16 +199,8 @@ func SendLeave( } } - roomVersion, err := rsAPI.QueryRoomVersionForRoom(httpReq.Context(), roomID) - if err != nil { - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: spec.UnsupportedRoomVersion(err.Error()), - } - } - leaveEvent, err := gomatrixserverlib.HandleSendLeave( - httpReq.Context(), request.Content(), request.Origin(), roomVersion, eventID, roomID, rsAPI, keys) + httpReq.Context(), request.Content(), request.Origin(), roomInfo.RoomVersion, eventID, roomID, rsAPI, keys) switch e := err.(type) { case nil: From 86ad6c64f5f63e3b50790af0b386c0578ee7707c Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Thu, 23 Nov 2023 14:34:26 +0100 Subject: [PATCH 12/12] Update GMSL a last time --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 709e679b81..fc666f9a2a 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 - github.com/matrix-org/gomatrixserverlib v0.0.0-20231123113708-498c48650dc9 + github.com/matrix-org/gomatrixserverlib v0.0.0-20231123125815-185a49a8c72d github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7 github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 github.com/mattn/go-sqlite3 v1.14.17 diff --git a/go.sum b/go.sum index 13960a7962..4d2aea84ce 100644 --- a/go.sum +++ b/go.sum @@ -208,8 +208,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s= -github.com/matrix-org/gomatrixserverlib v0.0.0-20231123113708-498c48650dc9 h1:jf2D3nqdpb/AWyKPeNScYMphaf0FnmoqdulKmTz8484= -github.com/matrix-org/gomatrixserverlib v0.0.0-20231123113708-498c48650dc9/go.mod h1:M8m7seOroO5ePlgxA7AFZymnG90Cnh94rYQyngSrZkk= +github.com/matrix-org/gomatrixserverlib v0.0.0-20231123125815-185a49a8c72d h1:gdXFfDL6daF/mf6PihcArRITjbT5HJGApkaHR9Z3KWs= +github.com/matrix-org/gomatrixserverlib v0.0.0-20231123125815-185a49a8c72d/go.mod h1:M8m7seOroO5ePlgxA7AFZymnG90Cnh94rYQyngSrZkk= github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7 h1:6t8kJr8i1/1I5nNttw6nn1ryQJgzVlBmSGgPiiaTdw4= github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7/go.mod h1:ReWMS/LoVnOiRAdq9sNUC2NZnd1mZkMNB52QhpTRWjg= github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=