2017-11-29 09:38:56 +00:00
|
|
|
// Copyright 2017 New Vector Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package routing
|
|
|
|
|
|
|
|
import (
|
Federation for v3/v4 rooms (#954)
* Update gomatrixserverlib
* Default to room version 4
* Update gomatrixserverlib
* Limit prev_events and auth_events
* Fix auth_events, prev_events
* Fix linter issues
* Update gomatrixserverlib
* Fix getState
* Update sytest-whitelist
* Squashed commit of the following:
commit 067b87506357c996fd6ddb11271db9469ad4ce80
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Fri Apr 3 14:29:06 2020 +0100
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
commit 955244c09298d0e6c870377dad3af2ffa1f5e578
Author: Ben B <benne@klimlive.de>
Date: Fri Apr 3 12:40:50 2020 +0200
use custom http client instead of the http DefaultClient (#823)
This commit replaces the default client from the http lib with a custom one.
The previously used default client doesn't come with a timeout. This could cause
unwanted locks.
That solution chosen here creates a http client in the base component dendrite
with a constant timeout of 30 seconds. If it should be necessary to overwrite
this, we could include the timeout in the dendrite configuration.
Here it would be a good idea to extend the type "Address" by a timeout and
create an http client for each service.
Closes #820
Signed-off-by: Benedikt Bongartz <benne@klimlive.de>
Co-authored-by: Kegsay <kegan@matrix.org>
* Update sytest-whitelist, sytest-blacklist
* Update go.mod/go.sum
* Add some error wrapping for debug
* Add a NOTSPEC to common/events.go
* Perform state resolution at send_join
* Set default room version to v2 again
* Tweak GetCapabilities
* Add comments to ResolveConflictsAdhoc
* Update sytest-blacklist
* go mod tidy
* Update sytest-whitelist, sytest-blacklist
* Update versions
* Updates from review comments
* Update sytest-blacklist, sytest-whitelist
* Check room versions compatible at make_join, add some comments, update gomatrixserverlib, other tweaks
* Set default room version back to v2
* Update gomatrixserverlib, sytest-whitelist
2020-04-09 15:46:06 +01:00
|
|
|
"fmt"
|
2017-11-29 09:38:56 +00:00
|
|
|
"net/http"
|
2020-05-12 16:24:28 +01:00
|
|
|
"sort"
|
2018-08-06 14:09:25 +01:00
|
|
|
"time"
|
2017-11-29 09:38:56 +00:00
|
|
|
|
2022-08-05 10:12:41 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2023-04-06 09:55:01 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
2023-04-19 15:50:33 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
2022-08-05 10:12:41 +01:00
|
|
|
"github.com/matrix-org/util"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
2020-06-12 14:55:57 +01:00
|
|
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
2017-11-29 09:38:56 +00:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/api"
|
2023-04-27 12:54:20 +01:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/types"
|
2020-12-02 17:41:00 +00:00
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2017-11-29 09:38:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// MakeJoin implements the /make_join API
|
|
|
|
func MakeJoin(
|
|
|
|
httpReq *http.Request,
|
2023-04-19 15:50:33 +01:00
|
|
|
request *fclient.FederationRequest,
|
2020-08-10 14:18:04 +01:00
|
|
|
cfg *config.FederationAPI,
|
2022-05-05 19:30:38 +01:00
|
|
|
rsAPI api.FederationRoomserverAPI,
|
2023-05-17 01:33:27 +01:00
|
|
|
roomID spec.RoomID, userID spec.UserID,
|
Federation for v3/v4 rooms (#954)
* Update gomatrixserverlib
* Default to room version 4
* Update gomatrixserverlib
* Limit prev_events and auth_events
* Fix auth_events, prev_events
* Fix linter issues
* Update gomatrixserverlib
* Fix getState
* Update sytest-whitelist
* Squashed commit of the following:
commit 067b87506357c996fd6ddb11271db9469ad4ce80
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Fri Apr 3 14:29:06 2020 +0100
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
commit 955244c09298d0e6c870377dad3af2ffa1f5e578
Author: Ben B <benne@klimlive.de>
Date: Fri Apr 3 12:40:50 2020 +0200
use custom http client instead of the http DefaultClient (#823)
This commit replaces the default client from the http lib with a custom one.
The previously used default client doesn't come with a timeout. This could cause
unwanted locks.
That solution chosen here creates a http client in the base component dendrite
with a constant timeout of 30 seconds. If it should be necessary to overwrite
this, we could include the timeout in the dendrite configuration.
Here it would be a good idea to extend the type "Address" by a timeout and
create an http client for each service.
Closes #820
Signed-off-by: Benedikt Bongartz <benne@klimlive.de>
Co-authored-by: Kegsay <kegan@matrix.org>
* Update sytest-whitelist, sytest-blacklist
* Update go.mod/go.sum
* Add some error wrapping for debug
* Add a NOTSPEC to common/events.go
* Perform state resolution at send_join
* Set default room version to v2 again
* Tweak GetCapabilities
* Add comments to ResolveConflictsAdhoc
* Update sytest-blacklist
* go mod tidy
* Update sytest-whitelist, sytest-blacklist
* Update versions
* Updates from review comments
* Update sytest-blacklist, sytest-whitelist
* Check room versions compatible at make_join, add some comments, update gomatrixserverlib, other tweaks
* Set default room version back to v2
* Update gomatrixserverlib, sytest-whitelist
2020-04-09 15:46:06 +01:00
|
|
|
remoteVersions []gomatrixserverlib.RoomVersion,
|
2017-11-29 09:38:56 +00:00
|
|
|
) util.JSONResponse {
|
2023-05-17 01:33:27 +01:00
|
|
|
roomVersion, err := rsAPI.QueryRoomVersionForRoom(httpReq.Context(), roomID.String())
|
2023-04-27 07:07:13 +01:00
|
|
|
if err != nil {
|
2023-05-17 01:33:27 +01:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("failed obtaining room version")
|
2020-03-27 16:28:22 +00:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
2023-05-17 01:33:27 +01:00
|
|
|
JSON: spec.InternalServerError{},
|
Federation for v3/v4 rooms (#954)
* Update gomatrixserverlib
* Default to room version 4
* Update gomatrixserverlib
* Limit prev_events and auth_events
* Fix auth_events, prev_events
* Fix linter issues
* Update gomatrixserverlib
* Fix getState
* Update sytest-whitelist
* Squashed commit of the following:
commit 067b87506357c996fd6ddb11271db9469ad4ce80
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Fri Apr 3 14:29:06 2020 +0100
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
commit 955244c09298d0e6c870377dad3af2ffa1f5e578
Author: Ben B <benne@klimlive.de>
Date: Fri Apr 3 12:40:50 2020 +0200
use custom http client instead of the http DefaultClient (#823)
This commit replaces the default client from the http lib with a custom one.
The previously used default client doesn't come with a timeout. This could cause
unwanted locks.
That solution chosen here creates a http client in the base component dendrite
with a constant timeout of 30 seconds. If it should be necessary to overwrite
this, we could include the timeout in the dendrite configuration.
Here it would be a good idea to extend the type "Address" by a timeout and
create an http client for each service.
Closes #820
Signed-off-by: Benedikt Bongartz <benne@klimlive.de>
Co-authored-by: Kegsay <kegan@matrix.org>
* Update sytest-whitelist, sytest-blacklist
* Update go.mod/go.sum
* Add some error wrapping for debug
* Add a NOTSPEC to common/events.go
* Perform state resolution at send_join
* Set default room version to v2 again
* Tweak GetCapabilities
* Add comments to ResolveConflictsAdhoc
* Update sytest-blacklist
* go mod tidy
* Update sytest-whitelist, sytest-blacklist
* Update versions
* Updates from review comments
* Update sytest-blacklist, sytest-whitelist
* Check room versions compatible at make_join, add some comments, update gomatrixserverlib, other tweaks
* Set default room version back to v2
* Update gomatrixserverlib, sytest-whitelist
2020-04-09 15:46:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-17 01:33:27 +01:00
|
|
|
req := api.QueryServerJoinedToRoomRequest{
|
2023-05-23 18:37:04 +01:00
|
|
|
ServerName: request.Destination(),
|
2023-05-17 01:33:27 +01:00
|
|
|
RoomID: roomID.String(),
|
2020-09-24 16:18:13 +01:00
|
|
|
}
|
2023-05-17 01:33:27 +01:00
|
|
|
res := api.QueryServerJoinedToRoomResponse{}
|
|
|
|
if err := rsAPI.QueryServerJoinedToRoom(httpReq.Context(), &req, &res); err != nil {
|
2020-09-24 16:18:13 +01:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryServerJoinedToRoom failed")
|
|
|
|
return util.JSONResponse{
|
2023-05-17 01:33:27 +01:00
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
2020-09-24 16:18:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-17 01:33:27 +01:00
|
|
|
createJoinTemplate := func(proto *gomatrixserverlib.ProtoEvent) (gomatrixserverlib.PDU, []gomatrixserverlib.PDU, error) {
|
|
|
|
identity, err := cfg.Matrix.SigningIdentityFor(request.Destination())
|
|
|
|
if err != nil {
|
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Errorf("obtaining signing identity for %s failed", request.Destination())
|
|
|
|
return nil, nil, spec.NotFound(fmt.Sprintf("Server name %q does not exist", request.Destination()))
|
|
|
|
}
|
|
|
|
|
|
|
|
queryRes := api.QueryLatestEventsAndStateResponse{
|
|
|
|
RoomVersion: roomVersion,
|
|
|
|
}
|
2023-05-31 16:27:08 +01:00
|
|
|
event, err := eventutil.QueryAndBuildEvent(httpReq.Context(), proto, identity, time.Now(), rsAPI, &queryRes)
|
2023-05-17 01:33:27 +01:00
|
|
|
switch e := err.(type) {
|
|
|
|
case nil:
|
|
|
|
case eventutil.ErrRoomNoExists:
|
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("eventutil.BuildEvent failed")
|
|
|
|
return nil, nil, spec.NotFound("Room does not exist")
|
|
|
|
case gomatrixserverlib.BadJSONError:
|
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("eventutil.BuildEvent failed")
|
|
|
|
return nil, nil, spec.BadJSON(e.Error())
|
|
|
|
default:
|
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("eventutil.BuildEvent failed")
|
|
|
|
return nil, nil, spec.InternalServerError{}
|
|
|
|
}
|
|
|
|
|
|
|
|
stateEvents := make([]gomatrixserverlib.PDU, len(queryRes.StateEvents))
|
|
|
|
for i, stateEvent := range queryRes.StateEvents {
|
|
|
|
stateEvents[i] = stateEvent.PDU
|
|
|
|
}
|
|
|
|
return event, stateEvents, nil
|
|
|
|
}
|
|
|
|
|
2023-06-06 14:16:55 +01:00
|
|
|
roomQuerier := api.JoinRoomQuerier{
|
|
|
|
Roomserver: rsAPI,
|
2023-05-17 01:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
input := gomatrixserverlib.HandleMakeJoinInput{
|
2023-06-06 21:55:18 +01:00
|
|
|
Context: httpReq.Context(),
|
|
|
|
UserID: userID,
|
|
|
|
RoomID: roomID,
|
|
|
|
RoomVersion: roomVersion,
|
|
|
|
RemoteVersions: remoteVersions,
|
|
|
|
RequestOrigin: request.Origin(),
|
|
|
|
LocalServerName: cfg.Matrix.ServerName,
|
|
|
|
LocalServerInRoom: res.RoomExists && res.IsInRoom,
|
|
|
|
RoomQuerier: &roomQuerier,
|
|
|
|
UserIDQuerier: func(roomID, senderID string) (*spec.UserID, error) {
|
|
|
|
return rsAPI.QueryUserIDForSender(httpReq.Context(), roomID, senderID)
|
|
|
|
},
|
2023-05-17 01:33:27 +01:00
|
|
|
BuildEventTemplate: createJoinTemplate,
|
|
|
|
}
|
|
|
|
response, internalErr := gomatrixserverlib.HandleMakeJoin(input)
|
2023-05-19 17:27:01 +01:00
|
|
|
switch e := internalErr.(type) {
|
|
|
|
case nil:
|
|
|
|
case spec.InternalServerError:
|
2023-05-23 18:37:04 +01:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(internalErr).Error("failed to handle make_join request")
|
2023-05-19 17:27:01 +01:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
|
|
|
case spec.MatrixError:
|
2023-05-23 18:37:04 +01:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(internalErr).Error("failed to handle make_join request")
|
2023-05-19 17:27:01 +01:00
|
|
|
code := http.StatusInternalServerError
|
|
|
|
switch e.ErrCode {
|
|
|
|
case spec.ErrorForbidden:
|
|
|
|
code = http.StatusForbidden
|
|
|
|
case spec.ErrorNotFound:
|
|
|
|
code = http.StatusNotFound
|
|
|
|
case spec.ErrorUnableToAuthoriseJoin:
|
|
|
|
fallthrough // http.StatusBadRequest
|
|
|
|
case spec.ErrorBadJSON:
|
|
|
|
code = http.StatusBadRequest
|
|
|
|
}
|
2022-11-15 15:05:23 +00:00
|
|
|
|
2023-05-19 17:27:01 +01:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: code,
|
|
|
|
JSON: e,
|
|
|
|
}
|
|
|
|
case spec.IncompatibleRoomVersionError:
|
2023-05-23 18:37:04 +01:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(internalErr).Error("failed to handle make_join request")
|
2023-05-19 17:27:01 +01:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: e,
|
|
|
|
}
|
|
|
|
default:
|
2023-05-23 18:37:04 +01:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(internalErr).Error("failed to handle make_join request")
|
2023-05-19 17:27:01 +01:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: spec.Unknown("unknown error"),
|
2020-06-04 10:53:39 +01:00
|
|
|
}
|
2017-11-29 09:38:56 +00:00
|
|
|
}
|
2020-03-27 16:28:22 +00:00
|
|
|
|
2023-05-17 01:33:27 +01:00
|
|
|
if response == nil {
|
|
|
|
util.GetLogger(httpReq.Context()).Error("gmsl.HandleMakeJoin returned invalid response")
|
2017-11-29 09:38:56 +00:00
|
|
|
return util.JSONResponse{
|
2023-05-17 01:33:27 +01:00
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
2017-11-29 09:38:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return util.JSONResponse{
|
2018-03-13 15:55:45 +00:00
|
|
|
Code: http.StatusOK,
|
2020-03-27 16:28:22 +00:00
|
|
|
JSON: map[string]interface{}{
|
2023-05-17 01:33:27 +01:00
|
|
|
"event": response.JoinTemplateEvent,
|
|
|
|
"room_version": response.RoomVersion,
|
2020-03-27 16:28:22 +00:00
|
|
|
},
|
2017-11-29 09:38:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendJoin implements the /send_join API
|
2020-05-04 13:53:47 +01:00
|
|
|
// The make-join send-join dance makes much more sense as a single
|
|
|
|
// flow so the cyclomatic complexity is high:
|
2022-05-25 10:05:30 +01:00
|
|
|
// nolint:gocyclo
|
2017-11-29 09:38:56 +00:00
|
|
|
func SendJoin(
|
|
|
|
httpReq *http.Request,
|
2023-04-19 15:50:33 +01:00
|
|
|
request *fclient.FederationRequest,
|
2020-08-10 14:18:04 +01:00
|
|
|
cfg *config.FederationAPI,
|
2022-05-05 19:30:38 +01:00
|
|
|
rsAPI api.FederationRoomserverAPI,
|
2020-06-15 16:57:59 +01:00
|
|
|
keys gomatrixserverlib.JSONVerifier,
|
2023-05-19 17:27:01 +01:00
|
|
|
roomID spec.RoomID,
|
|
|
|
eventID string,
|
2017-11-29 09:38:56 +00:00
|
|
|
) util.JSONResponse {
|
2023-05-19 17:27:01 +01:00
|
|
|
roomVersion, err := rsAPI.QueryRoomVersionForRoom(httpReq.Context(), roomID.String())
|
2023-04-27 07:07:13 +01:00
|
|
|
if err != nil {
|
2020-05-01 10:48:17 +01:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryRoomVersionForRoom failed")
|
2020-03-27 16:28:22 +00:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
2023-05-17 01:33:27 +01:00
|
|
|
JSON: spec.InternalServerError{},
|
2020-03-27 16:28:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-19 17:27:01 +01:00
|
|
|
input := gomatrixserverlib.HandleSendJoinInput{
|
|
|
|
Context: httpReq.Context(),
|
|
|
|
RoomID: roomID,
|
|
|
|
EventID: eventID,
|
|
|
|
JoinEvent: request.Content(),
|
|
|
|
RoomVersion: roomVersion,
|
|
|
|
RequestOrigin: request.Origin(),
|
|
|
|
LocalServerName: cfg.Matrix.ServerName,
|
|
|
|
KeyID: cfg.Matrix.KeyID,
|
|
|
|
PrivateKey: cfg.Matrix.PrivateKey,
|
|
|
|
Verifier: keys,
|
2023-05-31 17:33:49 +01:00
|
|
|
MembershipQuerier: &api.MembershipQuerier{Roomserver: rsAPI},
|
2023-06-06 21:55:18 +01:00
|
|
|
UserIDQuerier: func(roomID, senderID string) (*spec.UserID, error) {
|
|
|
|
return rsAPI.QueryUserIDForSender(httpReq.Context(), roomID, senderID)
|
|
|
|
},
|
2023-05-19 17:27:01 +01:00
|
|
|
}
|
|
|
|
response, joinErr := gomatrixserverlib.HandleSendJoin(input)
|
|
|
|
switch e := joinErr.(type) {
|
|
|
|
case nil:
|
|
|
|
case spec.InternalServerError:
|
|
|
|
util.GetLogger(httpReq.Context()).WithError(joinErr)
|
2017-11-29 09:38:56 +00:00
|
|
|
return util.JSONResponse{
|
2023-05-19 17:27:01 +01:00
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
2022-08-02 10:22:17 +01:00
|
|
|
}
|
2023-05-19 17:27:01 +01:00
|
|
|
case spec.MatrixError:
|
|
|
|
util.GetLogger(httpReq.Context()).WithError(joinErr)
|
|
|
|
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
|
2022-08-02 10:22:17 +01:00
|
|
|
}
|
|
|
|
|
2017-11-29 09:38:56 +00:00
|
|
|
return util.JSONResponse{
|
2023-05-19 17:27:01 +01:00
|
|
|
Code: code,
|
|
|
|
JSON: e,
|
2017-11-29 09:38:56 +00:00
|
|
|
}
|
2023-05-19 17:27:01 +01:00
|
|
|
default:
|
|
|
|
util.GetLogger(httpReq.Context()).WithError(joinErr)
|
2017-11-29 09:38:56 +00:00
|
|
|
return util.JSONResponse{
|
2018-03-13 15:55:45 +00:00
|
|
|
Code: http.StatusBadRequest,
|
2023-05-19 17:27:01 +01:00
|
|
|
JSON: spec.Unknown("unknown error"),
|
2017-11-29 09:38:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-19 17:27:01 +01:00
|
|
|
if response == nil {
|
|
|
|
util.GetLogger(httpReq.Context()).Error("gmsl.HandleMakeJoin returned invalid response")
|
2023-05-17 01:33:27 +01:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
2023-05-19 17:27:01 +01:00
|
|
|
|
2017-11-29 09:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch the state and auth chain. We do this before we send the events
|
|
|
|
// on, in case this fails.
|
2019-12-20 14:42:57 +00:00
|
|
|
var stateAndAuthChainResponse api.QueryStateAndAuthChainResponse
|
2020-05-01 10:48:17 +01:00
|
|
|
err = rsAPI.QueryStateAndAuthChain(httpReq.Context(), &api.QueryStateAndAuthChainRequest{
|
2023-05-19 17:27:01 +01:00
|
|
|
PrevEventIDs: response.JoinEvent.PrevEventIDs(),
|
|
|
|
AuthEventIDs: response.JoinEvent.AuthEventIDs(),
|
|
|
|
RoomID: roomID.String(),
|
Federation for v3/v4 rooms (#954)
* Update gomatrixserverlib
* Default to room version 4
* Update gomatrixserverlib
* Limit prev_events and auth_events
* Fix auth_events, prev_events
* Fix linter issues
* Update gomatrixserverlib
* Fix getState
* Update sytest-whitelist
* Squashed commit of the following:
commit 067b87506357c996fd6ddb11271db9469ad4ce80
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Fri Apr 3 14:29:06 2020 +0100
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
commit 955244c09298d0e6c870377dad3af2ffa1f5e578
Author: Ben B <benne@klimlive.de>
Date: Fri Apr 3 12:40:50 2020 +0200
use custom http client instead of the http DefaultClient (#823)
This commit replaces the default client from the http lib with a custom one.
The previously used default client doesn't come with a timeout. This could cause
unwanted locks.
That solution chosen here creates a http client in the base component dendrite
with a constant timeout of 30 seconds. If it should be necessary to overwrite
this, we could include the timeout in the dendrite configuration.
Here it would be a good idea to extend the type "Address" by a timeout and
create an http client for each service.
Closes #820
Signed-off-by: Benedikt Bongartz <benne@klimlive.de>
Co-authored-by: Kegsay <kegan@matrix.org>
* Update sytest-whitelist, sytest-blacklist
* Update go.mod/go.sum
* Add some error wrapping for debug
* Add a NOTSPEC to common/events.go
* Perform state resolution at send_join
* Set default room version to v2 again
* Tweak GetCapabilities
* Add comments to ResolveConflictsAdhoc
* Update sytest-blacklist
* go mod tidy
* Update sytest-whitelist, sytest-blacklist
* Update versions
* Updates from review comments
* Update sytest-blacklist, sytest-whitelist
* Check room versions compatible at make_join, add some comments, update gomatrixserverlib, other tweaks
* Set default room version back to v2
* Update gomatrixserverlib, sytest-whitelist
2020-04-09 15:46:06 +01:00
|
|
|
ResolveState: true,
|
2019-12-20 14:42:57 +00:00
|
|
|
}, &stateAndAuthChainResponse)
|
2017-11-29 09:38:56 +00:00
|
|
|
if err != nil {
|
2020-05-01 10:48:17 +01:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryStateAndAuthChain failed")
|
2023-05-17 01:33:27 +01:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
2017-11-29 09:38:56 +00:00
|
|
|
}
|
|
|
|
|
2019-12-20 14:42:57 +00:00
|
|
|
if !stateAndAuthChainResponse.RoomExists {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusNotFound,
|
2023-05-09 23:46:49 +01:00
|
|
|
JSON: spec.NotFound("Room does not exist"),
|
2019-12-20 14:42:57 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-25 09:51:36 +01:00
|
|
|
if !stateAndAuthChainResponse.StateKnown {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusForbidden,
|
2023-05-09 23:46:49 +01:00
|
|
|
JSON: spec.Forbidden("State not known"),
|
2022-08-25 09:51:36 +01:00
|
|
|
}
|
|
|
|
}
|
2019-12-20 14:42:57 +00:00
|
|
|
|
2017-11-29 09:38:56 +00:00
|
|
|
// Send the events to the room server.
|
|
|
|
// We are responsible for notifying other servers that the user has joined
|
|
|
|
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
2023-05-19 17:27:01 +01:00
|
|
|
if !response.AlreadyJoined {
|
|
|
|
var rsResponse api.InputRoomEventsResponse
|
2023-05-09 23:46:49 +01:00
|
|
|
rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
|
2021-07-19 13:15:19 +01:00
|
|
|
InputRoomEvents: []api.InputRoomEvent{
|
|
|
|
{
|
|
|
|
Kind: api.KindNew,
|
2023-05-19 17:27:01 +01:00
|
|
|
Event: &types.HeaderedEvent{PDU: response.JoinEvent},
|
2021-07-19 13:15:19 +01:00
|
|
|
SendAsServer: string(cfg.Matrix.ServerName),
|
|
|
|
TransactionID: nil,
|
|
|
|
},
|
2020-05-04 13:53:47 +01:00
|
|
|
},
|
2023-05-19 17:27:01 +01:00
|
|
|
}, &rsResponse)
|
|
|
|
if rsResponse.ErrMsg != "" {
|
|
|
|
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, rsResponse.ErrMsg).Error("SendEvents failed")
|
|
|
|
if rsResponse.NotAllowed {
|
2021-07-19 13:15:19 +01:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
2023-05-19 17:27:01 +01:00
|
|
|
JSON: spec.Forbidden(rsResponse.ErrMsg),
|
2021-07-19 13:15:19 +01:00
|
|
|
}
|
|
|
|
}
|
2023-05-17 01:33:27 +01:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
2020-05-04 13:53:47 +01:00
|
|
|
}
|
2017-11-29 09:38:56 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 16:24:28 +01:00
|
|
|
// sort events deterministically by depth (lower is earlier)
|
|
|
|
// We also do this because sytest's basic federation server isn't good at using the correct
|
|
|
|
// state if these lists are randomised, resulting in flakey tests. :(
|
|
|
|
sort.Sort(eventsByDepth(stateAndAuthChainResponse.StateEvents))
|
|
|
|
sort.Sort(eventsByDepth(stateAndAuthChainResponse.AuthChainEvents))
|
|
|
|
|
2020-05-05 10:53:38 +01:00
|
|
|
// https://matrix.org/docs/spec/server_server/latest#put-matrix-federation-v1-send-join-roomid-eventid
|
2017-11-29 09:38:56 +00:00
|
|
|
return util.JSONResponse{
|
2018-03-13 15:55:45 +00:00
|
|
|
Code: http.StatusOK,
|
2023-04-06 09:55:01 +01:00
|
|
|
JSON: fclient.RespSendJoin{
|
2023-04-27 12:54:20 +01:00
|
|
|
StateEvents: types.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.StateEvents),
|
|
|
|
AuthEvents: types.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.AuthChainEvents),
|
2020-05-05 10:53:38 +01:00
|
|
|
Origin: cfg.Matrix.ServerName,
|
2023-05-19 17:27:01 +01:00
|
|
|
Event: response.JoinEvent.JSON(),
|
2017-11-29 09:38:56 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-05-12 16:24:28 +01:00
|
|
|
|
2023-04-27 12:54:20 +01:00
|
|
|
type eventsByDepth []*types.HeaderedEvent
|
2020-05-12 16:24:28 +01:00
|
|
|
|
|
|
|
func (e eventsByDepth) Len() int {
|
|
|
|
return len(e)
|
|
|
|
}
|
|
|
|
func (e eventsByDepth) Swap(i, j int) {
|
|
|
|
e[i], e[j] = e[j], e[i]
|
|
|
|
}
|
|
|
|
func (e eventsByDepth) Less(i, j int) bool {
|
|
|
|
return e[i].Depth() < e[j].Depth()
|
|
|
|
}
|