aboutsummaryrefslogtreecommitdiff
path: root/roomserver/api/input.go
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-09-16 13:00:52 +0100
committerGitHub <noreply@github.com>2020-09-16 13:00:52 +0100
commit18231f25b437d2f03b3be1e0536fc46d45c8691f (patch)
tree5a3ef66c25268df8214be69f0c9e1f5f925da14f /roomserver/api/input.go
parentba6c7c4a5c4166b7085343886ab69ef331238ff4 (diff)
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
Diffstat (limited to 'roomserver/api/input.go')
-rw-r--r--roomserver/api/input.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/roomserver/api/input.go b/roomserver/api/input.go
index 651c0e9f..862a6fa1 100644
--- a/roomserver/api/input.go
+++ b/roomserver/api/input.go
@@ -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)
}