mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Finish implementing redactions (#1189)
* Add a bit more logging to the fedsender * bugfix: continue sending PDUs if ones are added whilst sending another PDU Without this, the queue goes back to sleep on `<-oq.notifyPDUs` which won't fire because `pendingPDUs` is already > 0. This should fix a flakey sytest. * Break if no txn is sent * WIP syncapi work * More debugging * Bump GMSL version to pull in working Event.Redact * Remove logging * Make redactions work on v3+ * Fix more tests
This commit is contained in:
parent
a5a51b4141
commit
d9648b0615
14 changed files with 131 additions and 25 deletions
|
@ -29,6 +29,22 @@ const (
|
|||
// OutputTypeRetireInviteEvent indicates that the event is an OutputRetireInviteEvent
|
||||
OutputTypeRetireInviteEvent OutputType = "retire_invite_event"
|
||||
// OutputTypeRedactedEvent indicates that the event is an OutputRedactedEvent
|
||||
//
|
||||
// This event is emitted when a redaction has been 'validated' (meaning both the redaction and the event to redact are known).
|
||||
// Redaction validation happens when the roomserver receives either:
|
||||
// - A redaction for which we have the event to redact.
|
||||
// - Any event for which we have a redaction.
|
||||
// When the roomserver receives an event, it will check against the redactions table to see if there is a matching redaction
|
||||
// for the event. If there is, it will mark the redaction as validated and emit this event. In the common case of a redaction
|
||||
// happening after receiving the event to redact, the roomserver will emit a OutputTypeNewRoomEvent of m.room.redaction
|
||||
// immediately followed by a OutputTypeRedactedEvent. In the uncommon case of receiving the redaction BEFORE the event to redact,
|
||||
// the roomserver will emit a OutputTypeNewRoomEvent of the event to redact immediately followed by a OutputTypeRedactedEvent.
|
||||
//
|
||||
// In order to honour redactions correctly, downstream components must ignore m.room.redaction events emitted via OutputTypeNewRoomEvent.
|
||||
// When downstream components receive an OutputTypeRedactedEvent they must:
|
||||
// - Pull out the event to redact from the database. They should have this because the redaction is validated.
|
||||
// - Redact the event and set the corresponding `unsigned` fields to indicate it as redacted.
|
||||
// - Replace the event in the database.
|
||||
OutputTypeRedactedEvent OutputType = "redacted_event"
|
||||
)
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/auth"
|
||||
"github.com/matrix-org/dendrite/roomserver/state"
|
||||
|
@ -867,7 +868,7 @@ func getAuthChain(
|
|||
func persistEvents(ctx context.Context, db storage.Database, events []gomatrixserverlib.HeaderedEvent) (types.RoomNID, map[string]types.Event) {
|
||||
var roomNID types.RoomNID
|
||||
backfilledEventMap := make(map[string]types.Event)
|
||||
for _, ev := range events {
|
||||
for j, ev := range events {
|
||||
nidMap, err := db.EventNIDs(ctx, ev.AuthEventIDs())
|
||||
if err != nil { // this shouldn't happen as RequestBackfill already found them
|
||||
logrus.WithError(err).WithField("auth_events", ev.AuthEventIDs()).Error("Failed to find one or more auth events")
|
||||
|
@ -891,12 +892,14 @@ func persistEvents(ctx context.Context, db storage.Database, events []gomatrixse
|
|||
// It's also possible for this event to be a redaction which results in another event being
|
||||
// redacted, which we don't care about since we aren't returning it in this backfill.
|
||||
if redactedEventID == ev.EventID() {
|
||||
ev = ev.Redact().Headered(ev.RoomVersion)
|
||||
err = ev.SetUnsignedField("redacted_because", redactionEvent)
|
||||
eventToRedact := ev.Unwrap()
|
||||
redactedEvent, err := eventutil.RedactEvent(redactionEvent, &eventToRedact)
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("event_id", ev.EventID()).Error("Failed to set unsigned field")
|
||||
logrus.WithError(err).WithField("event_id", ev.EventID()).Error("Failed to redact event")
|
||||
continue
|
||||
}
|
||||
ev = redactedEvent.Headered(ev.RoomVersion)
|
||||
events[j] = ev
|
||||
}
|
||||
backfilledEventMap[ev.EventID()] = types.Event{
|
||||
EventNID: stateAtEvent.StateEntry.EventNID,
|
||||
|
|
|
@ -563,6 +563,10 @@ func (d *Database) handleRedactions(
|
|||
// we've seen this redaction before or there is nothing to redact
|
||||
return nil, "", nil
|
||||
}
|
||||
if redactedEvent.RoomID() != redactionEvent.RoomID() {
|
||||
// redactions across rooms aren't allowed
|
||||
return nil, "", nil
|
||||
}
|
||||
|
||||
// mark the event as redacted
|
||||
err = redactedEvent.SetUnsignedField("redacted_because", redactionEvent)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue