2017-11-29 03:38:56 -06: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 (
|
2023-06-28 13:29:49 -05:00
|
|
|
"context"
|
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 09:46:06 -05:00
|
|
|
"fmt"
|
2017-11-29 03:38:56 -06:00
|
|
|
"net/http"
|
2020-05-12 10:24:28 -05:00
|
|
|
"sort"
|
2018-08-06 08:09:25 -05:00
|
|
|
"time"
|
2017-11-29 03:38:56 -06:00
|
|
|
|
2022-08-05 04:12:41 -05:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2023-04-06 03:55:01 -05:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
2023-04-19 09:50:33 -05:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
2022-08-05 04:12:41 -05:00
|
|
|
"github.com/matrix-org/util"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
2020-06-12 08:55:57 -05:00
|
|
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
2017-11-29 03:38:56 -06:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/api"
|
2023-04-27 06:54:20 -05:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/types"
|
2020-12-02 11:41:00 -06:00
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2017-11-29 03:38:56 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// MakeJoin implements the /make_join API
|
|
|
|
func MakeJoin(
|
|
|
|
httpReq *http.Request,
|
2023-04-19 09:50:33 -05:00
|
|
|
request *fclient.FederationRequest,
|
2020-08-10 08:18:04 -05:00
|
|
|
cfg *config.FederationAPI,
|
2022-05-05 13:30:38 -05:00
|
|
|
rsAPI api.FederationRoomserverAPI,
|
2023-05-16 19:33:27 -05: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 09:46:06 -05:00
|
|
|
remoteVersions []gomatrixserverlib.RoomVersion,
|
2017-11-29 03:38:56 -06:00
|
|
|
) util.JSONResponse {
|
2023-05-16 19:33:27 -05:00
|
|
|
roomVersion, err := rsAPI.QueryRoomVersionForRoom(httpReq.Context(), roomID.String())
|
2023-04-27 01:07:13 -05:00
|
|
|
if err != nil {
|
2023-05-16 19:33:27 -05:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("failed obtaining room version")
|
2020-03-27 11:28:22 -05:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
2023-05-16 19:33:27 -05: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 09:46:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-16 19:33:27 -05:00
|
|
|
req := api.QueryServerJoinedToRoomRequest{
|
2023-05-23 12:37:04 -05:00
|
|
|
ServerName: request.Destination(),
|
2023-05-16 19:33:27 -05:00
|
|
|
RoomID: roomID.String(),
|
2020-09-24 10:18:13 -05:00
|
|
|
}
|
2023-05-16 19:33:27 -05:00
|
|
|
res := api.QueryServerJoinedToRoomResponse{}
|
2023-06-07 12:14:35 -05:00
|
|
|
if err = rsAPI.QueryServerJoinedToRoom(httpReq.Context(), &req, &res); err != nil {
|
2020-09-24 10:18:13 -05:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryServerJoinedToRoom failed")
|
|
|
|
return util.JSONResponse{
|
2023-05-16 19:33:27 -05:00
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
2020-09-24 10:18:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-16 19:33:27 -05:00
|
|
|
createJoinTemplate := func(proto *gomatrixserverlib.ProtoEvent) (gomatrixserverlib.PDU, []gomatrixserverlib.PDU, error) {
|
2023-06-07 12:14:35 -05: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-16 19:33:27 -05:00
|
|
|
return nil, nil, spec.NotFound(fmt.Sprintf("Server name %q does not exist", request.Destination()))
|
|
|
|
}
|
|
|
|
|
|
|
|
queryRes := api.QueryLatestEventsAndStateResponse{
|
|
|
|
RoomVersion: roomVersion,
|
|
|
|
}
|
2023-06-07 12:14:35 -05:00
|
|
|
event, signErr := eventutil.QueryAndBuildEvent(httpReq.Context(), proto, identity, time.Now(), rsAPI, &queryRes)
|
|
|
|
switch e := signErr.(type) {
|
2023-05-16 19:33:27 -05:00
|
|
|
case nil:
|
|
|
|
case eventutil.ErrRoomNoExists:
|
2023-06-07 12:14:35 -05:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(signErr).Error("eventutil.BuildEvent failed")
|
2023-05-16 19:33:27 -05:00
|
|
|
return nil, nil, spec.NotFound("Room does not exist")
|
|
|
|
case gomatrixserverlib.BadJSONError:
|
2023-06-07 12:14:35 -05:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(signErr).Error("eventutil.BuildEvent failed")
|
2023-05-16 19:33:27 -05:00
|
|
|
return nil, nil, spec.BadJSON(e.Error())
|
|
|
|
default:
|
2023-06-07 12:14:35 -05:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(signErr).Error("eventutil.BuildEvent failed")
|
2023-05-16 19:33:27 -05: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 08:16:55 -05:00
|
|
|
roomQuerier := api.JoinRoomQuerier{
|
|
|
|
Roomserver: rsAPI,
|
2023-05-16 19:33:27 -05:00
|
|
|
}
|
|
|
|
|
2023-08-02 05:12:14 -05:00
|
|
|
senderIDPtr, err := rsAPI.QuerySenderIDForUser(httpReq.Context(), roomID, userID)
|
2023-06-07 12:14:35 -05:00
|
|
|
if err != nil {
|
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QuerySenderIDForUser failed")
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-02 05:12:14 -05:00
|
|
|
var senderID spec.SenderID
|
|
|
|
if senderIDPtr == nil {
|
2023-06-28 13:29:49 -05:00
|
|
|
senderID = spec.SenderID(userID.String())
|
2023-08-02 05:12:14 -05:00
|
|
|
} else {
|
|
|
|
senderID = *senderIDPtr
|
2023-06-28 13:29:49 -05:00
|
|
|
}
|
|
|
|
|
2023-05-16 19:33:27 -05:00
|
|
|
input := gomatrixserverlib.HandleMakeJoinInput{
|
2023-06-06 15:55:18 -05:00
|
|
|
Context: httpReq.Context(),
|
|
|
|
UserID: userID,
|
2023-06-07 12:14:35 -05:00
|
|
|
SenderID: senderID,
|
2023-06-06 15:55:18 -05:00
|
|
|
RoomID: roomID,
|
|
|
|
RoomVersion: roomVersion,
|
|
|
|
RemoteVersions: remoteVersions,
|
|
|
|
RequestOrigin: request.Origin(),
|
|
|
|
LocalServerName: cfg.Matrix.ServerName,
|
|
|
|
LocalServerInRoom: res.RoomExists && res.IsInRoom,
|
|
|
|
RoomQuerier: &roomQuerier,
|
2023-06-14 09:23:46 -05:00
|
|
|
UserIDQuerier: func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
2023-06-06 15:55:18 -05:00
|
|
|
return rsAPI.QueryUserIDForSender(httpReq.Context(), roomID, senderID)
|
|
|
|
},
|
2023-05-16 19:33:27 -05:00
|
|
|
BuildEventTemplate: createJoinTemplate,
|
|
|
|
}
|
|
|
|
response, internalErr := gomatrixserverlib.HandleMakeJoin(input)
|
2023-05-19 11:27:01 -05:00
|
|
|
switch e := internalErr.(type) {
|
|
|
|
case nil:
|
|
|
|
case spec.InternalServerError:
|
2023-05-23 12:37:04 -05:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(internalErr).Error("failed to handle make_join request")
|
2023-05-19 11:27:01 -05:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
|
|
|
case spec.MatrixError:
|
2023-05-23 12:37:04 -05:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(internalErr).Error("failed to handle make_join request")
|
2023-05-19 11:27:01 -05: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 09:05:23 -06:00
|
|
|
|
2023-05-19 11:27:01 -05:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: code,
|
|
|
|
JSON: e,
|
|
|
|
}
|
|
|
|
case spec.IncompatibleRoomVersionError:
|
2023-05-23 12:37:04 -05:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(internalErr).Error("failed to handle make_join request")
|
2023-05-19 11:27:01 -05:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: e,
|
|
|
|
}
|
|
|
|
default:
|
2023-05-23 12:37:04 -05:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(internalErr).Error("failed to handle make_join request")
|
2023-05-19 11:27:01 -05:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: spec.Unknown("unknown error"),
|
2020-06-04 04:53:39 -05:00
|
|
|
}
|
2017-11-29 03:38:56 -06:00
|
|
|
}
|
2020-03-27 11:28:22 -05:00
|
|
|
|
2023-05-16 19:33:27 -05:00
|
|
|
if response == nil {
|
|
|
|
util.GetLogger(httpReq.Context()).Error("gmsl.HandleMakeJoin returned invalid response")
|
2017-11-29 03:38:56 -06:00
|
|
|
return util.JSONResponse{
|
2023-05-16 19:33:27 -05:00
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
2017-11-29 03:38:56 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return util.JSONResponse{
|
2018-03-13 10:55:45 -05:00
|
|
|
Code: http.StatusOK,
|
2020-03-27 11:28:22 -05:00
|
|
|
JSON: map[string]interface{}{
|
2023-05-16 19:33:27 -05:00
|
|
|
"event": response.JoinTemplateEvent,
|
|
|
|
"room_version": response.RoomVersion,
|
2020-03-27 11:28:22 -05:00
|
|
|
},
|
2017-11-29 03:38:56 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendJoin implements the /send_join API
|
|
|
|
func SendJoin(
|
|
|
|
httpReq *http.Request,
|
2023-04-19 09:50:33 -05:00
|
|
|
request *fclient.FederationRequest,
|
2020-08-10 08:18:04 -05:00
|
|
|
cfg *config.FederationAPI,
|
2022-05-05 13:30:38 -05:00
|
|
|
rsAPI api.FederationRoomserverAPI,
|
2020-06-15 10:57:59 -05:00
|
|
|
keys gomatrixserverlib.JSONVerifier,
|
2023-05-19 11:27:01 -05:00
|
|
|
roomID spec.RoomID,
|
|
|
|
eventID string,
|
2017-11-29 03:38:56 -06:00
|
|
|
) util.JSONResponse {
|
2023-05-19 11:27:01 -05:00
|
|
|
roomVersion, err := rsAPI.QueryRoomVersionForRoom(httpReq.Context(), roomID.String())
|
2023-04-27 01:07:13 -05:00
|
|
|
if err != nil {
|
2020-05-01 04:48:17 -05:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryRoomVersionForRoom failed")
|
2020-03-27 11:28:22 -05:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
2023-05-16 19:33:27 -05:00
|
|
|
JSON: spec.InternalServerError{},
|
2020-03-27 11:28:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-19 11:27:01 -05: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 11:33:49 -05:00
|
|
|
MembershipQuerier: &api.MembershipQuerier{Roomserver: rsAPI},
|
2023-06-14 09:23:46 -05:00
|
|
|
UserIDQuerier: func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
2023-06-06 15:55:18 -05:00
|
|
|
return rsAPI.QueryUserIDForSender(httpReq.Context(), roomID, senderID)
|
|
|
|
},
|
2023-06-28 13:29:49 -05:00
|
|
|
StoreSenderIDFromPublicID: func(ctx context.Context, senderID spec.SenderID, userIDRaw string, roomID spec.RoomID) error {
|
|
|
|
userID, userErr := spec.NewUserID(userIDRaw, true)
|
|
|
|
if userErr != nil {
|
|
|
|
return userErr
|
|
|
|
}
|
|
|
|
return rsAPI.StoreUserRoomPublicKey(ctx, senderID, *userID, roomID)
|
|
|
|
},
|
2023-05-19 11:27:01 -05:00
|
|
|
}
|
|
|
|
response, joinErr := gomatrixserverlib.HandleSendJoin(input)
|
|
|
|
switch e := joinErr.(type) {
|
|
|
|
case nil:
|
|
|
|
case spec.InternalServerError:
|
|
|
|
util.GetLogger(httpReq.Context()).WithError(joinErr)
|
2017-11-29 03:38:56 -06:00
|
|
|
return util.JSONResponse{
|
2023-05-19 11:27:01 -05:00
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
2022-08-02 04:22:17 -05:00
|
|
|
}
|
2023-05-19 11:27:01 -05: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 04:22:17 -05:00
|
|
|
}
|
|
|
|
|
2017-11-29 03:38:56 -06:00
|
|
|
return util.JSONResponse{
|
2023-05-19 11:27:01 -05:00
|
|
|
Code: code,
|
|
|
|
JSON: e,
|
2017-11-29 03:38:56 -06:00
|
|
|
}
|
2023-05-19 11:27:01 -05:00
|
|
|
default:
|
|
|
|
util.GetLogger(httpReq.Context()).WithError(joinErr)
|
2017-11-29 03:38:56 -06:00
|
|
|
return util.JSONResponse{
|
2018-03-13 10:55:45 -05:00
|
|
|
Code: http.StatusBadRequest,
|
2023-05-19 11:27:01 -05:00
|
|
|
JSON: spec.Unknown("unknown error"),
|
2017-11-29 03:38:56 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-19 11:27:01 -05:00
|
|
|
if response == nil {
|
|
|
|
util.GetLogger(httpReq.Context()).Error("gmsl.HandleMakeJoin returned invalid response")
|
2023-05-16 19:33:27 -05:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
2023-05-19 11:27:01 -05:00
|
|
|
|
2017-11-29 03:38:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch the state and auth chain. We do this before we send the events
|
|
|
|
// on, in case this fails.
|
2019-12-20 08:42:57 -06:00
|
|
|
var stateAndAuthChainResponse api.QueryStateAndAuthChainResponse
|
2020-05-01 04:48:17 -05:00
|
|
|
err = rsAPI.QueryStateAndAuthChain(httpReq.Context(), &api.QueryStateAndAuthChainRequest{
|
2023-05-19 11:27:01 -05: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 09:46:06 -05:00
|
|
|
ResolveState: true,
|
2019-12-20 08:42:57 -06:00
|
|
|
}, &stateAndAuthChainResponse)
|
2017-11-29 03:38:56 -06:00
|
|
|
if err != nil {
|
2020-05-01 04:48:17 -05:00
|
|
|
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryStateAndAuthChain failed")
|
2023-05-16 19:33:27 -05:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
2017-11-29 03:38:56 -06:00
|
|
|
}
|
|
|
|
|
2019-12-20 08:42:57 -06:00
|
|
|
if !stateAndAuthChainResponse.RoomExists {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusNotFound,
|
2023-05-09 17:46:49 -05:00
|
|
|
JSON: spec.NotFound("Room does not exist"),
|
2019-12-20 08:42:57 -06:00
|
|
|
}
|
|
|
|
}
|
2022-08-25 03:51:36 -05:00
|
|
|
if !stateAndAuthChainResponse.StateKnown {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusForbidden,
|
2023-05-09 17:46:49 -05:00
|
|
|
JSON: spec.Forbidden("State not known"),
|
2022-08-25 03:51:36 -05:00
|
|
|
}
|
|
|
|
}
|
2019-12-20 08:42:57 -06:00
|
|
|
|
2017-11-29 03:38:56 -06: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 11:27:01 -05:00
|
|
|
if !response.AlreadyJoined {
|
|
|
|
var rsResponse api.InputRoomEventsResponse
|
2023-05-09 17:46:49 -05:00
|
|
|
rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
|
2021-07-19 07:15:19 -05:00
|
|
|
InputRoomEvents: []api.InputRoomEvent{
|
|
|
|
{
|
|
|
|
Kind: api.KindNew,
|
2023-05-19 11:27:01 -05:00
|
|
|
Event: &types.HeaderedEvent{PDU: response.JoinEvent},
|
2021-07-19 07:15:19 -05:00
|
|
|
SendAsServer: string(cfg.Matrix.ServerName),
|
|
|
|
TransactionID: nil,
|
|
|
|
},
|
2020-05-04 07:53:47 -05:00
|
|
|
},
|
2023-05-19 11:27:01 -05:00
|
|
|
}, &rsResponse)
|
|
|
|
if rsResponse.ErrMsg != "" {
|
|
|
|
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, rsResponse.ErrMsg).Error("SendEvents failed")
|
|
|
|
if rsResponse.NotAllowed {
|
2021-07-19 07:15:19 -05:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
2023-05-19 11:27:01 -05:00
|
|
|
JSON: spec.Forbidden(rsResponse.ErrMsg),
|
2021-07-19 07:15:19 -05:00
|
|
|
}
|
|
|
|
}
|
2023-05-16 19:33:27 -05:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
JSON: spec.InternalServerError{},
|
|
|
|
}
|
2020-05-04 07:53:47 -05:00
|
|
|
}
|
2017-11-29 03:38:56 -06:00
|
|
|
}
|
|
|
|
|
2020-05-12 10:24:28 -05: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 04:53:38 -05:00
|
|
|
// https://matrix.org/docs/spec/server_server/latest#put-matrix-federation-v1-send-join-roomid-eventid
|
2017-11-29 03:38:56 -06:00
|
|
|
return util.JSONResponse{
|
2018-03-13 10:55:45 -05:00
|
|
|
Code: http.StatusOK,
|
2023-04-06 03:55:01 -05:00
|
|
|
JSON: fclient.RespSendJoin{
|
2023-04-27 06:54:20 -05:00
|
|
|
StateEvents: types.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.StateEvents),
|
|
|
|
AuthEvents: types.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.AuthChainEvents),
|
2020-05-05 04:53:38 -05:00
|
|
|
Origin: cfg.Matrix.ServerName,
|
2023-05-19 11:27:01 -05:00
|
|
|
Event: response.JoinEvent.JSON(),
|
2017-11-29 03:38:56 -06:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-05-12 10:24:28 -05:00
|
|
|
|
2023-04-27 06:54:20 -05:00
|
|
|
type eventsByDepth []*types.HeaderedEvent
|
2020-05-12 10:24:28 -05: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()
|
|
|
|
}
|