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 14:46:06 +00:00
|
|
|
"fmt"
|
2017-11-29 09:38:56 +00:00
|
|
|
"net/http"
|
2020-05-12 15:24:28 +00:00
|
|
|
"sort"
|
2018-08-06 13:09:25 +00:00
|
|
|
"time"
|
2017-11-29 09:38:56 +00:00
|
|
|
|
2022-08-05 09:12:41 +00:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2023-04-06 08:55:01 +00:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
2023-04-19 14:50:33 +00:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
2022-08-05 09:12:41 +00:00
|
|
|
"github.com/matrix-org/util"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
2020-06-12 13:55:57 +00: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 11:54:20 +00: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 14:50:33 +00:00
|
|
|
request *fclient.FederationRequest,
|
2020-08-10 13:18:04 +00:00
|
|
|
cfg *config.FederationAPI,
|
2022-05-05 18:30:38 +00:00
|
|
|
rsAPI api.FederationRoomserverAPI,
|
2023-05-17 00:33:27 +00: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 14:46:06 +00:00
|
|
|
remoteVersions []gomatrixserverlib.RoomVersion,
|
2017-11-29 09:38:56 +00:00
|
|
|
) util.JSONResponse {
|
2023-05-17 00:33:27 +00:00
|
|
|
roomVersion, err := rsAPI.QueryRoomVersionForRoom(httpReq.Context(), roomID.String())
|
2023-04-27 06:07:13 +00:00
|
|
|
if err != nil {
|
2023-05-17 00:33:27 +00: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 00:33:27 +00: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 14:46:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-17 00:33:27 +00:00
|
|
|
req := api.QueryServerJoinedToRoomRequest{
|
2023-05-23 17:37:04 +00:00
|
|
|
ServerName: request.Destination(),
|
2023-05-17 00:33:27 +00:00
|
|
|
RoomID: roomID.String(),
|
2020-09-24 15:18:13 +00:00
|
|
|
}
|
2023-05-17 00:33:27 +00:00
|
|
|
res := api.QueryServerJoinedToRoomResponse{}
|
2023-06-07 17:14:35 +00:00
|
|
|
if err = rsAPI.QueryServerJoinedToRoom(httpReq.Context(), &req, &res); err != nil {
|
2020-09-24 15:18:13 +00:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryServerJoinedToRoom failed")
|
|
|
|
return util.JSONResponse{
|
2023-05-17 00:33:27 +00:00
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
2020-09-24 15:18:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-17 00:33:27 +00:00
|
|
|
createJoinTemplate := func(proto *gomatrixserverlib.ProtoEvent) (gomatrixserverlib.PDU, []gomatrixserverlib.PDU, error) {
|
2023-06-07 17:14:35 +00:00
|
|
|
identity, signErr := cfg.Matrix.SigningIdentityFor(request.Destination())
|
|
|
|
if signErr != nil {
|
|
|
|
util.GetLogger(httpReq.Context()).WithError(signErr).Errorf("obtaining signing identity for %s failed", request.Destination())
|
2023-05-17 00:33:27 +00:00
|
|
|
return nil, nil, spec.NotFound(fmt.Sprintf("Server name %q does not exist", request.Destination()))
|
|
|
|
}
|
|
|
|
|
|
|
|
queryRes := api.QueryLatestEventsAndStateResponse{
|
|
|
|
RoomVersion: roomVersion,
|
|
|
|
}
|
2023-06-07 17:14:35 +00:00
|
|
|
event, signErr := eventutil.QueryAndBuildEvent(httpReq.Context(), proto, identity, time.Now(), rsAPI, &queryRes)
|
|
|
|
switch e := signErr.(type) {
|
2023-05-17 00:33:27 +00:00
|
|
|
case nil:
|
|
|
|
case eventutil.ErrRoomNoExists:
|
2023-06-07 17:14:35 +00:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(signErr).Error("eventutil.BuildEvent failed")
|
2023-05-17 00:33:27 +00:00
|
|
|
return nil, nil, spec.NotFound("Room does not exist")
|
|
|
|
case gomatrixserverlib.BadJSONError:
|
2023-06-07 17:14:35 +00:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(signErr).Error("eventutil.BuildEvent failed")
|
2023-05-17 00:33:27 +00:00
|
|
|
return nil, nil, spec.BadJSON(e.Error())
|
|
|
|
default:
|
2023-06-07 17:14:35 +00:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(signErr).Error("eventutil.BuildEvent failed")
|
2023-05-17 00:33:27 +00:00
|
|
|
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 13:16:55 +00:00
|
|
|
roomQuerier := api.JoinRoomQuerier{
|
|
|
|
Roomserver: rsAPI,
|
2023-05-17 00:33:27 +00:00
|
|
|
}
|
|
|
|
|
2023-06-07 17:14:35 +00:00
|
|
|
senderID, err := rsAPI.QuerySenderIDForUser(httpReq.Context(), roomID.String(), userID)
|
|
|
|
if err != nil {
|
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QuerySenderIDForUser failed")
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-17 00:33:27 +00:00
|
|
|
input := gomatrixserverlib.HandleMakeJoinInput{
|
2023-06-06 20:55:18 +00:00
|
|
|
Context: httpReq.Context(),
|
|
|
|
UserID: userID,
|
2023-06-07 17:14:35 +00:00
|
|
|
SenderID: senderID,
|
2023-06-06 20:55:18 +00:00
|
|
|
RoomID: roomID,
|
|
|
|
RoomVersion: roomVersion,
|
|
|
|
RemoteVersions: remoteVersions,
|
|
|
|
RequestOrigin: request.Origin(),
|
|
|
|
LocalServerName: cfg.Matrix.ServerName,
|
|
|
|
LocalServerInRoom: res.RoomExists && res.IsInRoom,
|
|
|
|
RoomQuerier: &roomQuerier,
|
2023-06-07 17:14:35 +00:00
|
|
|
UserIDQuerier: func(roomID string, senderID spec.SenderID) (*spec.UserID, error) {
|
2023-06-06 20:55:18 +00:00
|
|
|
return rsAPI.QueryUserIDForSender(httpReq.Context(), roomID, senderID)
|
|
|
|
},
|
2023-05-17 00:33:27 +00:00
|
|
|
BuildEventTemplate: createJoinTemplate,
|
|
|
|
}
|
|
|
|
response, internalErr := gomatrixserverlib.HandleMakeJoin(input)
|
2023-05-19 16:27:01 +00:00
|
|
|
switch e := internalErr.(type) {
|
|
|
|
case nil:
|
|
|
|
case spec.InternalServerError:
|
2023-05-23 17:37:04 +00:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(internalErr).Error("failed to handle make_join request")
|
2023-05-19 16:27:01 +00:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
|
|
|
case spec.MatrixError:
|
2023-05-23 17:37:04 +00:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(internalErr).Error("failed to handle make_join request")
|
2023-05-19 16:27:01 +00: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 16:27:01 +00:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: code,
|
|
|
|
JSON: e,
|
|
|
|
}
|
|
|
|
case spec.IncompatibleRoomVersionError:
|
2023-05-23 17:37:04 +00:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(internalErr).Error("failed to handle make_join request")
|
2023-05-19 16:27:01 +00:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: e,
|
|
|
|
}
|
|
|
|
default:
|
2023-05-23 17:37:04 +00:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(internalErr).Error("failed to handle make_join request")
|
2023-05-19 16:27:01 +00:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: spec.Unknown("unknown error"),
|
2020-06-04 09:53:39 +00:00
|
|
|
}
|
2017-11-29 09:38:56 +00:00
|
|
|
}
|
2020-03-27 16:28:22 +00:00
|
|
|
|
2023-05-17 00:33:27 +00: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 00:33:27 +00: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 00:33:27 +00: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 12:53:47 +00:00
|
|
|
// The make-join send-join dance makes much more sense as a single
|
|
|
|
// flow so the cyclomatic complexity is high:
|
2022-05-25 09:05:30 +00:00
|
|
|
// nolint:gocyclo
|
2017-11-29 09:38:56 +00:00
|
|
|
func SendJoin(
|
|
|
|
httpReq *http.Request,
|
2023-04-19 14:50:33 +00:00
|
|
|
request *fclient.FederationRequest,
|
2020-08-10 13:18:04 +00:00
|
|
|
cfg *config.FederationAPI,
|
2022-05-05 18:30:38 +00:00
|
|
|
rsAPI api.FederationRoomserverAPI,
|
2020-06-15 15:57:59 +00:00
|
|
|
keys gomatrixserverlib.JSONVerifier,
|
2023-05-19 16:27:01 +00:00
|
|
|
roomID spec.RoomID,
|
|
|
|
eventID string,
|
2017-11-29 09:38:56 +00:00
|
|
|
) util.JSONResponse {
|
2023-05-19 16:27:01 +00:00
|
|
|
roomVersion, err := rsAPI.QueryRoomVersionForRoom(httpReq.Context(), roomID.String())
|
2023-04-27 06:07:13 +00:00
|
|
|
if err != nil {
|
2020-05-01 09:48:17 +00: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 00:33:27 +00:00
|
|
|
JSON: spec.InternalServerError{},
|
2020-03-27 16:28:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-19 16:27:01 +00: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 16:33:49 +00:00
|
|
|
MembershipQuerier: &api.MembershipQuerier{Roomserver: rsAPI},
|
2023-06-07 17:14:35 +00:00
|
|
|
UserIDQuerier: func(roomID string, senderID spec.SenderID) (*spec.UserID, error) {
|
2023-06-06 20:55:18 +00:00
|
|
|
return rsAPI.QueryUserIDForSender(httpReq.Context(), roomID, senderID)
|
|
|
|
},
|
2023-05-19 16:27:01 +00: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 16:27:01 +00:00
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
2022-08-02 09:22:17 +00:00
|
|
|
}
|
2023-05-19 16:27:01 +00: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 09:22:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-29 09:38:56 +00:00
|
|
|
return util.JSONResponse{
|
2023-05-19 16:27:01 +00:00
|
|
|
Code: code,
|
|
|
|
JSON: e,
|
2017-11-29 09:38:56 +00:00
|
|
|
}
|
2023-05-19 16:27:01 +00: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 16:27:01 +00:00
|
|
|
JSON: spec.Unknown("unknown error"),
|
2017-11-29 09:38:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-19 16:27:01 +00:00
|
|
|
if response == nil {
|
|
|
|
util.GetLogger(httpReq.Context()).Error("gmsl.HandleMakeJoin returned invalid response")
|
2023-05-17 00:33:27 +00:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
2023-05-19 16:27:01 +00: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 09:48:17 +00:00
|
|
|
err = rsAPI.QueryStateAndAuthChain(httpReq.Context(), &api.QueryStateAndAuthChainRequest{
|
2023-05-19 16:27:01 +00: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 14:46:06 +00: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 09:48:17 +00:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryStateAndAuthChain failed")
|
2023-05-17 00:33:27 +00: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 22:46:49 +00:00
|
|
|
JSON: spec.NotFound("Room does not exist"),
|
2019-12-20 14:42:57 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-25 08:51:36 +00:00
|
|
|
if !stateAndAuthChainResponse.StateKnown {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusForbidden,
|
2023-05-09 22:46:49 +00:00
|
|
|
JSON: spec.Forbidden("State not known"),
|
2022-08-25 08:51:36 +00: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 16:27:01 +00:00
|
|
|
if !response.AlreadyJoined {
|
|
|
|
var rsResponse api.InputRoomEventsResponse
|
2023-05-09 22:46:49 +00:00
|
|
|
rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
|
2021-07-19 12:15:19 +00:00
|
|
|
InputRoomEvents: []api.InputRoomEvent{
|
|
|
|
{
|
|
|
|
Kind: api.KindNew,
|
2023-05-19 16:27:01 +00:00
|
|
|
Event: &types.HeaderedEvent{PDU: response.JoinEvent},
|
2021-07-19 12:15:19 +00:00
|
|
|
SendAsServer: string(cfg.Matrix.ServerName),
|
|
|
|
TransactionID: nil,
|
|
|
|
},
|
2020-05-04 12:53:47 +00:00
|
|
|
},
|
2023-05-19 16:27:01 +00:00
|
|
|
}, &rsResponse)
|
|
|
|
if rsResponse.ErrMsg != "" {
|
|
|
|
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, rsResponse.ErrMsg).Error("SendEvents failed")
|
|
|
|
if rsResponse.NotAllowed {
|
2021-07-19 12:15:19 +00:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
2023-05-19 16:27:01 +00:00
|
|
|
JSON: spec.Forbidden(rsResponse.ErrMsg),
|
2021-07-19 12:15:19 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-17 00:33:27 +00:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
2020-05-04 12:53:47 +00:00
|
|
|
}
|
2017-11-29 09:38:56 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 15:24:28 +00: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 09:53:38 +00: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 08:55:01 +00:00
|
|
|
JSON: fclient.RespSendJoin{
|
2023-04-27 11:54:20 +00:00
|
|
|
StateEvents: types.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.StateEvents),
|
|
|
|
AuthEvents: types.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.AuthChainEvents),
|
2020-05-05 09:53:38 +00:00
|
|
|
Origin: cfg.Matrix.ServerName,
|
2023-05-19 16:27:01 +00:00
|
|
|
Event: response.JoinEvent.JSON(),
|
2017-11-29 09:38:56 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-05-12 15:24:28 +00:00
|
|
|
|
2023-04-27 11:54:20 +00:00
|
|
|
type eventsByDepth []*types.HeaderedEvent
|
2020-05-12 15:24:28 +00: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()
|
|
|
|
}
|