mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 21:12:45 +00:00
Make StrictValidityChecking
a function (#3092)
Companion PR to https://github.com/matrix-org/gomatrixserverlib/pull/388
This commit is contained in:
parent
d11da6ec7c
commit
725ff5567d
15 changed files with 145 additions and 252 deletions
|
@ -170,7 +170,7 @@ func (s *FederationInternalAPI) handleDatabaseKeys(
|
|||
// in that case. If the key isn't valid right now, then by
|
||||
// leaving it in the 'requests' map, we'll try to update the
|
||||
// key using the fetchers in handleFetcherKeys.
|
||||
if res.WasValidAt(now, true) {
|
||||
if res.WasValidAt(now, gomatrixserverlib.StrictValiditySignatureCheck) {
|
||||
delete(requests, req)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ func Backfill(
|
|||
}
|
||||
}
|
||||
|
||||
// Query the roomserver.
|
||||
// Query the Roomserver.
|
||||
if err = rsAPI.PerformBackfill(httpReq.Context(), &req, &res); err != nil {
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("query.PerformBackfill failed")
|
||||
return util.JSONResponse{
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
package routing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
|
@ -33,53 +32,6 @@ import (
|
|||
"github.com/matrix-org/dendrite/setup/config"
|
||||
)
|
||||
|
||||
type JoinRoomQuerier struct {
|
||||
roomserver api.FederationRoomserverAPI
|
||||
}
|
||||
|
||||
func (rq *JoinRoomQuerier) CurrentStateEvent(ctx context.Context, roomID spec.RoomID, eventType string, stateKey string) (gomatrixserverlib.PDU, error) {
|
||||
return rq.roomserver.CurrentStateEvent(ctx, roomID, eventType, stateKey)
|
||||
}
|
||||
|
||||
func (rq *JoinRoomQuerier) InvitePending(ctx context.Context, roomID spec.RoomID, userID spec.UserID) (bool, error) {
|
||||
return rq.roomserver.InvitePending(ctx, roomID, userID)
|
||||
}
|
||||
|
||||
func (rq *JoinRoomQuerier) RestrictedRoomJoinInfo(ctx context.Context, roomID spec.RoomID, userID spec.UserID, localServerName spec.ServerName) (*gomatrixserverlib.RestrictedRoomJoinInfo, error) {
|
||||
roomInfo, err := rq.roomserver.QueryRoomInfo(ctx, roomID)
|
||||
if err != nil || roomInfo == nil || roomInfo.IsStub() {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req := api.QueryServerJoinedToRoomRequest{
|
||||
ServerName: localServerName,
|
||||
RoomID: roomID.String(),
|
||||
}
|
||||
res := api.QueryServerJoinedToRoomResponse{}
|
||||
if err = rq.roomserver.QueryServerJoinedToRoom(ctx, &req, &res); err != nil {
|
||||
util.GetLogger(ctx).WithError(err).Error("rsAPI.QueryServerJoinedToRoom failed")
|
||||
return nil, fmt.Errorf("InternalServerError: Failed to query room: %w", err)
|
||||
}
|
||||
|
||||
userJoinedToRoom, err := rq.roomserver.UserJoinedToRoom(ctx, types.RoomNID(roomInfo.RoomNID), userID)
|
||||
if err != nil {
|
||||
util.GetLogger(ctx).WithError(err).Error("rsAPI.UserJoinedToRoom failed")
|
||||
return nil, fmt.Errorf("InternalServerError: %w", err)
|
||||
}
|
||||
|
||||
locallyJoinedUsers, err := rq.roomserver.LocallyJoinedUsers(ctx, roomInfo.RoomVersion, types.RoomNID(roomInfo.RoomNID))
|
||||
if err != nil {
|
||||
util.GetLogger(ctx).WithError(err).Error("rsAPI.GetLocallyJoinedUsers failed")
|
||||
return nil, fmt.Errorf("InternalServerError: %w", err)
|
||||
}
|
||||
|
||||
return &gomatrixserverlib.RestrictedRoomJoinInfo{
|
||||
LocalServerInRoom: res.RoomExists && res.IsInRoom,
|
||||
UserJoinedToRoom: userJoinedToRoom,
|
||||
JoinedUsers: locallyJoinedUsers,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// MakeJoin implements the /make_join API
|
||||
func MakeJoin(
|
||||
httpReq *http.Request,
|
||||
|
@ -142,8 +94,8 @@ func MakeJoin(
|
|||
return event, stateEvents, nil
|
||||
}
|
||||
|
||||
roomQuerier := JoinRoomQuerier{
|
||||
roomserver: rsAPI,
|
||||
roomQuerier := api.JoinRoomQuerier{
|
||||
Roomserver: rsAPI,
|
||||
}
|
||||
|
||||
input := gomatrixserverlib.HandleMakeJoinInput{
|
||||
|
|
|
@ -291,10 +291,10 @@ func SendLeave(
|
|||
}
|
||||
}
|
||||
verifyRequests := []gomatrixserverlib.VerifyJSONRequest{{
|
||||
ServerName: serverName,
|
||||
Message: redacted,
|
||||
AtTS: event.OriginServerTS(),
|
||||
StrictValidityChecking: true,
|
||||
ServerName: serverName,
|
||||
Message: redacted,
|
||||
AtTS: event.OriginServerTS(),
|
||||
ValidityCheckingFunc: gomatrixserverlib.StrictValiditySignatureCheck,
|
||||
}}
|
||||
verifyResults, err := keys.VerifyJSONs(httpReq.Context(), verifyRequests)
|
||||
if err != nil {
|
||||
|
|
|
@ -34,7 +34,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// Event was passed to the roomserver
|
||||
// Event was passed to the Roomserver
|
||||
MetricsOutcomeOK = "ok"
|
||||
// Event failed to be processed
|
||||
MetricsOutcomeFail = "fail"
|
||||
|
|
|
@ -223,7 +223,7 @@ func ExchangeThirdPartyInvite(
|
|||
}
|
||||
}
|
||||
|
||||
// Send the event to the roomserver
|
||||
// Send the event to the Roomserver
|
||||
if err = api.SendEvents(
|
||||
httpReq.Context(), rsAPI,
|
||||
api.KindNew,
|
||||
|
@ -324,7 +324,7 @@ func buildMembershipEvent(
|
|||
return nil, errors.New("expecting state tuples for event builder, got none")
|
||||
}
|
||||
|
||||
// Ask the roomserver for information about this room
|
||||
// Ask the Roomserver for information about this room
|
||||
queryReq := api.QueryLatestEventsAndStateRequest{
|
||||
RoomID: protoEvent.RoomID,
|
||||
StateToFetch: eventsNeeded.Tuples(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue