Implement rejected events (#1426)

* WIP Event rejection

* Still send back errors for rejected events

Instead, discard them at the federationapi /send layer rather than
re-implementing checks at the clientapi/PerformJoin layer.

* Implement rejected events

Critically, rejected events CAN cause state resolution to happen
as it can merge forks in the DAG. This is fine, _provided_ we
do not add the rejected event when performing state resolution,
which is what this PR does. It also fixes the error handling
when NotAllowed happens, as we were checking too early and needlessly
handling NotAllowed in more than one place.

* Update test to match reality

* Modify InputRoomEvents to no longer return an error

Errors do not serialise across HTTP boundaries in polylith mode,
so instead set fields on the InputRoomEventsResponse. Add `Err()`
function to make the API shape basically the same.

* Remove redundant returns; linting

* Update blacklist
This commit is contained in:
Kegsay 2020-09-16 13:00:52 +01:00 committed by GitHub
parent ba6c7c4a5c
commit 18231f25b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 114 additions and 74 deletions

View file

@ -16,7 +16,7 @@ type RoomserverInternalAPI interface {
ctx context.Context,
request *InputRoomEventsRequest,
response *InputRoomEventsResponse,
) error
)
PerformInvite(
ctx context.Context,

View file

@ -23,10 +23,9 @@ func (t *RoomserverInternalAPITrace) InputRoomEvents(
ctx context.Context,
req *InputRoomEventsRequest,
res *InputRoomEventsResponse,
) error {
err := t.Impl.InputRoomEvents(ctx, req, res)
util.GetLogger(ctx).WithError(err).Infof("InputRoomEvents req=%+v res=%+v", js(req), js(res))
return err
) {
t.Impl.InputRoomEvents(ctx, req, res)
util.GetLogger(ctx).Infof("InputRoomEvents req=%+v res=%+v", js(req), js(res))
}
func (t *RoomserverInternalAPITrace) PerformInvite(

View file

@ -16,6 +16,8 @@
package api
import (
"fmt"
"github.com/matrix-org/gomatrixserverlib"
)
@ -87,4 +89,18 @@ type InputRoomEventsRequest struct {
// InputRoomEventsResponse is a response to InputRoomEvents
type InputRoomEventsResponse struct {
ErrMsg string // set if there was any error
NotAllowed bool // true if an event in the input was not allowed.
}
func (r *InputRoomEventsResponse) Err() error {
if r.ErrMsg == "" {
return nil
}
if r.NotAllowed {
return &gomatrixserverlib.NotAllowed{
Message: r.ErrMsg,
}
}
return fmt.Errorf("InputRoomEventsResponse: %s", r.ErrMsg)
}

View file

@ -187,7 +187,8 @@ func SendInputRoomEvents(
) error {
request := InputRoomEventsRequest{InputRoomEvents: ires}
var response InputRoomEventsResponse
return rsAPI.InputRoomEvents(ctx, &request, &response)
rsAPI.InputRoomEvents(ctx, &request, &response)
return response.Err()
}
// SendInvite event to the roomserver.